Commit 94c62a50 authored by Alessandro Ghedini's avatar Alessandro Ghedini

Imported Upstream version 2.1.8

parent 03d27c82
...@@ -2,7 +2,7 @@ Discount is primarily my work, but it has only reached the point ...@@ -2,7 +2,7 @@ Discount is primarily my work, but it has only reached the point
where it is via contributions, critiques, and bug reports from a where it is via contributions, critiques, and bug reports from a
host of other people, some of which are listed before. If your host of other people, some of which are listed before. If your
name isn't on this list, please remind me name isn't on this list, please remind me
-david parsons (orc@pell.chi.il.us) -david parsons (orc@pell.portland.or.us)
Josh Wood -- Plan9 support. Josh Wood -- Plan9 support.
......
...@@ -31,9 +31,11 @@ install: $(PGMS) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR) ...@@ -31,9 +31,11 @@ install: $(PGMS) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR)
install.everything: install install.samples install.man install.everything: install install.samples install.man
install.samples: $(SAMPLE_PGMS) install $(DESTDIR)$(BINDIR) install.samples: $(SAMPLE_PGMS) install $(DESTDIR)$(BINDIR)
@INSTALL_PROGRAM@ $(SAMPLE_PGMS) $(DESTDIR)$(BINDIR)
@INSTALL_DIR@ $(DESTDIR)$(MANDIR)/man1 @INSTALL_DIR@ $(DESTDIR)$(MANDIR)/man1
@INSTALL_DATA@ theme.1 makepage.1 mkd2html.1 $(DESTDIR)$(MANDIR)/man1 for x in $(SAMPLE_PGMS); do \
@INSTALL_PROGRAM@ $$x $(DESTDIR)$(BINDIR)/$(SAMPLE_PFX)$$x; \
@INSTALL_DATA@ $$x.1 $(DESTDIR)$(MANDIR)/man1/$(SAMPLE_PFX)$$x.1; \
done
install.man: install.man:
@INSTALL_DIR@ $(DESTDIR)$(MANDIR)/man3 @INSTALL_DIR@ $(DESTDIR)$(MANDIR)/man3
...@@ -115,7 +117,7 @@ clean: ...@@ -115,7 +117,7 @@ clean:
rm -f $(MKDLIB) `./librarian.sh files $(MKDLIB) VERSION` rm -f $(MKDLIB) `./librarian.sh files $(MKDLIB) VERSION`
distclean spotless: clean distclean spotless: clean
rm -f @GENERATED_FILES@ @CONFIGURE_FILES@ rm -f @GENERATED_FILES@ @CONFIGURE_FILES@ ./mktags ./blocktags ./librarian.sh
Csio.o: Csio.c cstring.h amalloc.h config.h markdown.h Csio.o: Csio.c cstring.h amalloc.h config.h markdown.h
amalloc.o: amalloc.c amalloc.o: amalloc.c
......
...@@ -5,7 +5,7 @@ language as described in ...@@ -5,7 +5,7 @@ language as described in
and passes the Markdown test suite at and passes the Markdown test suite at
<http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip> <http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip>
DISCOUNT is free software written by David Parsons <orc@pell.chi.il.us>; DISCOUNT is free software written by David Parsons <orc@pell.portland.or.us>;
it is released under a BSD-style license that allows you to do it is released under a BSD-style license that allows you to do
as you wish with it as long as you don't attempt to claim it as as you wish with it as long as you don't attempt to claim it as
your own work. your own work.
......
...@@ -13,6 +13,7 @@ ac_help='--enable-amalloc Enable memory allocation debugging ...@@ -13,6 +13,7 @@ ac_help='--enable-amalloc Enable memory allocation debugging
--with-id-anchor Use id= anchors for table-of-contents links --with-id-anchor Use id= anchors for table-of-contents links
--with-github-tags Allow `_` and `-` in <> tags --with-github-tags Allow `_` and `-` in <> tags
--with-fenced-code Allow fenced code blocks --with-fenced-code Allow fenced code blocks
--with-urlencoded-anchor Use url-encoded chars to multibyte chars in toc links
--enable-all-features Turn on all stable optional features --enable-all-features Turn on all stable optional features
--shared Build shared libraries (default is static)' --shared Build shared libraries (default is static)'
...@@ -36,6 +37,9 @@ locals() { ...@@ -36,6 +37,9 @@ locals() {
;; ;;
--ENABLE-*) enable=`echo $K | sed -e 's/--ENABLE-//' | tr '-' '_'` --ENABLE-*) enable=`echo $K | sed -e 's/--ENABLE-//' | tr '-' '_'`
echo WITH_${enable}=T ;; echo WITH_${enable}=T ;;
--DEBIAN-GLITCH)
echo DEBIAN_GLITCH=T
;;
esac esac
} }
...@@ -57,6 +61,8 @@ esac ...@@ -57,6 +61,8 @@ esac
test "$WITH_FENCED_CODE" && AC_DEFINE "WITH_FENCED_CODE" 1 test "$WITH_FENCED_CODE" && AC_DEFINE "WITH_FENCED_CODE" 1
test "$WITH_ID_ANCHOR" && AC_DEFINE 'WITH_ID_ANCHOR' 1 test "$WITH_ID_ANCHOR" && AC_DEFINE 'WITH_ID_ANCHOR' 1
test "$WITH_GITHUB_TAGS" && AC_DEFINE 'WITH_GITHUB_TAGS' 1 test "$WITH_GITHUB_TAGS" && AC_DEFINE 'WITH_GITHUB_TAGS' 1
test "$WITH_URLENCODED_ANCHOR" && AC_DEFINE 'WITH_URLENCODED_ANCHOR' 1
test "$DEBIAN_GLITCH" && AC_DEFINE 'DEBIAN_GLITCH' 1
AC_PROG_CC AC_PROG_CC
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* of html has been generated. * of html has been generated.
* *
* It should create MarkdownTest_1.0 (and _1.0.3) * It should create MarkdownTest_1.0 (and _1.0.3)
* compatable emphasis for non-pathological cases * compatible emphasis for non-pathological cases
* and it should fail in a standards-compliant way * and it should fail in a standards-compliant way
* when someone attempts to feed it junk. * when someone attempts to feed it junk.
* *
......
...@@ -38,6 +38,16 @@ push(char *bfr, int size, MMIOT *f) ...@@ -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. /* look <i> characters ahead of the cursor.
*/ */
static inline int static inline int
...@@ -207,7 +217,7 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f, char *esc) ...@@ -207,7 +217,7 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f, char *esc)
sub.esc = f->esc; sub.esc = f->esc;
push(bfr, size, &sub); push(bfr, size, &sub);
EXPAND(sub.in) = 0; pushc(0, &sub);
S(sub.in)--; S(sub.in)--;
text(&sub); text(&sub);
...@@ -262,7 +272,7 @@ puturl(char *s, int size, MMIOT *f, int display) ...@@ -262,7 +272,7 @@ puturl(char *s, int size, MMIOT *f, int display)
Qstring("%22", f); Qstring("%22", f);
else if ( isalnum(c) || ispunct(c) || (display && isspace(c)) ) else if ( isalnum(c) || ispunct(c) || (display && isspace(c)) )
Qchar(c, f); Qchar(c, f);
else if ( c == 003 ) /* untokenize ^C */ else if ( c == MKD_EOLN ) /* untokenize hard return */
Qstring(" ", f); Qstring(" ", f);
else else
Qprintf(f, "%%%02X", c); Qprintf(f, "%%%02X", c);
...@@ -618,7 +628,7 @@ extra_linky(MMIOT *f, Cstring text, Footnote *ref) ...@@ -618,7 +628,7 @@ extra_linky(MMIOT *f, Cstring text, Footnote *ref)
___mkd_reparse(T(text), S(text), linkt.flags, f, 0); ___mkd_reparse(T(text), S(text), linkt.flags, f, 0);
else { else {
ref->flags |= REFERENCED; 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>", 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,
p_or_nothing(f), ref->refnumber, ref->refnumber); p_or_nothing(f), ref->refnumber, ref->refnumber);
...@@ -731,7 +741,8 @@ linkylinky(int image, MMIOT *f) ...@@ -731,7 +741,8 @@ linkylinky(int image, MMIOT *f)
S(key.tag) = S(name); S(key.tag) = S(name);
} }
if ( ref = bsearch(&key, T(*f->footnotes), S(*f->footnotes), if ( ref = bsearch(&key, T(f->footnotes->note),
S(f->footnotes->note),
sizeof key, (stfu)__mkd_footsort) ) { sizeof key, (stfu)__mkd_footsort) ) {
if ( extra_footnote ) if ( extra_footnote )
status = extra_linky(f,name,ref); status = extra_linky(f,name,ref);
...@@ -774,8 +785,12 @@ static void ...@@ -774,8 +785,12 @@ static void
mangle(char *s, int len, MMIOT *f) mangle(char *s, int len, MMIOT *f)
{ {
while ( len-- > 0 ) { while ( len-- > 0 ) {
#if DEBIAN_GLITCH
Qprintf(f, "&#02d;", *((unsigned char*)(s++)) );
#else
Qstring("&#", f); Qstring("&#", f);
Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) ); Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
#endif
} }
} }
...@@ -837,7 +852,7 @@ code(MMIOT *f, char *s, int length) ...@@ -837,7 +852,7 @@ code(MMIOT *f, char *s, int length)
int i,c; int i,c;
for ( i=0; i < length; i++ ) 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); Qstring(" ", f);
else if ( c == '\\' && (i < length-1) && escaped(f, s[i+1]) ) else if ( c == '\\' && (i < length-1) && escaped(f, s[i+1]) )
cputc(s[++i], f); cputc(s[++i], f);
...@@ -1044,13 +1059,14 @@ maybe_autolink(MMIOT *f) ...@@ -1044,13 +1059,14 @@ maybe_autolink(MMIOT *f)
/* greedily scan forward for the end of a legitimate link. /* 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 ( c == '\\' ) {
if ( peek(f, size+2) != EOF ) if ( peek(f, size+2) != EOF )
++size; ++size;
} }
else if ( isspace(c) || strchr("'\"()[]{}<>`", c) ) else if ( isspace(c) || strchr("'\"()[]{}<>`", c) || c == MKD_EOLN )
break; break;
}
if ( (size > 1) && process_possible_link(f, size) ) { if ( (size > 1) && process_possible_link(f, size) ) {
shift(f, size); shift(f, size);
...@@ -1243,7 +1259,8 @@ text(MMIOT *f) ...@@ -1243,7 +1259,8 @@ text(MMIOT *f)
switch (c) { switch (c) {
case 0: break; case 0: break;
case 3: Qstring(tag_text(f) ? " " : "<br/>", f); case MKD_EOLN:
Qstring(tag_text(f) ? " " : "<br/>", f);
break; break;
case '>': if ( tag_text(f) ) case '>': if ( tag_text(f) )
...@@ -1567,13 +1584,14 @@ printblock(Paragraph *pp, MMIOT *f) ...@@ -1567,13 +1584,14 @@ printblock(Paragraph *pp, MMIOT *f)
&& T(t->text)[S(t->text)-2] == ' ' && T(t->text)[S(t->text)-2] == ' '
&& T(t->text)[S(t->text)-1] == ' ' ) { && T(t->text)[S(t->text)-1] == ' ' ) {
push(T(t->text), S(t->text)-2, f); push(T(t->text), S(t->text)-2, f);
push("\003\n", 2, f); pushc(MKD_EOLN, f);
pushc('\n', f);
} }
else { else {
___mkd_tidy(&t->text); ___mkd_tidy(&t->text);
push(T(t->text), S(t->text), f); push(T(t->text), S(t->text), f);
if ( t->next ) if ( t->next )
push("\n", 1, f); pushc('\n', f);
} }
} }
t = t->next; t = t->next;
...@@ -1758,14 +1776,14 @@ mkd_extra_footnotes(MMIOT *m) ...@@ -1758,14 +1776,14 @@ mkd_extra_footnotes(MMIOT *m)
int j, i; int j, i;
Footnote *t; Footnote *t;
if ( m->reference == 0 ) if ( m->footnotes->reference == 0 )
return; return;
Csprintf(&m->out, "\n<div class=\"footnotes\">\n<hr/>\n<ol>\n"); Csprintf(&m->out, "\n<div class=\"footnotes\">\n<hr/>\n<ol>\n");
for ( i=1; i <= m->reference; i++ ) { for ( i=1; i <= m->footnotes->reference; i++ ) {
for ( j=0; j < S(*m->footnotes); j++ ) { for ( j=0; j < S(m->footnotes->note); j++ ) {
t = &T(*m->footnotes)[j]; t = &T(m->footnotes->note)[j];
if ( (t->refnumber == i) && (t->flags & REFERENCED) ) { if ( (t->refnumber == i) && (t->flags & REFERENCED) ) {
Csprintf(&m->out, "<li id=\"%s:%d\">\n<p>", Csprintf(&m->out, "<li id=\"%s:%d\">\n<p>",
p_or_nothing(m), t->refnumber); p_or_nothing(m), t->refnumber);
......
...@@ -60,6 +60,7 @@ complain(char *fmt, ...) ...@@ -60,6 +60,7 @@ complain(char *fmt, ...)
} }
int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int opt; int opt;
......
...@@ -42,4 +42,4 @@ utility exits 0 on success, and >0 if an error occurs. ...@@ -42,4 +42,4 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr mkd-extensions 7 . .Xr mkd-extensions 7 .
.Sh AUTHOR .Sh AUTHOR
.An David Parsons .An David Parsons
.Pq Li orc@pell.chi.il.us .Pq Li orc@pell.portland.or.us
...@@ -176,4 +176,4 @@ utility exits 0 on success, and >0 if an error occurs. ...@@ -176,4 +176,4 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr mkd-extensions 7 . .Xr mkd-extensions 7 .
.Sh AUTHOR .Sh AUTHOR
.An David Parsons .An David Parsons
.Pq Li orc@pell.chi.il.us .Pq Li orc@pell.portland.or.us
...@@ -177,9 +177,14 @@ splitline(Line *t, int cutpoint) ...@@ -177,9 +177,14 @@ splitline(Line *t, int cutpoint)
} }
#define UNCHECK(l) ((l)->flags &= ~CHECKED) #define UNCHECK(l) ((l)->flags &= ~CHECKED)
#define UNLESS_FENCED(t) if (fenced) { \
#ifdef WITH_FENCED_CODE
# define UNLESS_FENCED(t) if (fenced) { \
other = 1; l->count += (c == ' ' ? 0 : -1); \ other = 1; l->count += (c == ' ' ? 0 : -1); \
} else { t; } } else { t; }
#else
# define UNLESS_FENCED(t) t;
#endif
/* /*
* walk a line, seeing if it's any of half a dozen interesting regular * walk a line, seeing if it's any of half a dozen interesting regular
...@@ -530,8 +535,7 @@ islist(Line *t, int *clip, DWORD flags, int *list_type) ...@@ -530,8 +535,7 @@ islist(Line *t, int *clip, DWORD flags, int *list_type)
strtoul(T(t->text)+t->dle, &q, 10); strtoul(T(t->text)+t->dle, &q, 10);
if ( (q > T(t->text)+t->dle) && (q == T(t->text) + (j-1)) ) { if ( (q > T(t->text)+t->dle) && (q == T(t->text) + (j-1)) ) {
j = nextnonblank(t,j); j = nextnonblank(t,j);
/* *clip = j; */ *clip = j;
*clip = (j > 4) ? 4 : j;
*list_type = OL; *list_type = OL;
return AL; return AL;
} }
...@@ -847,6 +851,12 @@ listitem(Paragraph *p, int indent, DWORD flags, linefn check) ...@@ -847,6 +851,12 @@ listitem(Paragraph *p, int indent, DWORD flags, linefn check)
UNCHECK(t); UNCHECK(t);
t->dle = mkd_firstnonblank(t); t->dle = mkd_firstnonblank(t);
/* even though we had to trim a long leader off this item,
* the indent for trailing paragraphs is still 4...
*/
if (indent > 4) {
indent = 4;
}
if ( (q = skipempty(t->next)) == 0 ) { if ( (q = skipempty(t->next)) == 0 ) {
___mkd_freeLineRange(t,q); ___mkd_freeLineRange(t,q);
return 0; return 0;
...@@ -998,7 +1008,7 @@ addfootnote(Line *p, MMIOT* f) ...@@ -998,7 +1008,7 @@ addfootnote(Line *p, MMIOT* f)
int c; int c;
Line *np = p->next; Line *np = p->next;
Footnote *foot = &EXPAND(*f->footnotes); Footnote *foot = &EXPAND(f->footnotes->note);
CREATE(foot->tag); CREATE(foot->tag);
CREATE(foot->link); CREATE(foot->link);
...@@ -1013,6 +1023,7 @@ addfootnote(Line *p, MMIOT* f) ...@@ -1013,6 +1023,7 @@ addfootnote(Line *p, MMIOT* f)
j = nextnonblank(p, j+2); j = nextnonblank(p, j+2);
if ( (f->flags & MKD_EXTRA_FOOTNOTE) && (T(foot->tag)[0] == '^') ) { if ( (f->flags & MKD_EXTRA_FOOTNOTE) && (T(foot->tag)[0] == '^') ) {
/* need to consume all lines until non-indented block? */
while ( j < S(p->text) ) while ( j < S(p->text) )
EXPAND(foot->title) = T(p->text)[j++]; EXPAND(foot->title) = T(p->text)[j++];
goto skip_to_end; goto skip_to_end;
...@@ -1320,13 +1331,14 @@ mkd_compile(Document *doc, DWORD flags) ...@@ -1320,13 +1331,14 @@ mkd_compile(Document *doc, DWORD flags)
doc->ctx->flags = flags & USER_FLAGS; doc->ctx->flags = flags & USER_FLAGS;
CREATE(doc->ctx->in); CREATE(doc->ctx->in);
doc->ctx->footnotes = malloc(sizeof doc->ctx->footnotes[0]); doc->ctx->footnotes = malloc(sizeof doc->ctx->footnotes[0]);
CREATE(*doc->ctx->footnotes); doc->ctx->footnotes->reference = 0;
CREATE(doc->ctx->footnotes->note);
mkd_initialize(); mkd_initialize();
doc->code = compile_document(T(doc->content), doc->ctx); doc->code = compile_document(T(doc->content), doc->ctx);
qsort(T(*doc->ctx->footnotes), S(*doc->ctx->footnotes), qsort(T(doc->ctx->footnotes->note), S(doc->ctx->footnotes->note),
sizeof T(*doc->ctx->footnotes)[0], sizeof T(doc->ctx->footnotes->note)[0],
(stfu)__mkd_footsort); (stfu)__mkd_footsort);
memset(&doc->content, 0, sizeof doc->content); memset(&doc->content, 0, sizeof doc->content);
return 1; return 1;
......
...@@ -88,6 +88,12 @@ struct escaped { ...@@ -88,6 +88,12 @@ struct escaped {
} ; } ;
struct footnote_list {
int reference;
STRING(Footnote) note;
} ;
/* a magic markdown io thing holds all the data structures needed to /* a magic markdown io thing holds all the data structures needed to
* do the backend processing of a markdown document * do the backend processing of a markdown document
*/ */
...@@ -96,10 +102,9 @@ typedef struct mmiot { ...@@ -96,10 +102,9 @@ typedef struct mmiot {
Cstring in; Cstring in;
Qblock Q; Qblock Q;
int isp; int isp;
int reference;
struct escaped *esc; struct escaped *esc;
char *ref_prefix; char *ref_prefix;
STRING(Footnote) *footnotes; struct footnote_list *footnotes;
DWORD flags; DWORD flags;
#define MKD_NOLINKS 0x00000001 #define MKD_NOLINKS 0x00000001
#define MKD_NOIMAGE 0x00000002 #define MKD_NOIMAGE 0x00000002
...@@ -132,6 +137,9 @@ typedef struct mmiot { ...@@ -132,6 +137,9 @@ typedef struct mmiot {
} MMIOT; } MMIOT;
#define MKD_EOLN 3
/* /*
* the mkdio text input functions return a document structure, * the mkdio text input functions return a document structure,
* which contains a header (retrieved from the document if * which contains a header (retrieved from the document if
......
...@@ -49,4 +49,4 @@ utility exits 0 on success, and >0 if an error occurs. ...@@ -49,4 +49,4 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr mkd-extensions 7 . .Xr mkd-extensions 7 .
.Sh AUTHOR .Sh AUTHOR
.An David Parsons .An David Parsons
.Pq Li orc@pell.chi.il.us .Pq Li orc@pell.portland.or.us
...@@ -159,7 +159,7 @@ char **argv; ...@@ -159,7 +159,7 @@ char **argv;
" <meta name=\"GENERATOR\" content=\"mkd2html %s\">\n", markdown_version); " <meta name=\"GENERATOR\" content=\"mkd2html %s\">\n", markdown_version);
fprintf(output," <meta http-equiv=\"Content-Type\"\n" fprintf(output," <meta http-equiv=\"Content-Type\"\n"
" content=\"text/html; charset-us-ascii\">"); " content=\"text/html; charset=utf-8\">");
for ( i=0; i < S(css); i++ ) for ( i=0; i < S(css); i++ )
fprintf(output, " <link rel=\"stylesheet\"\n" fprintf(output, " <link rel=\"stylesheet\"\n"
......
...@@ -215,6 +215,9 @@ void ...@@ -215,6 +215,9 @@ void
mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar, mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
void *out, int labelformat) void *out, int labelformat)
{ {
#if WITH_URLENCODED_ANCHOR
static const unsigned char hexchars[] = "0123456789abcdef";
#endif
unsigned char c; unsigned char c;
int i, size; int i, size;
...@@ -222,15 +225,25 @@ mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar, ...@@ -222,15 +225,25 @@ mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
size = mkd_line(s, len, &line, IS_LABEL); size = mkd_line(s, len, &line, IS_LABEL);
#if !WITH_URLENCODED_ANCHOR
if ( labelformat && (size>0) && !isalpha(line[0]) ) if ( labelformat && (size>0) && !isalpha(line[0]) )
(*outchar)('L',out); (*outchar)('L',out);
#endif
for ( i=0; i < size ; i++ ) { for ( i=0; i < size ; i++ ) {
c = line[i]; c = line[i];
if ( labelformat ) { if ( labelformat ) {
if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) ) if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) )
(*outchar)(c, out); (*outchar)(c, out);
else else
#if WITH_URLENCODED_ANCHOR
{
(*outchar)('%', out);
(*outchar)(hexchars[c >> 4 & 0xf], out);
(*outchar)(hexchars[c & 0xf], out);
}
#else
(*outchar)('.', out); (*outchar)('.', out);
#endif
} }
else else
(*outchar)(c,out); (*outchar)(c,out);
......
...@@ -76,9 +76,9 @@ ___mkd_freefootnotes(MMIOT *f) ...@@ -76,9 +76,9 @@ ___mkd_freefootnotes(MMIOT *f)
int i; int i;
if ( f->footnotes ) { if ( f->footnotes ) {
for (i=0; i < S(*f->footnotes); i++) for (i=0; i < S(f->footnotes->note); i++)
___mkd_freefootnote( &T(*f->footnotes)[i] ); ___mkd_freefootnote( &T(f->footnotes->note)[i] );
DELETE(*f->footnotes); DELETE(f->footnotes->note);
free(f->footnotes); free(f->footnotes);
} }
} }
...@@ -98,7 +98,7 @@ ___mkd_initmmiot(MMIOT *f, void *footnotes) ...@@ -98,7 +98,7 @@ ___mkd_initmmiot(MMIOT *f, void *footnotes)
f->footnotes = footnotes; f->footnotes = footnotes;
else { else {
f->footnotes = malloc(sizeof f->footnotes[0]); f->footnotes = malloc(sizeof f->footnotes[0]);
CREATE(*f->footnotes); CREATE(f->footnotes->note);
} }
} }
} }
......
...@@ -33,6 +33,17 @@ try 'backslashes in code(2)' '`printf "%s: \n", $1;`' \ ...@@ -33,6 +33,17 @@ try 'backslashes in code(2)' '`printf "%s: \n", $1;`' \
if ./markdown -V | grep FENCED-CODE >/dev/null; then if ./markdown -V | grep FENCED-CODE >/dev/null; then
try 'fenced code block with blank lines' \
'~~~
code!
still code!
~~~' \
'<pre><code>code!
still code!
</code></pre>'
try 'fenced code block' \ try 'fenced code block' \
'~~~ '~~~
code! code!
......
...@@ -13,5 +13,11 @@ try 'masses of non-block html' \ ...@@ -13,5 +13,11 @@ try 'masses of non-block html' \
<br> <br>
<span>bar</span><br></p>' <span>bar</span><br></p>'
try -fautolink -G 'autolink + github-flavoured markdown' \
'http://foo
bar' \
'<p><a href="http://foo">http://foo</a><br/>
bar</p>'
summary $0 summary $0
exit $rc exit $rc
...@@ -31,5 +31,90 @@ try -ffootnote -Cfoot 'footnotes (-ffootnote -Cfoot)' "$FOOTIE" \ ...@@ -31,5 +31,90 @@ try -ffootnote -Cfoot 'footnotes (-ffootnote -Cfoot)' "$FOOTIE" \
try -fnofootnote 'footnotes (-fnofootnote)' "$FOOTIE" \ try -fnofootnote 'footnotes (-fnofootnote)' "$FOOTIE" \
'<p>I haz a footnote<a href="yes?">^1</a></p>' '<p>I haz a footnote<a href="yes?">^1</a></p>'
TSRC='Alpha[^AlphaF].
Column 1 | Column 2
---------------------------------|--------------------------
Beta[^BetaF] | cell
[^AlphaF]: Alpha Footnote
[^BetaF]: Beta Footnote'
TOUT='<p>Alpha<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>.</p>
<table>
<thead>
<tr>
<th>Column 1 </th>
<th> Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Beta<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> </td>
<td> cell</td>
</tr>
</tbody>
</table>
<div class="footnotes">
<hr/>
<ol>
<li id="fn:1">
<p>Alpha Footnote<a href="#fnref:1" rev="footnote">&#8617;</a></p></li>
<li id="fn:2">
<p>Beta Footnote<a href="#fnref:2" rev="footnote">&#8617;</a></p></li>
</ol>
</div>'
try -ffootnote 'footnotes inside table elements' "$TSRC" "$TOUT"
TSRC='[Test test[^test]](class:test)
<span class="test">
Test2[^testtwo]
</span>
Test3[^testthree]
<span class="test">
Test4[^testfour]
</span>
[^test]: Test footnote
[^testtwo]: Test2 footnote
[^testthree]: Test3 footnote
[^testfour]: Test4 footnote'
TOUT='<p><span class="test">Test test<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></span></p>
<p><span class="test">
Test2<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup>
</span></p>
<p>Test3<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup></p>
<p><span class="test">
Test4<sup id="fnref:4"><a href="#fn:4" rel="footnote">4</a></sup>
</span></p>
<div class="footnotes">
<hr/>
<ol>
<li id="fn:1">
<p>Test footnote<a href="#fnref:1" rev="footnote">&#8617;</a></p></li>
<li id="fn:2">
<p>Test2 footnote<a href="#fnref:2" rev="footnote">&#8617;</a></p></li>
<li id="fn:3">
<p>Test3 footnote<a href="#fnref:3" rev="footnote">&#8617;</a></p></li>
<li id="fn:4">
<p>Test4 footnote<a href="#fnref:4" rev="footnote">&#8617;</a></p></li>
</ol>
</div>'
try -ffootnote 'footnotes inside spans' "$TSRC" "$TOUT"
summary $0 summary $0
exit $rc exit $rc