diff --git a/macros/core/PGML.pl b/macros/core/PGML.pl index 9a9ad891d4..b2b9ae5888 100644 --- a/macros/core/PGML.pl +++ b/macros/core/PGML.pl @@ -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 { @@ -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 }, "[\@" => { @@ -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 ''); @@ -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; @@ -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)); +} + ###################################################################### ###################################################################### @@ -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 // '') . '}'; +} + ###################################################################### ###################################################################### @@ -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); +} + ###################################################################### ######################################################################