Commit 8d8efc1d authored by Alessandro Ghedini's avatar Alessandro Ghedini

Imported Upstream version 2.1.2

parent 38e6fbd2
......@@ -29,5 +29,7 @@ Andrew White -- bug reports about the format of generated urls.
Steve Huff -- bug reports about Makefile portability (for Fink)
Ignacio Burgue?o-- bug reports about `>%class%`
Henrik Nyh -- bug reports about embedded html handling.
John J. Foerch -- bug reports about incorrect `–` and `—`
translations.
......@@ -1403,12 +1403,18 @@ static char* alignments[] = { "", " align=\"center\"", " align=\"left\"",
typedef STRING(int) Istring;
static int
splat(Line *p, char *block, Istring align, int force, MMIOT *f)
splat(Line *p, int leading_pipe, char *block, Istring align, int force, MMIOT *f)
{
int first,
idx = 0,
idx = p->dle,
colno = 0;
if ( leading_pipe ) idx++;
___mkd_tidy(&p->text);
if ( T(p->text)[S(p->text)-1] == '|' )
--S(p->text);
Qstring("<tr>\n", f);
while ( idx < S(p->text) ) {
first = idx;
......@@ -1446,17 +1452,15 @@ printtable(Paragraph *pp, MMIOT *f)
Line *hdr, *dash, *body;
Istring align;
int start;
int hcols;
int hcols,start,starts_with_pipe=0;
char *p;
if ( !(pp->text && pp->text->next) )
return 0;
hdr = pp->text;
dash= hdr->next;
body= dash->next;
starts_with_pipe = T(hdr->text)[hdr->dle] == '|';
/* first figure out cell alignments */
CREATE(align);
......@@ -1481,7 +1485,7 @@ printtable(Paragraph *pp, MMIOT *f)
Qstring("<table>\n", f);
Qstring("<thead>\n", f);
hcols = splat(hdr, "th", align, 0, f);
hcols = splat(hdr, starts_with_pipe, "th", align, 0, f);
Qstring("</thead>\n", f);
if ( hcols < S(align) )
......@@ -1492,7 +1496,7 @@ printtable(Paragraph *pp, MMIOT *f)
Qstring("<tbody>\n", f);
for ( ; body; body = body->next)
splat(body, "td", align, 1, f);
splat(body, starts_with_pipe, "td", align, 1, f);
Qstring("</tbody>\n", f);
Qstring("</table>\n", f);
......
......@@ -319,47 +319,6 @@ htmlblock(Paragraph *p, struct kw *tag, int *unclosed)
}
/* tables look like
* header|header{|header}
* ------|------{|......}
* {body lines}
*/
static int
istable(Line *t)
{
char *p;
Line *dashes, *body;
int l;
int dashed = 0;
/* three lines, first must contain |,
second must be ---|---,
third must contain |
*/
if ( !(t->flags & PIPECHAR) )
return 0;
dashes = t->next;
if ( !(dashes && (dashes->flags & PIPECHAR)) )
return 0;
body = dashes->next;
if ( !(body && (body->flags & PIPECHAR)) )
return 0;
/* second line must contain - or | and nothing
* else except for whitespace or :
*/
for ( p = T(dashes->text), l = S(dashes->text); l > 0; ++p, --l)
if ( *p == '-' )
dashed = 1;
else if ( ! ((*p == '|') || (*p == ':') || isspace(*p)) )
return 0;
return dashed;
}
/* footnotes look like ^<whitespace>{0,3}[stuff]: <content>$
*/
static int
......@@ -841,25 +800,6 @@ quoteblock(Paragraph *p, DWORD flags)
}
/*
* A table block starts with a table header (see istable()), and continues
* until EOF or a line that /doesn't/ contain a |.
*/
static Line *
tableblock(Paragraph *p)
{
Line *t, *q;
for ( t = p->text; t && (q = t->next); t = t->next ) {
if ( !(t->flags & PIPECHAR) ) {
t->next = 0;
return q;
}
}
return 0;
}
typedef int (*linefn)(Line *);
......@@ -1189,6 +1129,58 @@ compile_document(Line *ptr, MMIOT *f)
}
static int
first_nonblank_before(Line *j, int dle)
{
return (j->dle < dle) ? j->dle : dle;
}
static int
actually_a_table(MMIOT *f, Line *pp)
{
Line *r;
int j;
int c;
/* tables need to be turned on */
if ( f->flags & (MKD_STRICT|MKD_NOTABLES) )
return 0;
/* tables need three lines */
if ( !(pp && pp->next && pp->next->next) ) {
return 0;
}
/* all lines must contain |'s */
for (r = pp; r; r = r->next )
if ( !(r->flags & PIPECHAR) ) {
return 0;
}
/* if the header has a leading |, all lines must have leading |'s */
if ( T(pp->text)[pp->dle] == '|' ) {
for ( r = pp; r; r = r->next )
if ( T(r->text)[first_nonblank_before(r,pp->dle)] != '|' ) {
return 0;
}
}
/* second line must be only whitespace, -, |, or : */
r = pp->next;
for ( j=r->dle; j < S(r->text); ++j ) {
c = T(r->text)[j];
if ( !(isspace(c)||(c=='-')||(c==':')||(c=='|')) ) {
return 0;
}
}
return 1;
}
/*
* break a collection of markdown input into
* blocks of lists, code, html, and text to
......@@ -1249,13 +1241,12 @@ compile(Line *ptr, int toplevel, MMIOT *f)
p = Pp(&d, ptr, HDR);
ptr = headerblock(p, hdr_type);
}
else if ( istable(ptr) && !(f->flags & (MKD_STRICT|MKD_NOTABLES)) ) {
p = Pp(&d, ptr, TABLE);
ptr = tableblock(p);
}
else {
p = Pp(&d, ptr, MARKUP);
ptr = textblock(p, toplevel, f->flags);
/* tables are a special kind of paragraph */
if ( actually_a_table(f, p->text) )
p->typ = TABLE;
}
if ( (para||toplevel) && !p->align )
......
......@@ -12,13 +12,11 @@ try 'single-column table' \
'<table>
<thead>
<tr>
<th></th>
<th>hello</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>sailor</td>
</tr>
</tbody>
......@@ -33,7 +31,7 @@ hello|sailor' \
'<table>
<thead>
<tr>
<th> a </th>
<th>a </th>
<th> b</th>
</tr>
</thead>
......@@ -75,7 +73,7 @@ hello|
'<table>
<thead>
<tr>
<th> a </th>
<th>a </th>
<th> b</th>
</tr>
</thead>
......@@ -85,7 +83,7 @@ hello|
<td></td>
</tr>
<tr>
<td> </td>
<td></td>
<td>sailor</td>
</tr>
</tbody>
......@@ -99,7 +97,7 @@ hello|sailor' \
'<table>
<thead>
<tr>
<th align="right"> a </th>
<th align="right">a </th>
<th align="left"> b</th>
</tr>
</thead>
......@@ -119,7 +117,7 @@ hello|sailor|boy' \
'<table>
<thead>
<tr>
<th> a </th>
<th>a </th>
<th> b</th>
</tr>
</thead>
......@@ -207,5 +205,50 @@ CD' \
&ndash;|-
CD</p>'
try 'table followed by text' \
'
A|B
-|-
C|D
foo?' \
'<table>
<thead>
<tr>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<td>C</td>
<td>D</td>
</tr>
</tbody>
</table>
<p>foo?</p>'
try "table with flanking |'s" \
'
|A|B|
|-|-|
|D|C|' \
'<table>
<thead>
<tr>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<td>D</td>
<td>C</td>
</tr>
</tbody>
</table>'
summary $0
exit $rc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment