Skip to content

Commit

Permalink
Merge pull request #24 from Altai-man/master
Browse files Browse the repository at this point in the history
Fix code chunk parsing
This is pretty great. Thanks!
  • Loading branch information
JJ committed Oct 6, 2017
2 parents 6b3a080 + 1daf9c3 commit 626aa56
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
@@ -1,12 +1,13 @@
branches:
except:
- gh-pages

language: perl6

perl6:
- latest
- '2017.06'

- '2017.09'

install:
- rakudobrew build zef
- zef install HTML::Escape
- zef --deps-only install .
14 changes: 7 additions & 7 deletions lib/Text/Markdown/Document.pm6
Expand Up @@ -152,7 +152,7 @@ class Text::Markdown::Document {
for @tmp -> $_ is rw {
if $_ ~~ Str {
# regex stolen shamelessly from masak's Text::Markdown
if $_ ~~ s/ \! \[ (.+?) \] \( (.+?) \) (.*) // {
if $_ ~~ s/ \! \[ (.+?) \] \( (.+?) \) (.*) // {
@ret.push($_);
@ret.push(Text::Markdown::Image.new(:text(~$0), :url(~$1)));
@ret.push(~$2);
Expand Down Expand Up @@ -182,6 +182,12 @@ class Text::Markdown::Document {
@ret.push(~$1);
$changed = True;
}
elsif $_ ~~ s/ ('`'+) (.+?) <!after '`'> $0 <!before '`'> (.*) // {
@ret.push($_);
@ret.push(Text::Markdown::Code.new(:text(~$1)));
@ret.push(~$2);
$changed = True;
}
elsif $_ ~~ s/ \< ( .*? \@ .*? ) \> (.*) // {
@ret.push($_);
@ret.push(Text::Markdown::EmailLink.new(:url(~$0)));
Expand All @@ -206,12 +212,6 @@ class Text::Markdown::Document {
@ret.push(~$2);
$changed = True;
}
elsif $_ ~~ s/ ('`'+) (.+?) <!after '`'> $0 <!before '`'> (.*) // {
@ret.push($_);
@ret.push(Text::Markdown::Code.new(:text(~$1)));
@ret.push(~$2);
$changed = True;
}
else {
@ret.push($_);
}
Expand Down
3 changes: 0 additions & 3 deletions t/parse-link-with-code.t
Expand Up @@ -16,6 +16,3 @@ is $document.items.elems, 1, 'has correct number of items';
my $p = $document.items[0];
ok $p ~~ Text::Markdown::Paragraph, 'It is a Paragraph';
is $p.items[0] ~~ Text::Markdown::Link, True, "First element is a link";
# dd $p.items;


4 changes: 0 additions & 4 deletions t/parse-with-underscore.t
Expand Up @@ -15,8 +15,4 @@ is $document.items.elems, 1, 'has correct number of items';

my $p = $document.items[0];
ok $p ~~ Text::Markdown::Paragraph, 'It is a Paragraph';

dd $p.items;

is $p.items.elems, 3, "Slurped link correctly";

16 changes: 15 additions & 1 deletion t/parse.t
Expand Up @@ -2,7 +2,7 @@ use v6;
use Text::Markdown::Document;
use Test;

plan 176;
plan 182;

my $text = q:to/TEXT/;
## Markdown Test ##
Expand Down Expand Up @@ -315,3 +315,17 @@ ok $document.items[3].items == 3, '...with three items';

ok $document.items[4] ~~ Text::Markdown::Paragraph, 'fifth element is a paragraph';
is $document.items[4].items[0], 'The end.', '...with the right data';

$text = q:to/TEXT/;
My `VALUE_WITH_UNDERSCORE`.

My `</body>`.
TEXT

$document = Text::Markdown::Document.new($text);
ok $document ~~ Text::Markdown::Document, 'Able to parse';
is $document.items.elems, 2, 'has correct number of items';
ok $document.items[0].items[1] ~~ Text::Markdown::Code, 'code chunk is parsed';
is $document.items[0].items[1], '`VALUE_WITH_UNDERSCORE`', 'value is correct';
ok $document.items[1].items[1] ~~ Text::Markdown::Code, 'tag is parsed';
is $document.items[1].items[1], '`</body>`', 'value is correct';

0 comments on commit 626aa56

Please sign in to comment.