Commit a891dc03 authored by Alessandro Ghedini's avatar Alessandro Ghedini

Imported Upstream version 2.1.5

parent 24edcbbe
......@@ -54,7 +54,7 @@ Csreparse(Cstring *iot, char *buf, int size, int flags)
{
MMIOT f;
___mkd_initmmiot(&f, 0);
___mkd_reparse(buf, size, 0, &f);
___mkd_reparse(buf, size, 0, &f, 0);
___mkd_emblock(&f);
SUFFIX(*iot, T(f.out), S(f.out));
___mkd_freemmiot(&f, 0);
......
CC=@CC@ -I. -L.
CC=@CC@ -I.
LFLAGS=-L.
CFLAGS=@CFLAGS@
AR=@AR@
RANLIB=@RANLIB@
......@@ -15,7 +16,7 @@ MKDLIB=libmarkdown
OBJS=mkdio.o markdown.o dumptree.o generate.o \
resource.o docheader.o version.o toc.o css.o \
xml.o Csio.o xmlpage.o basename.o emmatch.o \
setup.o tags.o html5.o flags.o @AMALLOC@
github_flavoured.o setup.o tags.o html5.o flags.o @AMALLOC@
TESTFRAMEWORK=echo cols
MAN3PAGES=mkd-callbacks.3 mkd-functions.3 markdown.3 mkd-line.3
......@@ -75,17 +76,17 @@ blocktags: mktags
# example programs
@THEME@theme: theme.o $(MKDLIB) mkdio.h
@THEME@ $(CC) -o theme theme.o -lmarkdown @LIBS@
@THEME@ $(CC) $(LFLAGS) -o theme theme.o pgm_options.o -lmarkdown @LIBS@
mkd2html: mkd2html.o $(MKDLIB) mkdio.h
$(CC) -o mkd2html mkd2html.o -lmarkdown @LIBS@
$(CC) $(LFLAGS) -o mkd2html mkd2html.o -lmarkdown @LIBS@
markdown: main.o pgm_options.o $(MKDLIB)
$(CC) $(CFLAGS) -o markdown main.o pgm_options.o -lmarkdown @LIBS@
$(CC) $(LFLAGS) -o markdown main.o pgm_options.o -lmarkdown @LIBS@
makepage: makepage.c pgm_options.o $(MKDLIB) mkdio.h
$(CC) $(CFLAGS) -o makepage makepage.c pgm_options.o -lmarkdown @LIBS@
$(CC) $(LFLAGS) -o makepage makepage.c pgm_options.o -lmarkdown @LIBS@
pgm_options.o: pgm_options.c mkdio.h config.h
$(CC) -I. -c pgm_options.c
......
......@@ -387,9 +387,11 @@ EOF
if [ $status -eq 0 ]; then
if $AC_CC -x c /dev/null -dM -E 2>&1 | grep '__clang__' >/dev/null; then
TLOG " yuck, you're using clang"
IS_CLANG=T
IS_BROKEN_CC=T
elif $AC_CC -v 2>&1 | grep 'gcc version' >/dev/null; then
TLOG " oh ick, it looks like gcc"
IS_GCC=T
IS_BROKEN_CC=T
else
TLOG " ok"
......@@ -425,8 +427,6 @@ EOF
AC_FAIL " does not compile code properly"
fi
AC_SUB 'CC' "$AC_CC"
__remove ngc$$ ngc$$.c ngc$$.o
return $status
......@@ -940,6 +940,7 @@ AC_OUTPUT () {
AC_SUB 'LIBS' "$AC_LIBS"
AC_SUB 'CONFIGURE_FILES' "$__config_files"
AC_SUB 'GENERATED_FILES' "$*"
AC_SUB 'CC' "$AC_CC"
AC_SUB 'CFLAGS' "$AC_CFLAGS"
AC_SUB 'LDFLAGS' "$AC_LDFLAGS"
AC_SUB 'srcdir' "$AC_SRCDIR"
......@@ -1214,31 +1215,16 @@ AC_COMPILER_PIC () {
return $__rc
}
#
# AC_CC_SHLIBS checks if the C compiler can produce shared libraries
# and if it can writes a librarian that handles those libraries for us.
#
AC_CC_SHLIBS () {
AC_PROG_CC || AC_FAIL "Need a C compiler to build shared libraries"
AC_PROG_LN_S || AC_FAIL "Need to be able to make symbolic links for shared libraries"
AC_PROG_INSTALL || AC_FAIL "Need an install program to install shared libraries"
LOGN "checking whether the C compiler can build shared libraries "
echo "int some_variable = 0;" > ngc$$.c
if $AC_CC $AC_PICFLAG -shared -o ngc$$.so ngc$$.c; then
AC_SUB LD_LIBRARY_PATH LD_LIBRARY_PATH
# -Wl option probably works, but be paranoid anyway
_VFLAGS="$AC_PICFLAG -shared -Wl,-soname,ngc$$.so.1"
if $AC_CC $_VFLAGS -o ngc$$.so ngc$$.c; then
USE_SONAME=T
fi
LDCONFIG=`AC_PATH=/sbin:/usr/sbin:/usr/local/sbin acLookFor ldconfig`
__config_files="$__config_files librarian.sh"
cat > librarian.sh << EOF
# generate a macosX librarian
#
__AC_MACOS_LIBRARIAN() {
AC_SUB LD_LIBRARY_PATH DYLD_LIBRARY_PATH
__config_files="$__config_files librarian.sh"
cat > librarian.sh << EOF
#! /bin/sh
#
# Build ELF shared libraries, hiding (some) ickiness from the makefile
# Build MacOS shared libraries, hiding (some) ickiness from the makefile
ACTION=\$1; shift
LIBRARY=\$1; shift
......@@ -1247,41 +1233,43 @@ eval \`awk -F. '{ printf "MAJOR=%d\n", \$1;
printf "VERSION=%d.%d.%d\n", \$1, \$2, \$3; }' \$1\`
shift
LIBNAME=\$LIBRARY.so
FULLNAME=\$LIBNAME.\$VERSION
LIBNAME=\$LIBRARY.dylib
FULLNAME=\$LIBNAME
case "\$ACTION" in
make) FLAGS="$AC_CFLAGS -shared"
unset VFLAGS
test "$USE_SONAME" && VFLAGS="-Wl,-soname,\$LIBNAME.\$MAJOR"
make) FLAGS="$AC_CFLAGS -dynamiclib"
VFLAGS="-current_version \$VERSION -compatibility_version \$MAJOR"
rm -f \$LIBRARY \$LIBNAME \$LIBNAME.\$MAJOR
rm -f \$LIBRARY
if $AC_CC \$FLAGS \$VFLAGS -o \$FULLNAME "\$@"; then
$PROG_LN_S \$FULLNAME \$LIBRARY
$PROG_LN_S \$FULLNAME \$LIBNAME
$PROG_LN_S \$FULLNAME \$LIBNAME.\$MAJOR
fi
;;
files) echo "\$FULLNAME" "\$LIBNAME" "\$LIBNAME.\$MAJOR"
files) echo "\$FULLNAME"
;;
install)$PROG_INSTALL -c \$FULLNAME "\$1"
$PROG_LN_S -f \$FULLNAME \$1/\$LIBNAME.\$MAJOR
$PROG_LN_S -f \$FULLNAME \$1/\$LIBNAME
test "$LDCONFIG" && $LDCONFIG "\$1"
;;
esac
EOF
chmod +x librarian.sh
LOG "(yes; -shared)"
__rc=0
elif $AC_CC $AC_PICFLAG -dynamiclib -o ngc$$.so ngc$$.c; then
# macosx
AC_SUB LD_LIBRARY_PATH DYLD_LIBRARY_PATH
__config_files="$__config_files librarian.sh"
cat > librarian.sh << EOF
chmod +x librarian.sh
}
# Generate an ELF librarian (for Linux, freebsd)
#
__AC_ELF_LIBRARIAN() {
AC_SUB LD_LIBRARY_PATH LD_LIBRARY_PATH
# -Wl option probably works, but be paranoid anyway
_VFLAGS="$AC_PICFLAG -shared -Wl,-soname,ngc$$.so.1"
if $AC_CC $_VFLAGS -o ngc$$.so ngc$$.c; then
USE_SONAME=T
fi
LDCONFIG=`AC_PATH=/sbin:/usr/sbin:/usr/local/sbin acLookFor ldconfig`
__config_files="$__config_files librarian.sh"
cat > librarian.sh << EOF
#! /bin/sh
#
# Build MacOS shared libraries, hiding (some) ickiness from the makefile
# Build ELF shared libraries, hiding (some) ickiness from the makefile
ACTION=\$1; shift
LIBRARY=\$1; shift
......@@ -1290,26 +1278,60 @@ eval \`awk -F. '{ printf "MAJOR=%d\n", \$1;
printf "VERSION=%d.%d.%d\n", \$1, \$2, \$3; }' \$1\`
shift
LIBNAME=\$LIBRARY.dylib
FULLNAME=\$LIBNAME
LIBNAME=\$LIBRARY.so
FULLNAME=\$LIBNAME.\$VERSION
case "\$ACTION" in
make) FLAGS="$AC_CFLAGS -dynamiclib"
VFLAGS="-current_version \$VERSION -compatibility_version \$MAJOR"
make) FLAGS="$AC_CFLAGS -shared"
unset VFLAGS
test "$USE_SONAME" && VFLAGS="-Wl,-soname,\$LIBNAME.\$MAJOR"
rm -f \$LIBRARY
rm -f \$LIBRARY \$LIBNAME \$LIBNAME.\$MAJOR
if $AC_CC \$FLAGS \$VFLAGS -o \$FULLNAME "\$@"; then
$PROG_LN_S \$FULLNAME \$LIBRARY
$PROG_LN_S \$FULLNAME \$LIBNAME
$PROG_LN_S \$FULLNAME \$LIBNAME.\$MAJOR
fi
;;
files) echo "\$FULLNAME"
files) echo "\$FULLNAME" "\$LIBNAME" "\$LIBNAME.\$MAJOR"
;;
install)$PROG_INSTALL -c \$FULLNAME "\$1"
$PROG_LN_S -f \$FULLNAME \$1/\$LIBNAME.\$MAJOR
$PROG_LN_S -f \$FULLNAME \$1/\$LIBNAME
test "$LDCONFIG" && $LDCONFIG "\$1"
;;
esac
EOF
chmod +x librarian.sh
LOG "(yes; macos dylib)"
chmod +x librarian.sh
}
#
# AC_CC_SHLIBS checks if the C compiler can produce shared libraries
# and if it can writes a librarian that handles those libraries for us.
#
AC_CC_SHLIBS () {
AC_PROG_CC || AC_FAIL "Need a C compiler to build shared libraries"
AC_PROG_LN_S || AC_FAIL "Need to be able to make symbolic links for shared libraries"
AC_PROG_INSTALL || AC_FAIL "Need an install program to install shared libraries"
LOGN "checking whether the C compiler can build shared libraries "
echo "int some_variable = 0;" > ngc$$.c
if uname -a | grep Darwin >/dev/null; then
# Claims to be macos?
if $AC_CC $AC_PICFLAG -dynamiclib -o ngc$$.so ngc$$.c; then
__AC_MACOS_LIBRARIAN
LOG "(yes; macos dylib)"
__rc=0
else
LOG "(no)"
__rc=1
fi
elif $AC_CC $AC_PICFLAG -shared -o ngc$$.so ngc$$.c; then
__AC_ELF_LIBRARIAN
LOG "(yes; -shared)"
__rc=0
else
LOG "(no)"
......
......@@ -62,10 +62,21 @@ AC_PROG_CC
test "$TRY_SHARED" && AC_COMPILER_PIC && AC_CC_SHLIBS
case "$AC_CC $AC_CFLAGS" in
*-Wall*) AC_DEFINE 'while(x)' 'while( (x) != 0 )'
AC_DEFINE 'if(x)' 'if( (x) != 0 )' ;;
esac
if [ "IS_BROKEN_CC" ]; then
case "$AC_CC $AC_CFLAGS" in
*-pedantic*) ;;
*) # hack around deficiencies in gcc and clang
#
AC_DEFINE 'while(x)' 'while( (x) != 0 )'
AC_DEFINE 'if(x)' 'if( (x) != 0 )'
if [ "$IS_CLANG" ]; then
AC_CC="$AC_CC -Wno-implicit-int"
elif [ "$IS_GCC" ]; then
AC_CC="$AC_CC -Wno-return-type -Wno-implicit-int"
fi ;;
esac
fi
AC_PROG ar || AC_FAIL "$TARGET requires ar"
AC_PROG ranlib
......
......@@ -27,9 +27,9 @@
#define DELETE(x) ALLOCATED(x) ? (free(T(x)), S(x) = (x).alloc = 0) \
: ( S(x) = 0 )
#define CLIP(t,i,sz) \
( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
S(t) -= ( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
(memmove(&T(t)[i], &T(t)[i+sz], (S(t)-(i+sz)+1)*sizeof(T(t)[0])), \
S(t) -= (sz)) : -1
(sz)) : 0
#define RESERVE(x, sz) T(x) = ((x).alloc > S(x) + (sz) \
? T(x) \
......
......@@ -29,6 +29,7 @@ static struct flagnames flagnames[] = {
{ MKD_NOALPHALIST, "!ALPHALIST" },
{ MKD_NODLIST, "!DLIST" },
{ MKD_EXTRA_FOOTNOTE, "FOOTNOTE" },
{ MKD_NOSTYLE, "!STYLE" },
};
#define NR(x) (sizeof x/sizeof x[0])
......
......@@ -183,9 +183,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);
......@@ -193,6 +194,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)--;
......@@ -206,6 +215,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
*/
......@@ -553,7 +579,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);
......@@ -585,7 +611,7 @@ 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;
......@@ -604,7 +630,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) )
......@@ -624,7 +651,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));
......@@ -635,12 +662,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
......@@ -707,8 +734,6 @@ linkylinky(int image, MMIOT *f)
else
status = linkyformat(f, name, image, ref);
}
else if ( f->flags & IS_LABEL )
status = linkyformat(f, name, image, 0);
}
}
}
......@@ -810,6 +835,8 @@ code(MMIOT *f, char *s, int length)
for ( i=0; i < length; i++ )
if ( (c = s[i]) == 003) /* ^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 */
......@@ -821,7 +848,7 @@ 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);
}
......@@ -1058,7 +1085,7 @@ islike(MMIOT *f, char *s)
int len;
int i;
if ( s[0] == '<' ) {
if ( s[0] == '|' ) {
if ( !isthisnonword(f, -1) )
return 0;
++s;
......@@ -1067,7 +1094,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--;
......@@ -1086,13 +1113,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 },
......@@ -1100,11 +1127,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;", 0, 3 },
} ;
#define NRSMART ( sizeof smarties / sizeof smarties[0] )
......@@ -1146,7 +1173,7 @@ smartypants(int c, int *flags, MMIOT *f)
break;
else if ( c == '\'' && peek(f, j+1) == '\'' ) {
Qstring("&ldquo;", f);
___mkd_reparse(cursor(f)+1, j-2, 0, f);
___mkd_reparse(cursor(f)+1, j-2, 0, f, 0);
Qstring("&rdquo;", f);
shift(f,j+1);
return 1;
......@@ -1268,7 +1295,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;
......@@ -1327,16 +1354,16 @@ 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);
default: if ( escaped(f,c) ||
strchr(">#.-+{}]![*_\\()`", c) )
Qchar(c, f);
else {
Qchar('\\', f);
shift(f, -1);
}
break;
}
break;
......@@ -1429,7 +1456,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++;
......@@ -1613,7 +1640,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);
}
......
/*
* github_flavoured -- implement the obnoxious "returns are hard newlines"
* feature in github flavoured markdown.
*
* Copyright (C) 2012 David L Parsons.
* The redistribution terms are provided in the COPYRIGHT file that must
* be distributed with this source code.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "cstring.h"
#include "markdown.h"
#include "amalloc.h"
/* build a Document from any old input.
*/
typedef int (*getc_func)(void*);
Document *
gfm_populate(getc_func getc, void* ctx, int flags)
{
Cstring line;
Document *a = __mkd_new_Document();
int c;
int pandoc = 0;
if ( !a ) return 0;
a->tabstop = (flags & MKD_TABSTOP) ? 4 : TABSTOP;
CREATE(line);
while ( (c = (*getc)(ctx)) != EOF ) {
if ( c == '\n' ) {
if ( pandoc != EOF && pandoc < 3 ) {
if ( S(line) && (T(line)[0] == '%') )
pandoc++;
else
pandoc = EOF;
}
if (pandoc == EOF) {
EXPAND(line) = ' ';
EXPAND(line) = ' ';
}
__mkd_enqueue(a, &line);
S(line) = 0;
}
else if ( isprint(c) || isspace(c) || (c & 0x80) )
EXPAND(line) = c;
}
if ( S(line) )
__mkd_enqueue(a, &line);
DELETE(line);
if ( (pandoc == 3) && !(flags & (MKD_NOHEADER|MKD_STRICT)) ) {
/* the first three lines started with %, so we have a header.
* clip the first three lines out of content and hang them
* off header.
*/
Line *headers = T(a->content);
a->title = headers; __mkd_header_dle(a->title);
a->author= headers->next; __mkd_header_dle(a->author);
a->date = headers->next->next; __mkd_header_dle(a->date);
T(a->content) = headers->next->next->next;
}
return a;
}
/* convert a block of text into a linked list
*/
Document *
gfm_string(const char *buf, int len, DWORD flags)
{
struct string_stream about;
about.data = buf;
about.size = len;
return gfm_populate((getc_func)__mkd_io_strget, &about, flags & INPUT_MASK);
}
/* convert a file into a linked list
*/
Document *
gfm_in(FILE *f, DWORD flags)
{
return gfm_populate((getc_func)fgetc, f, flags & INPUT_MASK);
}
......@@ -18,6 +18,7 @@
#include "config.h"
#include "amalloc.h"
#include "pgm_options.h"
#include "tags.h"
#if HAVE_LIBGEN_H
#include <libgen.h>
......@@ -66,9 +67,12 @@ main(int argc, char **argv)
mkd_flag_t flags = 0;
int debug = 0;
int toc = 0;
int content = 1;
int version = 0;
int with_html5 = 0;
int styles = 0;
int use_mkd_line = 0;
int github_flavoured = 0;
char *extra_footnote_prefix = 0;
char *urlflags = 0;
char *text = 0;
......@@ -83,7 +87,7 @@ main(int argc, char **argv)
pgm = basename(argv[0]);
opterr = 1;
while ( (opt=getopt(argc, argv, "5b:C:df:E:F:o:s:t:TV")) != EOF ) {
while ( (opt=getopt(argc, argv, "5b:C:df:E:F:Gno:s:St:TV")) != EOF ) {
switch (opt) {
case '5': with_html5 = 1;
break;
......@@ -109,13 +113,19 @@ main(int argc, char **argv)
else if ( !set_flag(&flags, optarg) )
complain("unknown option <%s>", optarg);
break;
case 'G': github_flavoured = 1;
break;
case 'n': content = 0;
break;
case 's': text = optarg;
break;
case 'S': styles = 1;
break;
case 't': text = optarg;
use_mkd_line = 1;
break;
case 'T': toc = 1;
break;
case 's': text = optarg;
break;
case 'C': extra_footnote_prefix = optarg;
break;
case 'o': if ( ofile ) {
......@@ -154,7 +164,10 @@ main(int argc, char **argv)
rc = mkd_generateline( text, strlen(text), stdout, flags);
else {
if ( text ) {
if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
doc = github_flavoured ? gfm_string(text, strlen(text), flags)
: mkd_string(text, strlen(text), flags) ;
if ( !doc ) {
perror(text);
exit(1);
}
......@@ -164,7 +177,9 @@ main(int argc, char **argv)
perror(argv[0]);
exit(1);
}
if ( (doc = mkd_in(stdin,flags)) == 0 ) {
doc = github_flavoured ? gfm_in(stdin,flags) : mkd_in(stdin,flags);
if ( !doc ) {
perror(argc ? argv[0] : "stdin");
exit(1);
}
......@@ -184,9 +199,12 @@ main(int argc, char **argv)
rc = 1;
if ( mkd_compile(doc, flags) ) {
rc = 0;
if ( styles )
mkd_generatecss(doc, stdout);
if ( toc )
mkd_generatetoc(doc, stdout);
mkd_generatehtml(doc, stdout);
if ( content )
mkd_generatehtml(doc, stdout);
mkd_cleanup(doc);
}
}
......
......@@ -15,7 +15,9 @@
.Op Fl C Ar prefix
.Op Fl F Pa bitmap
.Op Fl f Ar flags
.Op Fl n
.Op Fl o Pa file
.Op Fl S
.Op Fl s Pa text
.Op Fl t Pa text
.Op Pa textfile
......@@ -107,6 +109,8 @@ Allow alphabetic lists.
Allow definition lists.
.It Ar footnote
Allow markdown extra-style footnotes.
.It Ar styles
Extract <style> blocks from the output.
.El
.Pp
As an example, the option
......@@ -123,6 +127,13 @@ described in
.Xr markdown 3
(the flag values are defined in
.Pa mkdio.h )
.It Fl n
Don't write generated html.
.It Fl o Pa file
Write the generated html to
.Pa file .
.It Fl S
output <style> blocks.
.It Fl V
Show the version# and compile-time configuration data.