From 231f3182599421d7c3c96127abc2898ca65ce029 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 20 Nov 2018 20:13:56 +0800 Subject: [PATCH] PegParser: update pegmarkdownhighlight to fix strike --- peg-highlight/pmh_parser.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/peg-highlight/pmh_parser.c b/peg-highlight/pmh_parser.c index 3b66968f..5be0afce 100644 --- a/peg-highlight/pmh_parser.c +++ b/peg-highlight/pmh_parser.c @@ -1048,6 +1048,15 @@ bool inline_equation_predict_post(char *buf, int pos) #define IEP_PRE inline_equation_predict_pre(G->buf, G->pos) #define IEP_POST inline_equation_predict_post(G->buf, G->pos) +// Do not allow whitespace before ending ~~ +bool strike_predict_post(char *buf, int pos) +{ + unsigned char ch = buf[pos - 1]; + return ch != '\n' && ch != '\r' && ch != ' ' && ch != '\t'; +} + +#define STRIKE_POST strike_predict_post(G->buf, G->pos) + // Number of display formula raw opening unsigned char nr_dfr = 0; @@ -3926,7 +3935,7 @@ YY_RULE(int) yy_Strike(GREG *G) l632:; G->pos= yypos632; G->thunkpos= yythunkpos632; } if (!yy_Inline(G)) { goto l630; } goto l629; l630:; G->pos= yypos630; G->thunkpos= yythunkpos630; - } if (!yymatchString(G, "~~")) goto l627; yyText(G, G->begin, G->end); if (!(YY_END)) goto l627; yyDo(G, yy_1_Strike, G->begin, G->end); + } yyText(G, G->begin, G->end); if (!( STRIKE_POST )) goto l627; if (!yymatchString(G, "~~")) goto l627; yyText(G, G->begin, G->end); if (!(YY_END)) goto l627; yyDo(G, yy_1_Strike, G->begin, G->end); yyprintf((stderr, " ok %s @ %s\n", "Strike", G->buf+G->pos)); yyDo(G, yyPop, 1, 0); return 1; l627:; G->pos= yypos0; G->thunkpos= yythunkpos0;