|
|
@@ -38,6 +38,16 @@ push(char *bfr, int size, MMIOT *f)
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+ * push a character into the generator input buffer
|
|
|
+ */
|
|
|
+static void
|
|
|
+pushc(char c, MMIOT *f)
|
|
|
+{
|
|
|
+ EXPAND(f->in) = c;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/* look <i> characters ahead of the cursor.
|
|
|
*/
|
|
|
static inline int
|
|
|
@@ -73,7 +83,11 @@ isthisspace(MMIOT *f, int i)
|
|
|
{
|
|
|
int c = peek(f, i);
|
|
|
|
|
|
- return isspace(c) || (c == EOF);
|
|
|
+ if ( c == EOF )
|
|
|
+ return 1;
|
|
|
+ if ( c & 0x80 )
|
|
|
+ return 0;
|
|
|
+ return isspace(c) || (c < ' ');
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -194,9 +208,10 @@ Qem(MMIOT *f, char c, int count)
|
|
|
/* generate html from a markup fragment
|
|
|
*/
|
|
|
void
|
|
|
-___mkd_reparse(char *bfr, int size, int flags, MMIOT *f)
|
|
|
+___mkd_reparse(char *bfr, int size, int flags, MMIOT *f, char *esc)
|
|
|
{
|
|
|
MMIOT sub;
|
|
|
+ struct escaped e;
|
|
|
|
|
|
___mkd_initmmiot(&sub, f->footnotes);
|
|
|
|
|
|
@@ -204,6 +219,14 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f)
|
|
|
sub.cb = f->cb;
|
|
|
sub.ref_prefix = f->ref_prefix;
|
|
|
|
|
|
+ if ( esc ) {
|
|
|
+ sub.esc = &e;
|
|
|
+ e.up = f->esc;
|
|
|
+ e.text = esc;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ sub.esc = f->esc;
|
|
|
+
|
|
|
push(bfr, size, &sub);
|
|
|
EXPAND(sub.in) = 0;
|
|
|
S(sub.in)--;
|
|
|
@@ -217,6 +240,23 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f)
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+ * check the escape list for special cases
|
|
|
+ */
|
|
|
+static int
|
|
|
+escaped(MMIOT *f, char c)
|
|
|
+{
|
|
|
+ struct escaped *thing = f->esc;
|
|
|
+
|
|
|
+ while ( thing ) {
|
|
|
+ if ( strchr(thing->text, c) )
|
|
|
+ return 1;
|
|
|
+ thing = thing->up;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/*
|
|
|
* write out a url, escaping problematic characters
|
|
|
*/
|
|
|
@@ -243,7 +283,7 @@ puturl(char *s, int size, MMIOT *f, int display)
|
|
|
Qstring("%22", f);
|
|
|
else if ( isalnum(c) || ispunct(c) || (display && isspace(c)) )
|
|
|
Qchar(c, f);
|
|
|
- else if ( c == 003 ) /* untokenize ^C */
|
|
|
+ else if ( c == MKD_EOLN ) /* untokenize hard return */
|
|
|
Qstring(" ", f);
|
|
|
else
|
|
|
Qprintf(f, "%%%02X", c);
|
|
|
@@ -366,7 +406,7 @@ linkysize(MMIOT *f, Footnote *ref)
|
|
|
/* extract a <...>-encased url from the input stream.
|
|
|
* (markdown 1.0.2b8 compatibility; older versions
|
|
|
* of markdown treated the < and > as syntactic
|
|
|
- * sugar that didn't have to be there. 1.0.2b8
|
|
|
+ * sugar that didn't have to be there. 1.0.2b8
|
|
|
* requires a closing >, and then falls into the
|
|
|
* title or closing )
|
|
|
*/
|
|
|
@@ -564,7 +604,7 @@ printlinkyref(MMIOT *f, linkytype *tag, char *link, int size)
|
|
|
puturl(link + tag->szpat, size - tag->szpat, f, 0);
|
|
|
}
|
|
|
else
|
|
|
- ___mkd_reparse(link + tag->szpat, size - tag->szpat, MKD_TAGTEXT, f);
|
|
|
+ ___mkd_reparse(link + tag->szpat, size - tag->szpat, MKD_TAGTEXT, f, 0);
|
|
|
|
|
|
Qstring(tag->link_sfx, f);
|
|
|
|
|
|
@@ -596,10 +636,10 @@ extra_linky(MMIOT *f, Cstring text, Footnote *ref)
|
|
|
return 0;
|
|
|
|
|
|
if ( f->flags & IS_LABEL )
|
|
|
- ___mkd_reparse(T(text), S(text), linkt.flags, f);
|
|
|
+ ___mkd_reparse(T(text), S(text), linkt.flags, f, 0);
|
|
|
else {
|
|
|
ref->flags |= REFERENCED;
|
|
|
- ref->refnumber = ++ f->reference;
|
|
|
+ ref->refnumber = ++ f->footnotes->reference;
|
|
|
Qprintf(f, "<sup id=\"%sref:%d\"><a href=\"#%s:%d\" rel=\"footnote\">%d</a></sup>",
|
|
|
p_or_nothing(f), ref->refnumber,
|
|
|
p_or_nothing(f), ref->refnumber, ref->refnumber);
|
|
|
@@ -615,7 +655,8 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref)
|
|
|
{
|
|
|
linkytype *tag;
|
|
|
|
|
|
- if ( image || (ref == 0) )
|
|
|
+
|
|
|
+ if ( image )
|
|
|
tag = &imaget;
|
|
|
else if ( tag = pseudo(ref->link) ) {
|
|
|
if ( f->flags & (MKD_NO_EXT|MKD_SAFELINK) )
|
|
|
@@ -635,7 +676,7 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref)
|
|
|
return 0;
|
|
|
|
|
|
if ( f->flags & IS_LABEL )
|
|
|
- ___mkd_reparse(T(text), S(text), tag->flags, f);
|
|
|
+ ___mkd_reparse(T(text), S(text), tag->flags, f, 0);
|
|
|
else if ( tag->link_pfx ) {
|
|
|
printlinkyref(f, tag, T(ref->link), S(ref->link));
|
|
|
|
|
|
@@ -646,12 +687,12 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref)
|
|
|
|
|
|
if ( S(ref->title) ) {
|
|
|
Qstring(" title=\"", f);
|
|
|
- ___mkd_reparse(T(ref->title), S(ref->title), MKD_TAGTEXT, f);
|
|
|
+ ___mkd_reparse(T(ref->title), S(ref->title), MKD_TAGTEXT, f, 0);
|
|
|
Qchar('"', f);
|
|
|
}
|
|
|
|
|
|
Qstring(tag->text_pfx, f);
|
|
|
- ___mkd_reparse(T(text), S(text), tag->flags, f);
|
|
|
+ ___mkd_reparse(T(text), S(text), tag->flags, f, 0);
|
|
|
Qstring(tag->text_sfx, f);
|
|
|
}
|
|
|
else
|
|
|
@@ -711,8 +752,9 @@ linkylinky(int image, MMIOT *f)
|
|
|
S(key.tag) = S(name);
|
|
|
}
|
|
|
|
|
|
- if ( ref = bsearch(&key, T(*f->footnotes), S(*f->footnotes),
|
|
|
- sizeof key, (stfu)__mkd_footsort) ) {
|
|
|
+ if ( ref = bsearch(&key, T(f->footnotes->note),
|
|
|
+ S(f->footnotes->note),
|
|
|
+ sizeof key, (stfu)__mkd_footsort) ) {
|
|
|
if ( extra_footnote )
|
|
|
status = extra_linky(f,name,ref);
|
|
|
else
|
|
|
@@ -756,8 +798,12 @@ static void
|
|
|
mangle(char *s, int len, MMIOT *f)
|
|
|
{
|
|
|
while ( len-- > 0 ) {
|
|
|
+#if DEBIAN_GLITCH
|
|
|
+ Qprintf(f, "&#%02d;", *((unsigned char*)(s++)) );
|
|
|
+#else
|
|
|
Qstring("&#", f);
|
|
|
Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
|
|
|
+#endif
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -819,20 +865,21 @@ code(MMIOT *f, char *s, int length)
|
|
|
int i,c;
|
|
|
|
|
|
for ( i=0; i < length; i++ )
|
|
|
- if ( (c = s[i]) == 003) /* ^C: expand back to 2 spaces */
|
|
|
+ if ( (c = s[i]) == MKD_EOLN) /* ^C: expand back to 2 spaces */
|
|
|
Qstring(" ", f);
|
|
|
+ else if ( c == '\\' && (i < length-1) && escaped(f, s[i+1]) )
|
|
|
+ cputc(s[++i], f);
|
|
|
else
|
|
|
cputc(c, f);
|
|
|
} /* code */
|
|
|
|
|
|
-
|
|
|
/* delspan() -- write out a chunk of text, blocking with <del>...</del>
|
|
|
*/
|
|
|
static void
|
|
|
delspan(MMIOT *f, int size)
|
|
|
{
|
|
|
Qstring("<del>", f);
|
|
|
- ___mkd_reparse(cursor(f)-1, size, 0, f);
|
|
|
+ ___mkd_reparse(cursor(f)-1, size, 0, f, 0);
|
|
|
Qstring("</del>", f);
|
|
|
}
|
|
|
|
|
|
@@ -974,11 +1021,9 @@ maybe_tag_or_link(MMIOT *f)
|
|
|
}
|
|
|
else if ( isspace(c) )
|
|
|
break;
|
|
|
-#if WITH_GITHUB_TAGS
|
|
|
- else if ( ! (c == '/' || c == '-' || c == '_' || isalnum(c) ) )
|
|
|
-#else
|
|
|
- else if ( ! (c == '/' || isalnum(c) ) )
|
|
|
-#endif
|
|
|
+ else if ( ! (c == '/'
|
|
|
+ || (f->flags & MKD_GITHUBTAGS && (c == '-' || c == '_'))
|
|
|
+ || isalnum(c) ) )
|
|
|
maybetag=0;
|
|
|
}
|
|
|
|
|
|
@@ -1024,13 +1069,16 @@ maybe_autolink(MMIOT *f)
|
|
|
|
|
|
/* greedily scan forward for the end of a legitimate link.
|
|
|
*/
|
|
|
- for ( size=0; (c=peek(f, size+1)) != EOF; size++ )
|
|
|
+ for ( size=0; (c=peek(f, size+1)) != EOF; size++ ) {
|
|
|
if ( c == '\\' ) {
|
|
|
if ( peek(f, size+2) != EOF )
|
|
|
++size;
|
|
|
}
|
|
|
- else if ( isspace(c) || strchr("'\"()[]{}<>`", c) )
|
|
|
+ else if ( c & 0x80 ) /* HACK: ignore utf-8 extended characters */
|
|
|
+ continue;
|
|
|
+ else if ( isspace(c) || strchr("'\"()[]{}<>`", c) || c == MKD_EOLN )
|
|
|
break;
|
|
|
+ }
|
|
|
|
|
|
if ( (size > 1) && process_possible_link(f, size) ) {
|
|
|
shift(f, size);
|
|
|
@@ -1069,7 +1117,7 @@ islike(MMIOT *f, char *s)
|
|
|
int len;
|
|
|
int i;
|
|
|
|
|
|
- if ( s[0] == '<' ) {
|
|
|
+ if ( s[0] == '|' ) {
|
|
|
if ( !isthisnonword(f, -1) )
|
|
|
return 0;
|
|
|
++s;
|
|
|
@@ -1078,7 +1126,7 @@ islike(MMIOT *f, char *s)
|
|
|
if ( !(len = strlen(s)) )
|
|
|
return 0;
|
|
|
|
|
|
- if ( s[len-1] == '>' ) {
|
|
|
+ if ( s[len-1] == '|' ) {
|
|
|
if ( !isthisnonword(f,len-1) )
|
|
|
return 0;
|
|
|
len--;
|
|
|
@@ -1097,13 +1145,13 @@ static struct smarties {
|
|
|
char *entity;
|
|
|
int shift;
|
|
|
} smarties[] = {
|
|
|
- { '\'', "'s>", "rsquo", 0 },
|
|
|
- { '\'', "'t>", "rsquo", 0 },
|
|
|
- { '\'', "'re>", "rsquo", 0 },
|
|
|
- { '\'', "'ll>", "rsquo", 0 },
|
|
|
- { '\'', "'ve>", "rsquo", 0 },
|
|
|
- { '\'', "'m>", "rsquo", 0 },
|
|
|
- { '\'', "'d>", "rsquo", 0 },
|
|
|
+ { '\'', "'s|", "rsquo", 0 },
|
|
|
+ { '\'', "'t|", "rsquo", 0 },
|
|
|
+ { '\'', "'re|", "rsquo", 0 },
|
|
|
+ { '\'', "'ll|", "rsquo", 0 },
|
|
|
+ { '\'', "'ve|", "rsquo", 0 },
|
|
|
+ { '\'', "'m|", "rsquo", 0 },
|
|
|
+ { '\'', "'d|", "rsquo", 0 },
|
|
|
{ '-', "---", "mdash", 2 },
|
|
|
{ '-', "--", "ndash", 1 },
|
|
|
{ '.', "...", "hellip", 2 },
|
|
|
@@ -1111,11 +1159,11 @@ static struct smarties {
|
|
|
{ '(', "(c)", "copy", 2 },
|
|
|
{ '(', "(r)", "reg", 2 },
|
|
|
{ '(', "(tm)", "trade", 3 },
|
|
|
- { '3', "<3/4>", "frac34", 2 },
|
|
|
- { '3', "<3/4ths>", "frac34", 2 },
|
|
|
- { '1', "<1/2>", "frac12", 2 },
|
|
|
- { '1', "<1/4>", "frac14", 2 },
|
|
|
- { '1', "<1/4th>", "frac14", 2 },
|
|
|
+ { '3', "|3/4|", "frac34", 2 },
|
|
|
+ { '3', "|3/4ths|", "frac34", 2 },
|
|
|
+ { '1', "|1/2|", "frac12", 2 },
|
|
|
+ { '1', "|1/4|", "frac14", 2 },
|
|
|
+ { '1', "|1/4th|", "frac14", 2 },
|
|
|
{ '&', "�", 0, 3 },
|
|
|
} ;
|
|
|
#define NRSMART ( sizeof smarties / sizeof smarties[0] )
|
|
|
@@ -1157,7 +1205,7 @@ smartypants(int c, int *flags, MMIOT *f)
|
|
|
break;
|
|
|
else if ( c == '\'' && peek(f, j+1) == '\'' ) {
|
|
|
Qstring("“", f);
|
|
|
- ___mkd_reparse(cursor(f)+1, j-2, 0, f);
|
|
|
+ ___mkd_reparse(cursor(f)+1, j-2, 0, f, 0);
|
|
|
Qstring("”", f);
|
|
|
shift(f,j+1);
|
|
|
return 1;
|
|
|
@@ -1172,6 +1220,29 @@ smartypants(int c, int *flags, MMIOT *f)
|
|
|
} /* smartypants */
|
|
|
|
|
|
|
|
|
+#if WITH_LATEX
|
|
|
+/* process latex with arbitrary 2-character ( $$ .. $$, \[ .. \], \( .. \)
|
|
|
+ * delimiters
|
|
|
+ */
|
|
|
+static int
|
|
|
+mathhandler(MMIOT *f, int e1, int e2)
|
|
|
+{
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ while(peek(f, ++i) != EOF) {
|
|
|
+ if (peek(f, i) == e1 && peek(f, i+1) == e2) {
|
|
|
+ cputc(peek(f,-1), f);
|
|
|
+ cputc(peek(f, 0), f);
|
|
|
+ while ( i-- > -1 )
|
|
|
+ cputc(pull(f), f);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
/* process a body of text encased in some sort of tick marks. If it
|
|
|
* works, generate the output and return 1, otherwise just return 0 and
|
|
|
* let the caller figure it out.
|
|
|
@@ -1223,7 +1294,8 @@ text(MMIOT *f)
|
|
|
switch (c) {
|
|
|
case 0: break;
|
|
|
|
|
|
- case 3: Qstring(tag_text(f) ? " " : "<br/>", f);
|
|
|
+ case MKD_EOLN:
|
|
|
+ Qstring(tag_text(f) ? " " : "<br/>", f);
|
|
|
break;
|
|
|
|
|
|
case '>': if ( tag_text(f) )
|
|
|
@@ -1246,6 +1318,7 @@ text(MMIOT *f)
|
|
|
else
|
|
|
Qchar(c, f);
|
|
|
break;
|
|
|
+
|
|
|
case '[': if ( tag_text(f) || !linkylinky(0, f) )
|
|
|
Qchar(c, f);
|
|
|
break;
|
|
|
@@ -1279,7 +1352,7 @@ text(MMIOT *f)
|
|
|
shift(f,len);
|
|
|
}
|
|
|
Qstring("<sup>",f);
|
|
|
- ___mkd_reparse(sup, len, 0, f);
|
|
|
+ ___mkd_reparse(sup, len, 0, f, "()");
|
|
|
Qstring("</sup>", f);
|
|
|
}
|
|
|
break;
|
|
|
@@ -1319,7 +1392,16 @@ text(MMIOT *f)
|
|
|
case '\\': switch ( c = pull(f) ) {
|
|
|
case '&': Qstring("&", f);
|
|
|
break;
|
|
|
- case '<': Qstring("<", f);
|
|
|
+ case '<': c = peek(f,1);
|
|
|
+ if ( (c == EOF) || isspace(c) )
|
|
|
+ Qstring("<", f);
|
|
|
+ else {
|
|
|
+ /* Markdown.pl does not escape <[nonwhite]
|
|
|
+ * sequences */
|
|
|
+ Qchar('\\', f);
|
|
|
+ shift(f, -1);
|
|
|
+ }
|
|
|
+
|
|
|
break;
|
|
|
case '^': if ( f->flags & (MKD_STRICT|MKD_NOSUPERSCRIPT) ) {
|
|
|
Qchar('\\', f);
|
|
|
@@ -1337,17 +1419,24 @@ text(MMIOT *f)
|
|
|
}
|
|
|
Qchar(c, f);
|
|
|
break;
|
|
|
-
|
|
|
- case '>': case '#': case '.': case '-':
|
|
|
- case '+': case '{': case '}': case ']':
|
|
|
- case '!': case '[': case '*': case '_':
|
|
|
- case '\\':case '(': case ')':
|
|
|
- case '`': Qchar(c, f);
|
|
|
+
|
|
|
+ case EOF: Qchar('\\', f);
|
|
|
break;
|
|
|
- default:
|
|
|
- Qchar('\\', f);
|
|
|
- if ( c != EOF )
|
|
|
- shift(f,-1);
|
|
|
+
|
|
|
+#if WITH_LATEX
|
|
|
+ case '[':
|
|
|
+ case '(': if ( mathhandler(f, '\\', (c =='(')?')':']') )
|
|
|
+ break;
|
|
|
+ /* else fall through to default */
|
|
|
+#endif
|
|
|
+
|
|
|
+ default: if ( escaped(f,c) ||
|
|
|
+ strchr(">#.-+{}]![*_\\()`", c) )
|
|
|
+ Qchar(c, f);
|
|
|
+ else {
|
|
|
+ Qchar('\\', f);
|
|
|
+ shift(f, -1);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
@@ -1366,6 +1455,16 @@ text(MMIOT *f)
|
|
|
Qchar(c, f);
|
|
|
break;
|
|
|
|
|
|
+#if WITH_LATEX
|
|
|
+ case '$': if ( peek(f, 1) == '$' ) {
|
|
|
+ pull(f);
|
|
|
+ if ( mathhandler(f, '$', '$') )
|
|
|
+ break;
|
|
|
+ Qchar('$', f);
|
|
|
+ }
|
|
|
+ /* fall through to default */
|
|
|
+#endif
|
|
|
+
|
|
|
default: Qchar(c, f);
|
|
|
break;
|
|
|
}
|
|
|
@@ -1380,26 +1479,26 @@ text(MMIOT *f)
|
|
|
static void
|
|
|
printheader(Paragraph *pp, MMIOT *f)
|
|
|
{
|
|
|
-#if WITH_ID_ANCHOR
|
|
|
- Qprintf(f, "<h%d", pp->hnumber);
|
|
|
- if ( f->flags & MKD_TOC ) {
|
|
|
- Qstring(" id=\"", f);
|
|
|
- mkd_string_to_anchor(T(pp->text->text),
|
|
|
- S(pp->text->text),
|
|
|
- (mkd_sta_function_t)Qchar, f, 1);
|
|
|
- Qchar('"', f);
|
|
|
- }
|
|
|
- Qchar('>', f);
|
|
|
-#else
|
|
|
- if ( f->flags & MKD_TOC ) {
|
|
|
- Qstring("<a name=\"", f);
|
|
|
- mkd_string_to_anchor(T(pp->text->text),
|
|
|
- S(pp->text->text),
|
|
|
- (mkd_sta_function_t)Qchar, f, 1);
|
|
|
- Qstring("\"></a>\n", f);
|
|
|
+ if ( f->flags & MKD_IDANCHOR ) {
|
|
|
+ Qprintf(f, "<h%d", pp->hnumber);
|
|
|
+ if ( f->flags & MKD_TOC ) {
|
|
|
+ Qstring(" id=\"", f);
|
|
|
+ mkd_string_to_anchor(T(pp->text->text),
|
|
|
+ S(pp->text->text),
|
|
|
+ (mkd_sta_function_t)Qchar, f, 1, f->flags);
|
|
|
+ Qchar('"', f);
|
|
|
+ }
|
|
|
+ Qchar('>', f);
|
|
|
+ } else {
|
|
|
+ if ( f->flags & MKD_TOC ) {
|
|
|
+ Qstring("<a name=\"", f);
|
|
|
+ mkd_string_to_anchor(T(pp->text->text),
|
|
|
+ S(pp->text->text),
|
|
|
+ (mkd_sta_function_t)Qchar, f, 1, f->flags);
|
|
|
+ Qstring("\"></a>\n", f);
|
|
|
+ }
|
|
|
+ Qprintf(f, "<h%d>", pp->hnumber);
|
|
|
}
|
|
|
- Qprintf(f, "<h%d>", pp->hnumber);
|
|
|
-#endif
|
|
|
push(T(pp->text->text), S(pp->text->text), f);
|
|
|
text(f);
|
|
|
Qprintf(f, "</h%d>", pp->hnumber);
|
|
|
@@ -1408,8 +1507,9 @@ printheader(Paragraph *pp, MMIOT *f)
|
|
|
|
|
|
enum e_alignments { a_NONE, a_CENTER, a_LEFT, a_RIGHT };
|
|
|
|
|
|
-static char* alignments[] = { "", " align=\"center\"", " align=\"left\"",
|
|
|
- " align=\"right\"" };
|
|
|
+static char* alignments[] = { "", " style=\"text-align:center;\"",
|
|
|
+ " style=\"text-align:left;\"",
|
|
|
+ " style=\"text-align:right;\"" };
|
|
|
|
|
|
typedef STRING(int) Istring;
|
|
|
|
|
|
@@ -1440,7 +1540,7 @@ splat(Line *p, char *block, Istring align, int force, MMIOT *f)
|
|
|
Qprintf(f, "<%s%s>",
|
|
|
block,
|
|
|
alignments[ (colno < S(align)) ? T(align)[colno] : a_NONE ]);
|
|
|
- ___mkd_reparse(T(p->text)+first, idx-first, 0, f);
|
|
|
+ ___mkd_reparse(T(p->text)+first, idx-first, 0, f, "|");
|
|
|
Qprintf(f, "</%s>\n", block);
|
|
|
idx++;
|
|
|
colno++;
|
|
|
@@ -1546,13 +1646,14 @@ printblock(Paragraph *pp, MMIOT *f)
|
|
|
&& T(t->text)[S(t->text)-2] == ' '
|
|
|
&& T(t->text)[S(t->text)-1] == ' ' ) {
|
|
|
push(T(t->text), S(t->text)-2, f);
|
|
|
- push("\003\n", 2, f);
|
|
|
+ pushc(MKD_EOLN, f);
|
|
|
+ pushc('\n', f);
|
|
|
}
|
|
|
else {
|
|
|
___mkd_tidy(&t->text);
|
|
|
push(T(t->text), S(t->text), f);
|
|
|
if ( t->next )
|
|
|
- push("\n", 1, f);
|
|
|
+ pushc('\n', f);
|
|
|
}
|
|
|
}
|
|
|
t = t->next;
|
|
|
@@ -1565,11 +1666,17 @@ printblock(Paragraph *pp, MMIOT *f)
|
|
|
|
|
|
|
|
|
static void
|
|
|
-printcode(Line *t, MMIOT *f)
|
|
|
+printcode(Line *t, char *lang, MMIOT *f)
|
|
|
{
|
|
|
int blanks;
|
|
|
|
|
|
- Qstring("<pre><code>", f);
|
|
|
+ Qstring("<pre><code", f);
|
|
|
+ if (lang) {
|
|
|
+ Qstring(" class=\"", f);
|
|
|
+ Qstring(lang, f);
|
|
|
+ Qstring("\"", f);
|
|
|
+ }
|
|
|
+ Qstring(">", f);
|
|
|
for ( blanks = 0; t ; t = t->next ) {
|
|
|
if ( S(t->text) > t->dle ) {
|
|
|
while ( blanks ) {
|
|
|
@@ -1633,7 +1740,7 @@ definitionlist(Paragraph *p, MMIOT *f)
|
|
|
for ( ; p ; p = p->next) {
|
|
|
for ( tag = p->text; tag; tag = tag->next ) {
|
|
|
Qstring("<dt>", f);
|
|
|
- ___mkd_reparse(T(tag->text), S(tag->text), 0, f);
|
|
|
+ ___mkd_reparse(T(tag->text), S(tag->text), 0, f, 0);
|
|
|
Qstring("</dt>\n", f);
|
|
|
}
|
|
|
|
|
|
@@ -1682,7 +1789,7 @@ display(Paragraph *p, MMIOT *f)
|
|
|
break;
|
|
|
|
|
|
case CODE:
|
|
|
- printcode(p->text, f);
|
|
|
+ printcode(p->text, p->lang, f);
|
|
|
break;
|
|
|
|
|
|
case QUOTE:
|
|
|
@@ -1731,14 +1838,14 @@ mkd_extra_footnotes(MMIOT *m)
|
|
|
int j, i;
|
|
|
Footnote *t;
|
|
|
|
|
|
- if ( m->reference == 0 )
|
|
|
+ if ( m->footnotes->reference == 0 )
|
|
|
return;
|
|
|
|
|
|
Csprintf(&m->out, "\n<div class=\"footnotes\">\n<hr/>\n<ol>\n");
|
|
|
-
|
|
|
- for ( i=1; i <= m->reference; i++ ) {
|
|
|
- for ( j=0; j < S(*m->footnotes); j++ ) {
|
|
|
- t = &T(*m->footnotes)[j];
|
|
|
+
|
|
|
+ for ( i=1; i <= m->footnotes->reference; i++ ) {
|
|
|
+ for ( j=0; j < S(m->footnotes->note); j++ ) {
|
|
|
+ t = &T(m->footnotes->note)[j];
|
|
|
if ( (t->refnumber == i) && (t->flags & REFERENCED) ) {
|
|
|
Csprintf(&m->out, "<li id=\"%s:%d\">\n<p>",
|
|
|
p_or_nothing(m), t->refnumber);
|
|
|
@@ -1767,15 +1874,20 @@ mkd_document(Document *p, char **res)
|
|
|
if ( p->ctx->flags & MKD_EXTRA_FOOTNOTE )
|
|
|
mkd_extra_footnotes(p->ctx);
|
|
|
p->html = 1;
|
|
|
+ size = S(p->ctx->out);
|
|
|
+
|
|
|
+ if ( (size == 0) || T(p->ctx->out)[size-1] ) {
|
|
|
+ /* Add a null byte at the end of the generated html,
|
|
|
+ * but pretend it doesn't exist.
|
|
|
+ */
|
|
|
+ EXPAND(p->ctx->out) = 0;
|
|
|
+ --S(p->ctx->out);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- size = S(p->ctx->out);
|
|
|
-
|
|
|
- if ( (size == 0) || T(p->ctx->out)[size-1] )
|
|
|
- EXPAND(p->ctx->out) = 0;
|
|
|
-
|
|
|
+
|
|
|
*res = T(p->ctx->out);
|
|
|
- return size;
|
|
|
+ return S(p->ctx->out);
|
|
|
}
|
|
|
return EOF;
|
|
|
}
|
|
|
+
|