khajavi / pandoc

Automatically exported from code.google.com/p/pandoc
GNU General Public License v2.0
0 stars 0 forks source link

Better grammar for nested emph and strong #67

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
*hello**there* is perhaps better parsed as
<em>hello**there</em>
than as
<em>hello</em><em>there</em>

See the grammar in markdown-peg for a fix.

Original issue reported on code.google.com by fiddloso...@gmail.com on 18 Apr 2008 at 3:02

GoogleCodeExporter commented 9 years ago
Here's the grammar from peg-markdown:

# This keeps the parser from getting bogged down on long strings of '*' or '_',
# or strings of '*' or '_' with space on each side:
UlOrStarLine = UlLine | StarLine { $$ = mk_str(yytext); }
StarLine = < "****" '*'* > | < Spacechar '*'+ &Spacechar >
UlLine = < "____" '_'* > | < Spacechar '_'+ &Spacechar >

Emph = EmphStar | EmphUl

OneStarOpen = !StarLine '*' !Spacechar !Newline
OneStarClose = !Spacechar !Newline a:Inline !StrongStar '*' { $$ = a; }

EmphStar = OneStarOpen
            a:StartList
            ( !OneStarClose Inline { a = cons($$, a); } )*
            OneStarClose { a = cons($$, a); }
            { $$ = mk_list(EMPH, a); }

OneUlOpen = !UlLine '_' !Spacechar !Newline
OneUlClose = !Spacechar !Newline a:Inline !StrongUl '_' !Alphanumeric { $$ = a; 
}

EmphUl = OneUlOpen
            a:StartList
            ( !OneUlClose Inline { a = cons($$, a); } )*
            OneUlClose { a = cons($$, a); }
            { $$ = mk_list(EMPH, a); }

Strong = StrongStar | StrongUl

TwoStarOpen = !StarLine "**" !Spacechar !Newline
TwoStarClose = !Spacechar !Newline a:Inline "**" { $$ = a; }

StrongStar = TwoStarOpen
                a:StartList
                ( !TwoStarClose Inline { a = cons($$, a); } )*
                TwoStarClose { a = cons($$, a); }
                { $$ = mk_list(STRONG, a); }

TwoUlOpen = !UlLine "__" !Spacechar !Newline
TwoUlClose = !Spacechar !Newline a:Inline "__" !Alphanumeric { $$ = a; }

StrongUl = TwoUlOpen
            a:StartList
            ( !TwoUlClose Inline { a = cons($$, a); } )*
            TwoUlClose { a = cons($$, a); }
            { $$ = mk_list(STRONG, a); }

Original comment by fiddloso...@gmail.com on 11 Aug 2008 at 2:45

GoogleCodeExporter commented 9 years ago

Original comment by fiddloso...@gmail.com on 5 Dec 2009 at 8:04

GoogleCodeExporter commented 9 years ago
Here's how lunamark does it:

    UlOrStarLine = p"*"^4 + p"_"^4 + (generic.space * lpeg.S("*_")^1 *
#generic.space) / writer.str,

    Emph = _"EmphStar" + _"EmphUl",

    EmphStar = p"*" * -(generic.spacechar + generic.newline) * lpeg.Ct((_"Inline" -
p"*")^1) * p"*" / writer.emph,

    EmphUl = p"_" * -(generic.spacechar + generic.newline) * lpeg.Ct((_"Inline" -
p"_")^1) * p"_" / writer.emph,

    Strong = _"StrongStar" + _"StrongUl",

    StrongStar = p"**" * -(generic.spacechar + generic.newline) * lpeg.Ct((_"Inline"
- p"**")^1) * p"**" / writer.strong,

    StrongUl = p"__" * -(generic.spacechar + generic.newline) * lpeg.Ct((_"Inline" -
p"__")^1) * p"__" / writer.strong,

Original comment by fiddloso...@gmail.com on 5 Dec 2009 at 5:12

GoogleCodeExporter commented 9 years ago
Current peg-markdown:

# This keeps the parser from getting bogged down on long strings of '*' or '_',
# or strings of '*' or '_' with space on each side:
UlOrStarLine =  (UlLine | StarLine) { $$ = mk_str(yytext); }
StarLine =      < "****" '*'* > | < Spacechar '*'+ &Spacechar >
UlLine   =      < "____" '_'* > | < Spacechar '_'+ &Spacechar >

Emph =      EmphStar | EmphUl
OneStarOpen  =  !StarLine '*' !Spacechar !Newline
OneStarClose =  !Spacechar !Newline a:Inline !StrongStar '*' { $$ = a; }

EmphStar =  OneStarOpen
            a:StartList
            ( !OneStarClose Inline { a = cons($$, a); } )*
            OneStarClose { a = cons($$, a); }
            { $$ = mk_list(EMPH, a); }

OneUlOpen  =  !UlLine '_' !Spacechar !Newline
OneUlClose =  !Spacechar !Newline a:Inline !StrongUl '_' !Alphanumeric { $$ = a;
 }

EmphUl =    OneUlOpen
            a:StartList
            ( !OneUlClose Inline { a = cons($$, a); } )*
            OneUlClose { a = cons($$, a); }
            { $$ = mk_list(EMPH, a); }

Strong = StrongStar | StrongUl

TwoStarOpen =   !StarLine "**" !Spacechar !Newline
TwoStarClose =  !Spacechar !Newline a:Inline "**" { $$ = a; }

StrongStar =    TwoStarOpen
                a:StartList
                ( !TwoStarClose Inline { a = cons($$, a); } )*
                TwoStarClose { a = cons($$, a); }
                { $$ = mk_list(STRONG, a); }

TwoUlOpen =     !UlLine "__" !Spacechar !Newline
TwoUlClose =    !Spacechar !Newline a:Inline "__" !Alphanumeric { $$ = a; }

StrongUl =  TwoUlOpen
            a:StartList
            ( !TwoUlClose Inline { a = cons($$, a); } )*
            TwoUlClose { a = cons($$, a); }
            { $$ = mk_list(STRONG, a); }

Original comment by fiddloso...@gmail.com on 5 Dec 2009 at 7:02

GoogleCodeExporter commented 9 years ago

Original comment by fiddloso...@gmail.com on 5 Dec 2009 at 7:10

GoogleCodeExporter commented 9 years ago

Original comment by fiddloso...@gmail.com on 5 Dec 2009 at 7:10