ext/generate.c in patcito-rdiscount-1.6.8 vs ext/generate.c in patcito-rdiscount-1.6.9

- old
+ new

@@ -1070,11 +1070,11 @@ static int smartypants(int c, int *flags, MMIOT *f) { int i; - if ( f->flags & (MKD_NOPANTS|MKD_TAGTEXT|IS_LABEL|MKD_MATH) ) + if ( f->flags & (MKD_NOPANTS|MKD_TAGTEXT|IS_LABEL) ) return 0; for ( i=0; i < NRSMART; i++) if ( (c == smarties[i].c0) && islike(f, smarties[i].pat) ) { if ( smarties[i].entity ) @@ -1138,57 +1138,17 @@ return 1; } return 0; } -static int -ismathleft(MMIOT *f, int offset) -{ - int i; +#define tag_text(f) (f->flags & MKD_TAGTEXT) - while (peek(f,offset-1) == '$') - --offset; - i = 1; - while (peek(f,offset-i) == '\\') - ++i; - if ( (i % 2) == 0 ) - return 0; - - while (!isthisspace(f,offset-i)) { - if (isthisalnum(f,offset-i)) - return 0; - ++i; - } - - return !isthisspace(f,offset+1); -} - -static int -ismathright(MMIOT *f, int offset) -{ - int i; - - while (peek(f,offset+1) == '$') - ++offset; - - i = 1; - while (peek(f,offset-i) == '\\') - ++i; - if ( (i % 2) == 0 ) - return 0; - - return !isthisalnum(f,offset+1); -} - -#define protected(f) (f->flags & (MKD_TAGTEXT|MKD_MATH)) - - static void text(MMIOT *f) { - int c, j, escape; + int c, j; int rep; int smartyflags = 0; while (1) { if ( (f->flags & MKD_AUTOLINK) && isalpha(peek(f,1)) && !tag_text(f) ) @@ -1202,38 +1162,38 @@ if ( smartypants(c, &smartyflags, f) ) continue; switch (c) { case 0: break; - case 3: Qstring(protected(f) ? " " : "<br/>", f); + case 3: Qstring(tag_text(f) ? " " : "<br/>", f); break; - case '>': if ( protected(f) ) + case '>': if ( tag_text(f) ) Qstring("&gt;", f); else Qchar(c, f); break; - case '"': if ( protected(f) ) + case '"': if ( tag_text(f) ) Qstring("&quot;", f); else Qchar(c, f); break; case '!': if ( peek(f,1) == '[' ) { pull(f); - if ( protected(f) || !linkylinky(1, f) ) + if ( tag_text(f) || !linkylinky(1, f) ) Qstring("![", f); } else Qchar(c, f); break; - case '[': if ( protected(f) || !linkylinky(0, f) ) + case '[': if ( tag_text(f) || !linkylinky(0, f) ) Qchar(c, f); break; /* A^B -> A<sup>B</sup> */ - case '^': if ( (f->flags & (MKD_NOSUPERSCRIPT|MKD_STRICT|MKD_TAGTEXT|MKD_MATH)) + case '^': if ( (f->flags & (MKD_NOSUPERSCRIPT|MKD_STRICT|MKD_TAGTEXT)) || (isthisnonword(f,-1) && peek(f,-1) != ')') || isthisspace(f,1) ) Qchar(c,f); else { char *sup = cursor(f); @@ -1278,49 +1238,23 @@ if ( isthisspace(f,-1) && isthisspace(f,1) ) { Qchar(c, f); break; } /* else fall into the regular old emphasis case */ - if ( protected(f) ) + if ( tag_text(f) ) Qchar(c, f); else { for (rep = 1; peek(f,1) == c; pull(f) ) ++rep; Qem(f,c,rep); } break; - case '$': - if ( (f->flags & MKD_PROTECTMATH) && !(f->flags & MKD_TAGTEXT)) { - escape = 1; - for (j = 1; peek(f,j) == '$';) - ++j; - if ( ismathleft(f,j-1) ) { - for (; (c = peek(f,j)) != EOF; j++) { - if ((c == '\n' && peek(f,j+1) == '\n') - || (c == '$' && ismathleft(f,j))) - break; - if (c == '$' && ismathright(f,j)) { - escape = 0; - f->flags |= MKD_MATH; - break; - } - } - } else if ( ismathright(f,j-1) ) { - escape = 0; - f->flags &= ~MKD_MATH; - } - if (escape) - Qchar('\\', f); - } - Qchar('$', f); - break; - - case '~': if ( (f->flags & (MKD_NOSTRIKETHROUGH|MKD_TAGTEXT|MKD_STRICT|MKD_MATH)) || !tickhandler(f,c,2,delspan) ) + case '~': if ( (f->flags & (MKD_NOSTRIKETHROUGH|MKD_TAGTEXT|MKD_STRICT)) || !tickhandler(f,c,2,delspan) ) Qchar(c, f); break; - case '`': if ( protected(f) || !tickhandler(f,c,1,codespan) ) + case '`': if ( tag_text(f) || !tickhandler(f,c,1,codespan) ) Qchar(c, f); break; case '\\': switch ( c = pull(f) ) { case '&': Qstring("&amp;", f);