mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
1. Add the new E(x) abstraction for the ANCHOR() class, use
that when processing Lines in compile_document(). 2. Add some test cases for [footnote] links showing up in random places. 3. In `dumptree()`, show the `ident` string ,if any, associated with a given block.
This commit is contained in:
@@ -60,9 +60,10 @@
|
||||
* macro will work with it.
|
||||
*/
|
||||
#define ANCHOR(t) struct { t *text, *end; }
|
||||
#define E(t) ((t).end)
|
||||
|
||||
#define ATTACH(t, p) ( (t).text ?( ((t).end->next = (p)), ((t).end = (p)) ) \
|
||||
:( ((t).text = (t).end = (p)) ) )
|
||||
#define ATTACH(t, p) ( T(t) ? ( (E(t)->next = (p)), (E(t) = (p)) ) \
|
||||
: ( (T(t) = E(t) = (p)) ) )
|
||||
|
||||
typedef STRING(char) Cstring;
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ dumptree(Paragraph *pp, Stack *sp, FILE *f)
|
||||
printpfx(sp, f);
|
||||
|
||||
d = fprintf(f, "[%s", Pptype(pp->typ));
|
||||
if ( pp->ident )
|
||||
d += fprintf(f, " %s", pp->ident);
|
||||
if ( pp->align )
|
||||
d += fprintf(f, ", <%s>", Begin[pp->align]);
|
||||
|
||||
|
||||
+24
-17
@@ -889,24 +889,28 @@ consume(Line *ptr, int *eaten)
|
||||
|
||||
/*
|
||||
* top-level compilation; break the document into
|
||||
* style, html, and text blocks with footnote links
|
||||
* style, html, and source blocks with footnote links
|
||||
* weeded out.
|
||||
*/
|
||||
static Paragraph *
|
||||
compile_document(Line *ptr, MMIOT *f)
|
||||
{
|
||||
ParagraphRoot d = { 0, 0 };
|
||||
ANCHOR(Line) source = { 0, 0 };
|
||||
Paragraph *p = 0;
|
||||
Line *text = 0, *tail = 0;
|
||||
struct kw *tag;
|
||||
int eaten;
|
||||
|
||||
while ( ptr ) {
|
||||
if ( !(f->flags & DENY_HTML) && (tag = isopentag(ptr)) ) {
|
||||
if ( text ) {
|
||||
/* If we encounter a html/style block, compile and save all
|
||||
* of the cached source BEFORE processing the html/style.
|
||||
*/
|
||||
if ( T(source) ) {
|
||||
E(source)->next = 0;
|
||||
p = Pp(&d, 0, SOURCE);
|
||||
p->down = compile(text, 1, f);
|
||||
text = tail = 0;
|
||||
p->down = compile(T(source), 1, f);
|
||||
T(source) = E(source) = 0;
|
||||
}
|
||||
p = Pp(&d, ptr, strcmp(tag->id, "STYLE") == 0 ? STYLE : HTML);
|
||||
if ( strcmp(tag->id, "!--") == 0 )
|
||||
@@ -915,24 +919,27 @@ compile_document(Line *ptr, MMIOT *f)
|
||||
ptr = htmlblock(p, tag);
|
||||
}
|
||||
else if ( isfootnote(ptr) ) {
|
||||
/* footnotes, like cats, sleep anywhere; pull them
|
||||
* out of the input stream and file them away for
|
||||
* later processing
|
||||
*/
|
||||
ptr = consume(addfootnote(ptr, f), &eaten);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
Line *r = ptr->next;
|
||||
if ( tail ) {
|
||||
tail->next = ptr;
|
||||
tail = ptr;
|
||||
}
|
||||
else
|
||||
text = tail = ptr;
|
||||
tail->next = 0;
|
||||
ptr = r;
|
||||
/* source; cache it up to wait for eof or the
|
||||
* next html/style block
|
||||
*/
|
||||
ATTACH(source,ptr);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
if ( text ) {
|
||||
if ( T(source) ) {
|
||||
/* if there's any cached source at EOF, compile
|
||||
* it now.
|
||||
*/
|
||||
E(source)->next = 0;
|
||||
p = Pp(&d, 0, SOURCE);
|
||||
p->down = compile(text, 1, f);
|
||||
p->down = compile(T(source), 1, f);
|
||||
}
|
||||
return T(d);
|
||||
}
|
||||
|
||||
@@ -89,4 +89,32 @@ try 'footnote cuddled up to text' \
|
||||
[bar]:bar' \
|
||||
'<p>foo</p>'
|
||||
|
||||
try 'mid-paragraph footnote' \
|
||||
'talk talk talk talk
|
||||
[bar]: bar
|
||||
talk talk talk talk' \
|
||||
'<p>talk talk talk talk
|
||||
talk talk talk talk</p>'
|
||||
|
||||
try 'mid-blockquote footnote' \
|
||||
'>blockquote!
|
||||
[footnote]: here!
|
||||
>blockquote!' \
|
||||
'<blockquote><p>blockquote!
|
||||
blockquote!</p></blockquote>'
|
||||
|
||||
try 'end-blockquote footnote' \
|
||||
'>blockquote!
|
||||
>blockquote!
|
||||
[footnote]: here!' \
|
||||
'<blockquote><p>blockquote!
|
||||
blockquote!</p></blockquote>'
|
||||
|
||||
try 'start-blockquote footnote' \
|
||||
'[footnote]: here!
|
||||
>blockquote!
|
||||
>blockquote!' \
|
||||
'<blockquote><p>blockquote!
|
||||
blockquote!</p></blockquote>'
|
||||
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user