ext/markdown.c in rdiscount-2.1.6 vs ext/markdown.c in rdiscount-2.1.7
- old
+ new
@@ -175,10 +175,13 @@
S(t->text) = cutpoint;
}
}
#define UNCHECK(l) ((l)->flags &= ~CHECKED)
+#define UNLESS_FENCED(t) if (fenced) { \
+ other = 1; l->count += (c == ' ' ? 0 : -1); \
+ } else { t; }
/*
* walk a line, seeing if it's any of half a dozen interesting regular
* types.
*/
@@ -186,12 +189,12 @@
checkline(Line *l)
{
int eol, i;
int dashes = 0, spaces = 0,
equals = 0, underscores = 0,
- stars = 0, tildes = 0,
- backticks = 0;
+ stars = 0, tildes = 0, other = 0,
+ backticks = 0, fenced = 0;
l->flags |= CHECKED;
l->kind = chk_text;
l->count = 0;
@@ -204,20 +207,23 @@
register int c = T(l->text)[i];
if ( c != ' ' ) l->count++;
switch (c) {
- case '-': dashes = 1; break;
- case ' ': spaces = 1; break;
+ case '-': UNLESS_FENCED(dashes = 1); break;
+ case ' ': UNLESS_FENCED(spaces = 1); break;
case '=': equals = 1; break;
- case '_': underscores = 1; break;
+ case '_': UNLESS_FENCED(underscores = 1); break;
case '*': stars = 1; break;
#if WITH_FENCED_CODE
- case '~': tildes = 1; break;
- case '`': backticks = 1; break;
+ case '~': if (other) return; fenced = 1; tildes = 1; break;
+ case '`': if (other) return; fenced = 1; backticks = 1; break;
#endif
- default: return;
+ default:
+ other = 1;
+ l->count--;
+ if (!fenced) return;
}
}
if ( dashes + equals + underscores + stars + tildes + backticks > 1 )
return;
@@ -636,9 +642,17 @@
*/
for ( r = first; r && r->next; r = r->next )
if ( iscodefence(r->next, first->count, first->kind) ) {
(*ptr) = r->next->next;
ret = Pp(d, first->next, CODE);
+ if (S(first->text) - first->count > 0) {
+ char *lang_attr = T(first->text) + first->count;
+ while ( *lang_attr != 0 && *lang_attr == ' ' ) lang_attr++;
+ ret->lang = strdup(lang_attr);
+ }
+ else {
+ ret->lang = 0;
+ }
___mkd_freeLine(first);
___mkd_freeLine(r->next);
r->next = 0;
return ret;
}