mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
checkline was still having problems with properly detecting fenced code blocks
This commit is contained in:
+26
-24
@@ -178,10 +178,6 @@ splitline(Line *t, int cutpoint)
|
||||
|
||||
#define UNCHECK(t) ((t)->is_checked = 0)
|
||||
|
||||
#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.
|
||||
@@ -193,33 +189,36 @@ checkline(Line *l, mkd_flag_t *flags)
|
||||
int dashes = 0, spaces = 0,
|
||||
equals = 0, underscores = 0,
|
||||
stars = 0, tildes = 0, other = 0,
|
||||
backticks = 0, fenced = 0, others = 0;
|
||||
register int c, previous = 0;
|
||||
backticks = 0;
|
||||
register int c, first;
|
||||
|
||||
l->is_checked = 1;
|
||||
l->kind = chk_text;
|
||||
l->is_fenced = 0;
|
||||
l->count = 0;
|
||||
|
||||
|
||||
if (l->dle >= 4) { l->kind=chk_code; return; }
|
||||
|
||||
for ( eol = S(l->text); eol > l->dle && isspace(T(l->text)[eol-1]); --eol )
|
||||
;
|
||||
|
||||
if ( is_flag_set(flags, MKD_FENCEDCODE) ) {
|
||||
for ( i=l->dle; i<eol; i++ ) {
|
||||
c = T(l->text)[i];
|
||||
first = T(l->text)[l->dle];
|
||||
|
||||
if ( c != '~' && c != '`' && previous && previous != c )
|
||||
break;
|
||||
l->count++;
|
||||
previous = c;
|
||||
}
|
||||
if ( first == '~' || first == '`' ) {
|
||||
for ( i=l->dle; i<eol; i++ ) {
|
||||
c = T(l->text)[i];
|
||||
|
||||
if ( l->count > 1 ) {
|
||||
l->kind = (previous == '`' ? chk_backtick : chk_tilde);
|
||||
l->is_fenced = 1;
|
||||
return;
|
||||
if ( (c != '~') && (c != '`') && (c != first) )
|
||||
break;
|
||||
l->count++;
|
||||
}
|
||||
|
||||
if ( l->count > 1 ) {
|
||||
l->kind = (first == '`' ? chk_backtick : chk_tilde);
|
||||
l->is_fenced = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,20 +227,19 @@ checkline(Line *l, mkd_flag_t *flags)
|
||||
if ( (c = T(l->text)[i]) != ' ' ) l->count++;
|
||||
|
||||
switch (c) {
|
||||
case '-': UNLESS_FENCED(dashes = 1); break;
|
||||
case ' ': UNLESS_FENCED(spaces = 1); break;
|
||||
case '-': dashes = 1; break;
|
||||
case ' ': spaces = 1; break;
|
||||
case '=': equals = 1; break;
|
||||
case '_': UNLESS_FENCED(underscores = 1); break;
|
||||
case '_': underscores = 1; break;
|
||||
case '*': stars = 1; break;
|
||||
default:
|
||||
others = 1; break;
|
||||
default: other = 1; break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( dashes + equals + underscores + stars + tildes + backticks > 1 )
|
||||
return;
|
||||
|
||||
if ( !others ) {
|
||||
if ( !other ) {
|
||||
if (underscores || stars )
|
||||
l->kind = chk_hr;
|
||||
else if ( dashes )
|
||||
@@ -635,6 +633,10 @@ iscodefence(Line *r, int size, line_type kind, mkd_flag_t *flags)
|
||||
if ( !(r->is_checked) )
|
||||
checkline(r, flags);
|
||||
|
||||
if ( !r->is_fenced )
|
||||
return 0;
|
||||
|
||||
|
||||
if ( kind )
|
||||
return (r->kind == kind) && (r->count >= size);
|
||||
else
|
||||
|
||||
+19
-1
@@ -1,6 +1,6 @@
|
||||
. tests/functions.sh
|
||||
|
||||
title "code blocks"
|
||||
title "traditional code blocks"
|
||||
|
||||
rc=0
|
||||
MARKDOWN_FLAGS=
|
||||
@@ -12,6 +12,10 @@ try 'format for code block html' \
|
||||
code
|
||||
</code></pre>'
|
||||
|
||||
summary $0
|
||||
|
||||
title "fenced code blocks"
|
||||
|
||||
try 'fenced code disabled backtick' \
|
||||
'```
|
||||
|
||||
@@ -247,5 +251,19 @@ bar
|
||||
</code></pre>
|
||||
</p>'
|
||||
|
||||
|
||||
try -ffencedcode 'checkline misparse as fenced code' \
|
||||
'[`label`](#code)
|
||||
```class
|
||||
content
|
||||
```
|
||||
' \
|
||||
'<p><a href="#code"><code>label</code></a>
|
||||
<pre><code class="class">
|
||||
content
|
||||
</code></pre>
|
||||
</p>'
|
||||
|
||||
|
||||
summary $0
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user