Skip to content

Commit

Permalink
RakuAST: fix podification of markup
Browse files Browse the repository at this point in the history
Specifically in the case where a unallowed markup had a meta that
contained markup that *was* allowed.  Case in point:

=begin code :allow<B>
An X<array|B<arrays, definition of>> is an ordered list of scalars
=end code
  • Loading branch information
lizmat committed Jul 25, 2023
1 parent aed6be5 commit bef9ea4
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions src/core.c/RakuAST/LegacyPodify.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class RakuAST::LegacyPodify {
}

# create podified contents for atoms
method !contentify-atoms($ast) {
method !contentify(@source) {
my str @parts;
my @atoms = $ast.atoms.map({
my @atoms = @source.map({
nqp::istype($_,Str)
?? sanitize(.subst("\n", ' ', :g))
!! .podify # may Slip
Expand Down Expand Up @@ -156,18 +156,55 @@ class RakuAST::LegacyPodify {
}

multi method podify(RakuAST::Doc::Markup:D $ast) {
# This markup is allowed
my str $letter = $ast.letter;
%*OK{$letter}
?? $letter eq 'V'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! Pod::FormattingCode.new(
type => $letter,
meta => $ast.meta,
contents => $letter eq 'C'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! self!contentify-atoms($ast)
)
!! $ast.Str

# make sure we have properly podified meta data
my @meta = do if $letter ne 'E' && $ast.meta -> @_ {
self!contentify(@_)
}

# Markup is allowed
if %*OK{$letter} {
$letter eq 'V'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! Pod::FormattingCode.new(
type => $letter,
meta => @meta,
contents => $letter eq 'C'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! self!contentify($ast.atoms)
)
}

# Meta on markup that itself is not allowed
elsif @meta {
my @atoms = self!contentify($ast.atoms);

@atoms.unshift: nqp::istype(@atoms.head,Str)
?? $letter ~ $ast.opener ~ @atoms.shift
!! $letter ~ $ast.opener;

@atoms.push: nqp::istype(@atoms.tail,Str)
?? @atoms.pop ~ "|"
!! "|";

@atoms.push: nqp::istype(@meta.head,Str)
?? @atoms.pop ~ @meta.shift
!! @meta.shift;
@atoms.append: @meta;

@atoms.push: nqp::istype(@atoms.tail,Str)
?? @atoms.pop ~ $ast.closer
!! $ast.closer;

@atoms.List
}

# No meta on unallowed markup
else {
$ast.Str
}
}

multi method podify(RakuAST::Doc::Paragraph:D $ast) {
Expand Down Expand Up @@ -328,8 +365,8 @@ class RakuAST::LegacyPodify {
!! .atoms.map({
nqp::istype($_,Str)
?? .split("\n", :v, :skip-empty).Slip
!! nqp::istype($_,RakuAST::Doc::Markup) && %*OK{.letter}
?? .podify
!! nqp::istype($_,RakuAST::Doc::Markup)
?? .podify.Slip
!! .Str
})
).Slip
Expand Down

0 comments on commit bef9ea4

Please sign in to comment.