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
where it is via contributions, critiques, and bug reports from a
host of other people, some of which are listed before. If your
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.
......
......@@ -31,9 +31,11 @@ install: $(PGMS) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR)
install.everything: install install.samples install.man
install.samples: $(SAMPLE_PGMS) install $(DESTDIR)$(BINDIR)
@INSTALL_PROGRAM@ $(SAMPLE_PGMS) $(DESTDIR)$(BINDIR)
@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_DIR@ $(DESTDIR)$(MANDIR)/man3
......@@ -115,7 +117,7 @@ clean:
rm -f $(MKDLIB) `./librarian.sh files $(MKDLIB) VERSION`
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
amalloc.o: amalloc.c
......
......@@ -5,7 +5,7 @@ language as described in
and passes the Markdown test suite at
<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
as you wish with it as long as you don't attempt to claim it as
your own work.
......
......@@ -13,6 +13,7 @@ ac_help='--enable-amalloc Enable memory allocation debugging
--with-id-anchor Use id= anchors for table-of-contents links
--with-github-tags Allow `_` and `-` in <> tags
--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
--shared Build shared libraries (default is static)'
......@@ -36,6 +37,9 @@ locals() {
;;
--ENABLE-*) enable=`echo $K | sed -e 's/--ENABLE-//' | tr '-' '_'`
echo WITH_${enable}=T ;;
--DEBIAN-GLITCH)
echo DEBIAN_GLITCH=T
;;
esac
}
......@@ -57,6 +61,8 @@ esac
test "$WITH_FENCED_CODE" && AC_DEFINE "WITH_FENCED_CODE" 1
test "$WITH_ID_ANCHOR" && AC_DEFINE 'WITH_ID_ANCHOR' 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
......
......@@ -22,7 +22,7 @@
* of html has been generated.
*
* 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
* when someone attempts to feed it junk.
*
......
......@@ -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
......@@ -207,7 +217,7 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f, char *esc)
sub.esc = f->esc;
push(bfr, size, &sub);
EXPAND(sub.in) = 0;
pushc(0, &sub);
S(sub.in)--;
text(&sub);
......@@ -262,7 +272,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);
......@@ -618,7 +628,7 @@ extra_linky(MMIOT *f, Cstring text, Footnote *ref)
___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);
......@@ -731,7 +741,8 @@ linkylinky(int image, MMIOT *f)
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) ) {
if ( extra_footnote )
status = extra_linky(f,name,ref);
......@@ -774,8 +785,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
}
}
......@@ -837,7 +852,7 @@ 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);
......@@ -1044,13 +1059,14 @@ 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 ( isspace(c) || strchr("'\"()[]{}<>`", c) || c == MKD_EOLN )
break;
}
if ( (size > 1) && process_possible_link(f, size) ) {
shift(f, size);
......@@ -1243,7 +1259,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) )
......@@ -1567,13 +1584,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;
......@@ -1758,14 +1776,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);
......
......@@ -60,6 +60,7 @@ complain(char *fmt, ...)
}
int
main(int argc, char **argv)
{
int opt;
......
......@@ -42,4 +42,4 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr mkd-extensions 7 .
.Sh AUTHOR
.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.
.Xr mkd-extensions 7 .
.Sh AUTHOR
.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)
}
#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); \
} else { t; }
#else
# define UNLESS_FENCED(t) t;
#endif
/*
* 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)
strtoul(T(t->text)+t->dle, &q, 10);
if ( (q > T(t->text)+t->dle) && (q == T(t->text) + (j-1)) ) {
j = nextnonblank(t,j);
/* *clip = j; */
*clip = (j > 4) ? 4 : j;
*clip = j;
*list_type = OL;
return AL;
}
......@@ -847,6 +851,12 @@ listitem(Paragraph *p, int indent, DWORD flags, linefn check)
UNCHECK(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 ) {
___mkd_freeLineRange(t,q);
return 0;
......@@ -998,7 +1008,7 @@ addfootnote(Line *p, MMIOT* f)
int c;
Line *np = p->next;
Footnote *foot = &EXPAND(*f->footnotes);
Footnote *foot = &EXPAND(f->footnotes->note);
CREATE(foot->tag);
CREATE(foot->link);
......@@ -1013,6 +1023,7 @@ addfootnote(Line *p, MMIOT* f)
j = nextnonblank(p, j+2);
if ( (f->flags & MKD_EXTRA_FOOTNOTE) && (T(foot->tag)[0] == '^') ) {
/* need to consume all lines until non-indented block? */
while ( j < S(p->text) )
EXPAND(foot->title) = T(p->text)[j++];
goto skip_to_end;
......@@ -1320,13 +1331,14 @@ mkd_compile(Document *doc, DWORD flags)
doc->ctx->flags = flags & USER_FLAGS;
CREATE(doc->ctx->in);
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();
doc->code = compile_document(T(doc->content), doc->ctx);
qsort(T(*doc->ctx->footnotes), S(*doc->ctx->footnotes),
sizeof T(*doc->ctx->footnotes)[0],
qsort(T(doc->ctx->footnotes->note), S(doc->ctx->footnotes->note),
sizeof T(doc->ctx->footnotes->note)[0],
(stfu)__mkd_footsort);
memset(&doc->content, 0, sizeof doc->content);
return 1;
......
......@@ -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
* do the backend processing of a markdown document
*/
......@@ -96,10 +102,9 @@ typedef struct mmiot {
Cstring in;
Qblock Q;
int isp;
int reference;
struct escaped *esc;
char *ref_prefix;
STRING(Footnote) *footnotes;
struct footnote_list *footnotes;
DWORD flags;
#define MKD_NOLINKS 0x00000001
#define MKD_NOIMAGE 0x00000002
......@@ -132,6 +137,9 @@ typedef struct mmiot {
} MMIOT;
#define MKD_EOLN 3
/*
* the mkdio text input functions return a document structure,
* which contains a header (retrieved from the document if
......
......@@ -49,4 +49,4 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr mkd-extensions 7 .
.Sh AUTHOR
.An David Parsons
.Pq Li orc@pell.chi.il.us
.Pq Li orc@pell.portland.or.us
......@@ -159,7 +159,7 @@ char **argv;
" <meta name=\"GENERATOR\" content=\"mkd2html %s\">\n", markdown_version);
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++ )
fprintf(output, " <link rel=\"stylesheet\"\n"
......
......@@ -215,6 +215,9 @@ void
mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
void *out, int labelformat)
{
#if WITH_URLENCODED_ANCHOR
static const unsigned char hexchars[] = "0123456789abcdef";
#endif
unsigned char c;
int i, size;
......@@ -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);
#if !WITH_URLENCODED_ANCHOR
if ( labelformat && (size>0) && !isalpha(line[0]) )
(*outchar)('L',out);
#endif
for ( i=0; i < size ; i++ ) {
c = line[i];
if ( labelformat ) {
if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) )
(*outchar)(c, out);
else
#if WITH_URLENCODED_ANCHOR
{
(*outchar)('%', out);
(*outchar)(hexchars[c >> 4 & 0xf], out);
(*outchar)(hexchars[c & 0xf], out);
}
#else
(*outchar)('.', out);
#endif
}
else
(*outchar)(c,out);
......
......@@ -76,9 +76,9 @@ ___mkd_freefootnotes(MMIOT *f)
int i;
if ( f->footnotes ) {
for (i=0; i < S(*f->footnotes); i++)
___mkd_freefootnote( &T(*f->footnotes)[i] );
DELETE(*f->footnotes);
for (i=0; i < S(f->footnotes->note); i++)
___mkd_freefootnote( &T(f->footnotes->note)[i] );
DELETE(f->footnotes->note);
free(f->footnotes);
}
}
......@@ -98,7 +98,7 @@ ___mkd_initmmiot(MMIOT *f, void *footnotes)
f->footnotes = footnotes;
else {
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;`' \
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' \
'~~~
code!
......
......@@ -13,5 +13,11 @@ try 'masses of non-block html' \
<br>
<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
exit $rc
......@@ -31,5 +31,90 @@ try -ffootnote -Cfoot 'footnotes (-ffootnote -Cfoot)' "$FOOTIE" \
try -fnofootnote 'footnotes (-fnofootnote)' "$FOOTIE" \
'<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
exit $rc
......@@ -61,9 +61,9 @@ try 'nested lists (2)' \
<li><p>A (list)</p>
<ol>
<li> Sub (list)</li>
<li> Two (items)</li>
<li> Here</li>
<li>Sub (list)</li>
<li>Two (items)</li>
<li>Here</li>
</ol>
......@@ -151,5 +151,46 @@ try 'non-dl followed by dl' \
<dd>hi!</dd>
</dl>'
try 'long enumerated list tag' \
'10000. This is an item
and this is another paragraph in the same
item.
2. and this is another item.
' \
'<ol>
<li><p>This is an item</p>
<p>and this is another paragraph in the same
item.</p></li>
<li><p>and this is another item.</p></li>
</ol>'
try 'long enumerated list tag' \
'10000. This is an item
and this is another paragraph in the same
item.
200000. A longer number in an embedded list.
200001. Another longer and bigger number in an embedded list.
2. and this is another item.
' \
'<ol>
<li><p>This is an item</p>
<p>and this is another paragraph in the same
item.</p>
<ol>
<li>A longer number in an embedded list.</li>
<li>Another longer and bigger number in an embedded list.</li>
</ol>
</li>
<li><p>and this is another item.</p></li>
</ol>'
summary $0
exit $rc
......@@ -157,4 +157,4 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr mkd-extensions 7 .
.Sh AUTHOR
.An David Parsons
.Pq Li orc@pell.chi.il.us
.Pq Li orc@pell.portland.or.us
......@@ -592,7 +592,7 @@ char **argv;
strcat(q, ".html");
}
}
if ( output ) {
if ( output && strcmp(output, "-") ) {
if ( force )
unlink(output);
if ( !freopen(output, "w", stdout) )
......
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