mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
Tweak table handling to hew more closely to the markdown extra implementation.
In particular, expand `\` escapes to include `:` and `|`, and follow how the markdown extra dingus treats escaped line parts.
This commit is contained in:
+16
-2
@@ -1315,6 +1315,15 @@ text(MMIOT *f)
|
||||
Qchar(c, f);
|
||||
break;
|
||||
|
||||
case ':': case '|':
|
||||
if ( f->flags & MKD_NOTABLES ) {
|
||||
Qchar('\\', f);
|
||||
shift(f,-1);
|
||||
break;
|
||||
}
|
||||
Qchar(c, f);
|
||||
break;
|
||||
|
||||
case '>': case '#': case '.': case '-':
|
||||
case '+': case '{': case '}': case ']':
|
||||
case '!': case '[': case '*': case '_':
|
||||
@@ -1403,8 +1412,11 @@ splat(Line *p, char *block, Istring align, int force, MMIOT *f)
|
||||
if ( force && (colno >= S(align)-1) )
|
||||
idx = S(p->text);
|
||||
else
|
||||
while ( (idx < S(p->text)) && (T(p->text)[idx] != '|') )
|
||||
while ( (idx < S(p->text)) && (T(p->text)[idx] != '|') ) {
|
||||
if ( T(p->text)[idx] == '\\' )
|
||||
++idx;
|
||||
++idx;
|
||||
}
|
||||
|
||||
Qprintf(f, "<%s%s>",
|
||||
block,
|
||||
@@ -1452,7 +1464,9 @@ printtable(Paragraph *pp, MMIOT *f)
|
||||
|
||||
last=first=0;
|
||||
for (end=start ; (end < S(dash->text)) && p[end] != '|'; ++ end ) {
|
||||
if ( !isspace(p[end]) ) {
|
||||
if ( p[end] == '\\' )
|
||||
++ end;
|
||||
else if ( !isspace(p[end]) ) {
|
||||
if ( !first) first = p[end];
|
||||
last = p[end];
|
||||
}
|
||||
|
||||
@@ -287,6 +287,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
mkd_deallocate_tags();
|
||||
adump();
|
||||
exit( (rc == 0) ? 0 : errno );
|
||||
}
|
||||
|
||||
+12
-2
@@ -271,16 +271,26 @@ istable(Line *t)
|
||||
{
|
||||
char *p;
|
||||
Line *dashes = t->next;
|
||||
Line *body;
|
||||
int l;
|
||||
int contains = 0; /* found character bits; 0x01 is |, 0x02 is - */
|
||||
|
||||
/* two lines, first must contain | */
|
||||
/* three lines, first must contain |,
|
||||
second must be ---|---,
|
||||
third must contain |
|
||||
*/
|
||||
if ( !(dashes && memchr(T(t->text), '|', S(t->text))) )
|
||||
return 0;
|
||||
|
||||
body = dashes->next;
|
||||
|
||||
if ( !(body && memchr(T(body->text), '|', S(body->text))) )
|
||||
return 0;
|
||||
|
||||
/* second line must contain - or | and nothing
|
||||
* else except for whitespace or :
|
||||
*/
|
||||
for ( p = T(dashes->text)+S(dashes->text)-1; p >= T(dashes->text); --p)
|
||||
for ( p = T(dashes->text), l = S(dashes->text); l > 0; ++p, --l)
|
||||
if ( *p == '|' )
|
||||
contains |= 0x01;
|
||||
else if ( *p == '-' )
|
||||
|
||||
+47
-3
@@ -151,17 +151,61 @@ text' \
|
||||
try 'table headers only' \
|
||||
'a|b|c
|
||||
-|-|-' \
|
||||
'<p>a|b|c
|
||||
–|–|–</p>'
|
||||
|
||||
try 'escaped title line' \
|
||||
'A\|B
|
||||
--|-
|
||||
C |D' \
|
||||
'<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>a</th>
|
||||
<th>b</th>
|
||||
<th>c</th>
|
||||
<th>A|B</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>C |D</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>'
|
||||
|
||||
|
||||
try 'escaped dashes line' \
|
||||
'A |B
|
||||
-\|-
|
||||
C |D' \
|
||||
'<p>A |B
|
||||
–|–
|
||||
C |D</p>'
|
||||
|
||||
try 'escaped content line' \
|
||||
'A |B
|
||||
--|-
|
||||
C\|D' \
|
||||
'<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>A </th>
|
||||
<th>B</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>C|D</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>'
|
||||
|
||||
try 'content line w/o dashes' \
|
||||
'A |B
|
||||
--|-
|
||||
CD' \
|
||||
'<p>A |B
|
||||
—|–
|
||||
CD</p>'
|
||||
|
||||
summary $0
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user