Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
check smart extensions
  • Loading branch information
fperrad committed Mar 24, 2009
1 parent 0b4492a commit 0ff6b01
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 13 deletions.
1 change: 1 addition & 0 deletions config/makefiles/root.in
Expand Up @@ -46,6 +46,7 @@ SOURCES := \
markdown.pir

BUILTINS_PIR := \
src/builtins/is_strict.pir \
src/builtins/length.pir

DOCS := README
Expand Down
17 changes: 17 additions & 0 deletions src/builtins/is_strict.pir
@@ -0,0 +1,17 @@
# Copyright (C) 2009, Parrot Foundation.
# $Id$

.namespace [ 'Markdown';'Grammar' ]

.sub 'is_strict' :method
$P0 = new 'Env'
$S0 = $P0['MARKDOWN_STRICT']
.return ($S0)
.end

# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:

32 changes: 24 additions & 8 deletions src/parser/actions.pm
Expand Up @@ -306,27 +306,43 @@ method Smart($/, $key) {
}

method Apostrophe($/) {
# make Markdown::Entity.new( :text( '’' ) );
make Markdown::Entity.new( :text( $/.text() ) );
# if ( $/.is_strict() ) {
make Markdown::Word.new( :text( $/.text() ) );
# }
# else {
# make Markdown::Entity.new( :text( '’' ) );
# }
}

method Ellipsis($/) {
# make Markdown::Entity.new( :text( '…' ) );
make Markdown::Entity.new( :text( $/.text() ) );
if ( $/.is_strict() ) {
make Markdown::Word.new( :text( $/.text() ) );
}
else {
make Markdown::Entity.new( :text( '…' ) );
}
}

method Dash($/, $key) {
make $( $/{$key} );
}

method EnDash($/) {
# make Markdown::Entity.new( :text( '–' ) );
make Markdown::Entity.new( :text( $/.text() ) );
# if ( $/.is_strict() ) {
make Markdown::Word.new( :text( $/.text() ) );
# }
# else {
# make Markdown::Entity.new( :text( '–' ) );
# }
}

method EmDash($/) {
# make Markdown::Entity.new( :text( '—' ) );
make Markdown::Entity.new( :text( $/.text() ) );
if ( $/.is_strict() ) {
make Markdown::Word.new( :text( $/.text() ) );
}
else {
make Markdown::Entity.new( :text( '—' ) );
}
}

method DoubleQuoted($/) {
Expand Down
4 changes: 2 additions & 2 deletions src/parser/grammar.pg
Expand Up @@ -540,7 +540,7 @@ token Apostrophe {
}

token Ellipsis {
'...' | '. . .'
[ '...' | '. . .' ]
{*}
}

Expand All @@ -555,7 +555,7 @@ token EnDash {
}

token EmDash {
'---' | '--'
[ '---' | '--' ]
{*}
}

Expand Down
71 changes: 71 additions & 0 deletions t/24-smart.t
@@ -0,0 +1,71 @@
#! perl
# Copyright (C) 2008-2009, Parrot Foundation.
# $Id$

=head1 Markdown smart extensions
=head2 Synopsis
% perl t/24-smart.t
=cut

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin";

use Parrot::Test tests => 2;
use Test::More;

#language_output_is( 'markdown', <<'CODE', <<'OUT', 'apostrophe' );
#
#smart '
#
#CODE
#<p>smart &rsquo;</p>
#
#OUT

language_output_is( 'markdown', <<'CODE', <<'OUT', 'ellipsis' );
smart ...
smart . . .
CODE
<p>smart &hellip;</p>

<p>smart &hellip;</p>

OUT

#language_output_is( 'markdown', <<'CODE', <<'OUT', 'endash' );
#
#smart -
#
#CODE
#<p>smart &ndash;</p>
#
#OUT

language_output_is( 'markdown', <<'CODE', <<'OUT', 'emdash' );
smart --
smart ---
CODE
<p>smart &mdash;</p>

<p>smart &mdash;</p>

OUT


# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
8 changes: 5 additions & 3 deletions t/MarkdownTest.t
Expand Up @@ -34,12 +34,14 @@ else {
plan skip_all => 'no MarkdownTest';
}

$ENV{MARKDOWN_STRICT} = 'NO_EXT';

foreach my $test_file (@test_files) {
my $test_name = basename($test_file, '.text');

my $code = Parrot::Test::slurp_file( $test_file );
my $out = Parrot::Test::slurp_file(File::Spec->catfile( @dir, "$test_name.html" ));
language_output_is( 'markdown', $code, $out, $test_name, todo => 'not implemented' );
my $code = Parrot::Test::slurp_file( $test_file ) . "\n";
my $out = Parrot::Test::slurp_file(File::Spec->catfile( @dir, "$test_name.html" )) . "\n";
language_output_is( 'markdown', $code, $out, $test_name );
}


Expand Down

0 comments on commit 0ff6b01

Please sign in to comment.