Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 53 additions & 8 deletions macros/core/PGML.pl
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ sub Rule {
my $self = shift;
my $token = shift;
if ($self->{atLineStart}) {
### check for line end or braces
# check for line end or braces
$self->Item("rule", $token, { options => [ "width", "height", "size" ] });
$self->{ignoreNL} = 1;
} else {
Expand Down Expand Up @@ -690,13 +690,11 @@ sub NOOP {
options => [ "source", "width", "height", "image_options" ]
},
"[<" => {
type => 'link',
parseComments => 1,
parseSubstitutions => 1,
terminator => qr/>\]/,
terminateMethod => 'terminateGetString',
cancelNL => 1,
options => [ "text", "title" ]
type => 'tag',
parseAll => 1,
isContainer => 1,
terminator => qr/>\]/,
options => [qw(html tex ptx)]
},
"[%" => { type => 'comment', parseComments => 1, terminator => qr/%\]/, allowPar => 1 },
"[\@" => {
Expand Down Expand Up @@ -1282,6 +1280,7 @@ sub string {
/forced/ && do { $string = $self->Forced($item); last };
/comment/ && do { $string = $self->Comment($item); last };
/table/ && do { $string = $self->Table($item); last };
/tag/ && do { $string = $self->Tag($item); last };
PGML::Warning "Warning: unknown block type '$item->{type}' in " . ref($self) . "::format\n";
}
push(@strings, $string) unless (!defined $string || $string eq '');
Expand Down Expand Up @@ -1338,6 +1337,11 @@ sub Table {
return ($item->{hasStar} ? main::LayoutTable($table, @options) : main::DataTable($table, @options));
}

sub Tag {
my ($self, $item) = @_;
return $self->string($item);
}

sub Math {
my $self = shift;
my $item = shift;
Expand Down Expand Up @@ -1645,6 +1649,27 @@ sub Math {
return main::general_math_ev3($self->SUPER::Math(@_));
}

sub Tag {
my ($self, $item) = @_;
my %whitelist = (div => 1, span => 1);
my @attributes = ref($item->{html}) eq 'ARRAY' ? @{ $item->{html} } : $item->{html};
my $tag = @attributes % 2 ? (shift @attributes // 'div') : 'div';
unless ($whitelist{$tag}) {
PGML::Warning qq{The tag "$tag" is not allowed};
return $self->string($item);
}
if ($tag eq 'span') {
for my $subblock (@{ $item->{stack} }) {
if ($subblock->{type} =~ /^(indent|align|par|list|bullet|answer|heading|rule|code|pre|verbatim|table|tag)$/)
{
PGML::Warning qq{A "span" tag may not contain a $subblock->{type}};
return $self->string($item);
}
}
}
return main::tag($tag, @attributes, $self->string($item));
}

######################################################################
######################################################################

Expand Down Expand Up @@ -1789,6 +1814,17 @@ sub Math {
return main::general_math_ev3($self->SUPER::Math(@_));
}

sub Tag {
my ($self, $item) = @_;
my ($tex_begin, $tex_end);
if (ref($item->{tex}) eq 'ARRAY') {
($tex_begin, $tex_end) = @{ $item->{tex} };
} elsif ($item->{tex}) {
($tex_begin, $tex_end) = ("\\begin{$item->{tex}}", "\\end{$item->{tex}}");
}
return '{' . ($tex_begin // '') . $self->string($item) . ($tex_end // '') . '}';
}

######################################################################
######################################################################

Expand Down Expand Up @@ -1936,6 +1972,15 @@ sub Math {
return main::general_math_ev3($self->SUPER::Math(@_));
}

sub Tag {
my ($self, $item) = @_;
my @args = ref($item->{ptx}) eq 'ARRAY' ? @{ $item->{ptx} } : $item->{ptx};
if (my $tag = shift @args) {
return NiceTables::tag($self->string($item), $tag, @args);
}
return $self->string($item);
}

######################################################################
######################################################################

Expand Down