Commit 9a4e0454 authored by Alessandro Ghedini's avatar Alessandro Ghedini

Imported Upstream version 2.2.0

parent 94c62a50
......@@ -30,7 +30,6 @@ Configure.sh has a few options that can be set:
--enable-pandoc-header Use pandoc-style header blocks
--enable-superscript A^B expands to A<sup>B</sup>
--enable-amalloc Use a debugging memory allocator (to detect leaks)
--relaxed-emphasis Don't treat _ in the middle of a word as emphasis
--with-tabstops=N Set tabstops to N characters (default is 4)
3) Installing sample programs and manpages
......
% Discount on Plan 9
% Josh Wood
% 2009-06-12
# *Discount* Markdown compiler on Plan 9
## Build
% CONFIG='--enable-all-features' mk config
% mk install
% markdown -V
markdown: discount X.Y.Z DL_TAG HEADER DEBUG SUPERSCRIPT RELAXED DIV
`--enable-all-features` may be replaced by zero or more of:
--enable-dl-tag Use the DL tag extension
--enable-pandoc-header Use pandoc-style header blocks
--enable-superscript A^B becomes A<sup>B</sup>
--enable-amalloc Enable memory allocation debugging
--relaxed-emphasis underscores aren't special in the middle of words
--with-tabstops=N Set tabstops to N characters (default is 4)
--enable-div Enable >%id% divisions
--enable-alpha-list Enable (a)/(b)/(c) lists
--enable-all-features Turn on all stable optional features
## Notes
The supplied mkfile merely drives Discount's own configure script and
then APE's *psh* environment to build the Discount source, then copies
the result(s) to locations appropriate for system-wide use on Plan 9.
There are a few other *mk*(1) targets:
`install.libs`: Discount includes a C library and header.
Installation is optional. Plan 9 binaries are statically linked.
`install.man`: Add manual pages for markdown(1) and (6).
`install.progs`: Extra programs. *makepage* writes complete XHTML
documents, rather than fragments. *mkd2html* is similar, but produces
HTML.
# *Discount* Markdown compiler on Plan 9
## Build
% CONFIG='--with-tabstops=7' mk config
% mk test
% mk install
% markdown -V
markdown: discount X.Y.Z TAB=7
### Configuration
To select features and extensions, `--with-tabstops=7` may be replaced by zero or more of:
* `--enable-pandoc-header`: Use pandoc-style header blocks
* `--enable-superscript`: `A^B` becomes A<sup>B</sup>
* `--enable-amalloc`: Enable memory allocation debugging
* `--with-tabstops=`*N*: Set tabstops to *N* characters (default 4)
* `--enable-alpha-list`: Enable `(a)/(b)/(c)` list markers
* `--enable-all-features`: Turn on all stable optional features
## Notes
1. This is not a port from POSIX to native Plan 9 APIs. The supplied
`mkfile` merely drives Discount's own `configure.sh` through Plan 9's
*APE* environment (in *pcc*(1)) to build the Discount source, then
copies the result to locations appropriate for system-wide use on
Plan 9.
2. There are a few other *mk*(1) targets:
* `install.libs`: Discount includes a C library and header.
Installation is optional. Plan 9 binaries are statically linked.
* `install.man`: Add manual pages for *markdown* in sections 1, 2, and 6.
* `install.progs`: Extra programs. *makepage* writes complete XHTML
documents, rather than fragments. *mkd2html* is similar, but produces
HTML.
......@@ -122,7 +122,7 @@ tags from the output.
Suppress Smartypants-style replacement of quotes, dashes, or ellipses.
.TP
.B MKD_STRICT
Disable superscript and relaxed emphasis processing if configured; otherwise a no-op.
Disable superscript and relaxed emphasis processing.
.TP
.B MKD_TAGTEXT
Process as inside an
......
......@@ -520,9 +520,7 @@ cell in the column.
A colon at both ends of a column's header dashes indicates center alignment.
.TP
Relaxed Emphasis
If configured with
.BR --relaxed-emphasis ,
the rules for emphasis are changed so that a single
The rules for emphasis are changed so that a single
.B _
will not count as an emphasis character in the middle of a word.
This is useful for documenting some code where
......
......@@ -2,7 +2,7 @@ BIN=/$objtype/bin
CC='cc -D_BSD_EXTENSION -D_C99_SNPRINTF_EXTENSION'
markdown:
ape/psh -c 'cd .. && make'
ape/psh -c 'cd .. && $CC mktags.c -o mktags && ./mktags > blocktags && make'
none:V: markdown
......
......@@ -8,7 +8,7 @@
#define MAGIC 0x1f2e3d4c
struct alist { int magic, size; struct alist *next, *last; };
struct alist { int magic, size, index; int *end; struct alist *next, *last; };
static struct alist list = { 0, 0, 0, 0 };
......@@ -16,14 +16,32 @@ static int mallocs=0;
static int reallocs=0;
static int frees=0;
static int index = 0;
static void
die(char *msg, int index)
{
fprintf(stderr, msg, index);
abort();
}
void *
acalloc(int size, int count)
acalloc(int count, int size)
{
struct alist *ret = calloc(size + sizeof(struct alist), count);
struct alist *ret;
if ( size > 1 ) {
count *= size;
size = 1;
}
if ( ret ) {
if ( ret = calloc(count + sizeof(struct alist) + sizeof(int), size) ) {
ret->magic = MAGIC;
ret->size = size * count;
ret->index = index ++;
ret->end = (int*)(count + (char*) (ret + 1));
*(ret->end) = ~MAGIC;
if ( list.next ) {
ret->next = list.next;
ret->last = &list;
......@@ -54,6 +72,8 @@ afree(void *ptr)
struct alist *p2 = ((struct alist*)ptr)-1;
if ( p2->magic == MAGIC ) {
if ( ! (p2->end && *(p2->end) == ~MAGIC) )
die("goddam: corrupted memory block %d in free()!\n", p2->index);
p2->last->next = p2->next;
p2->next->last = p2->last;
++frees;
......@@ -71,12 +91,16 @@ arealloc(void *ptr, int size)
struct alist save;
if ( p2->magic == MAGIC ) {
if ( ! (p2->end && *(p2->end) == ~MAGIC) )
die("goddam: corrupted memory block %d in realloc()!\n", p2->index);
save.next = p2->next;
save.last = p2->last;
p2 = realloc(p2, sizeof(*p2) + size);
p2 = realloc(p2, sizeof(int) + sizeof(*p2) + size);
if ( p2 ) {
p2->size = size;
p2->end = (int*)(size + (char*) (p2 + 1));
*(p2->end) = ~MAGIC;
p2->next->last = p2;
p2->last->next = p2;
++reallocs;
......
......@@ -169,7 +169,7 @@ AC_CHECK_HEADERS () {
for hdr in $*; do
echo "#include <$hdr>" >> ngc$$.c
done
echo "main() { }" >> ngc$$.c
echo "int main() { }" >> ngc$$.c
LOGN "looking for header $hdr"
......@@ -210,7 +210,7 @@ AC_CHECK_FUNCS () {
fi
cat >> ngc$$.c << EOF
main()
int main()
{
$F;
......@@ -251,7 +251,7 @@ AC_CHECK_STRUCT () {
done
cat >> ngc$$.c << EOF
main()
int main()
{
struct $struct foo;
}
......@@ -286,7 +286,7 @@ AC_CHECK_TYPE () {
done
cat >> ngc$$.c << EOF
main()
int main()
{
$type foo;
}
......@@ -323,7 +323,7 @@ AC_CHECK_FIELD () {
done
cat >> ngc$$.c << EOF
main()
int main()
{
struct $struct foo;
......@@ -352,7 +352,7 @@ AC_PROG_CC () {
cat > ngc$$.c << \EOF
#include <stdio.h>
main()
int main()
{
puts("hello, sailor");
}
......@@ -360,7 +360,7 @@ EOF
TLOGN "checking the C compiler"
unset AC_CFLAGS AC_LDFLAGS
unset AC_CFLAGS AC_LDFLAGS __MACOS_DSYM
if [ "$CC" ] ; then
AC_CC="$CC"
......@@ -381,10 +381,8 @@ EOF
fi
echo "checking out the C compiler"
unset __MACOS_DSYM
$AC_CC -o ngc$$ ngc$$.c
status=$?
test -d ngc$$.dSYM && __MACOS_DSYM=1
TLOGN " ($AC_CC)"
......@@ -427,6 +425,12 @@ EOF
else
AC_LDFLAGS=${CFLAGS:-"-g"}
fi
# macos-specific(?) test for .dSYM resource directories
$AC_CC $AC_CFLAGS $AC_LDFLAGS -o ngc$$ ngc$$.c
ls -dl ngc$$*
test -d ngc$$.dSYM && __MACOS_DSYM=1
else
AC_FAIL " does not compile code properly"
fi
......@@ -509,7 +513,7 @@ AC_INIT () {
__config_files="config.cmd config.sub config.h config.mak config.log"
rm -f $__config_files
__cwd=`pwd`
exec 5>&1 1>$__cwd/config.log 2>&1
exec 5>&1 1>"$__cwd"/config.log 2>&1
AC_CONFIGURE_FOR=__AC_`echo $1 | sed -e 's/\..$//' | $AC_UPPERCASE | tr ' ' '_'`_D
# check to see whether to use echo -n or echo ...\c
......@@ -532,7 +536,7 @@ AC_INIT () {
LOG "Configuring for [$1]"
cat > $__cwd/config.h << EOF
cat > "$__cwd"/config.h << EOF
/*
* configuration for $1${2:+" ($2)"}, generated `date`
* by ${LOGNAME:-`whoami`}@`hostname`
......@@ -875,7 +879,7 @@ AC_SCALAR_TYPES () {
if AC_QUIET AC_CHECK_HEADERS WinDef.h; then
# windows machine; BYTE, WORD, DWORD already
# defined
echo "#include <WinDef.h>" >> $__cwd/config.h
echo "#include <WinDef.h>" >> "$__cwd"/config.h
TLOG " (defined in WinDef.h)"
return 0
fi
......@@ -923,17 +927,17 @@ EOF
if $AC_CC ngc$$.c -o ngc$$; then
while [ "$1" ]; do
case "$1" in
sub)if ./ngc$$ sub >> $__cwd/config.sub; then
sub)if ./ngc$$ sub >> "$__cwd"/config.sub; then
rc=0
fi;;
*) if ./ngc$$ >> $__cwd/config.h; then
*) if ./ngc$$ >> "$__cwd"/config.h; then
rc=0
fi ;;
esac
shift
done
if [ "$rc" != 0 ]; then
if ./ngc$$ >> $__cwd/config.h; then
if ./ngc$$ >> "$__cwd"/config.h; then
rc=1
fi
fi
......@@ -951,10 +955,18 @@ EOF
# AC_OUTPUT generates makefiles from makefile.in's
#
AC_OUTPUT () {
cd $__cwd
cd "$__cwd"
AC_SUB 'LIBS' "$AC_LIBS"
AC_SUB 'CONFIGURE_FILES' "$__config_files"
AC_SUB 'GENERATED_FILES' "$*"
if test "$__MACOS_DSYM"; then
# deal with extra OSX droppings, if they exist
AC_SUB 'GENERATED_FILES' "-r *.dSYM $*"
else
AC_SUB 'GENERATED_FILES' "$*"
fi
AC_SUB 'CC' "$AC_CC"
AC_SUB 'CFLAGS' "$AC_CFLAGS"
AC_SUB 'LDFLAGS' "$AC_LDFLAGS"
......@@ -981,7 +993,7 @@ AC_OUTPUT () {
AC_PROG ar
AC_PROG ranlib
AC_SUB LD_LIBRARY_PATH HERE
AC
__config_files="$__config_files librarian.sh"
cat > librarian.sh << EOF
#! /bin/sh
......@@ -1024,10 +1036,10 @@ EOF
__d=$AC_SRCDIR
for makefile in $*;do
if test -r $__d/${makefile}.in; then
if test -r "$__d/${makefile}.in"; then
LOG "generating $makefile"
./config.md `__ac_dirname ./$makefile` 2>/dev/null
$AC_SED_PROG -f config.sub < $__d/${makefile}.in > $makefile
$AC_SED_PROG -f config.sub < "$__d/${makefile}.in" > $makefile
__config_files="$__config_files $makefile"
else
LOG "WARNING: ${makefile}.in does not exist!"
......@@ -1054,7 +1066,7 @@ AC_CHECK_FLOCK() {
#include <sys/types.h>
#include <fcntl.h>
main()
int main()
{
int x = open("$$.c", O_RDWR, 0666);
int y = open("$$.c", O_RDWR, 0666);
......@@ -1107,7 +1119,7 @@ AC_CHECK_RESOLVER () {
#include <arpa/nameser.h>
#include <resolv.h>
main()
int main()
{
char bfr[256];
......@@ -1119,14 +1131,15 @@ EOF
if $AC_CC -o ngc$$ ngc$$.c; then
TLOG " (found)"
elif $AC_CC -o ngc$$ ngc$$.c -lresolv; then
TLOG " (found, needs -lresolv)"
TLOG " (yes, needs -lresolv)"
AC_LIBS="$AC_LIBS -lresolv"
elif $AC_CC -DBIND_8_COMPAT -o ngc$$ ngc$$.c; then
TLOG " (found, needs BIND_8_COMPAT)"
TLOG " (fyes, needs BIND_8_COMPAT)"
AC_DEFINE BIND_8_COMPAT 1
elif $AC_CC -DBIND_8_COMPAT -o ngc$$ ngc$$.c -lresolv; then
TLOG " (found, needs BIND_8_COMPAT & -lresolv)"
TLOG " (yes, needs BIND_8_COMPAT & -lresolv)"
AC_DEFINE BIND_8_COMPAT 1
AC_LIBS="$AC_LIBS -lresolv"
else
TLOG " (not found)"
__ACR_rc=1
......@@ -1150,7 +1163,7 @@ AC_CHECK_ALLOCA () {
#else
# include <stdlib.h>
#endif
main()
int main()
{
alloca(10);
}
......@@ -1186,11 +1199,14 @@ AC_CHECK_BASENAME() {
extern char *basename(char*);
main()
int main()
{
char *a = basename("/a/test");
char *b = basename("/a/nother");
if ( a == 0 || b == 0 || a == b )
return 0;
return (strcmp(a,b) != 0) ? 0 : 1;
}
......@@ -1315,7 +1331,9 @@ 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"
EOF
test "$LDCONFIG" && echo ' '$LDCONFIG '"$1"' >> librarian.sh
cat >> librarian.sh << EOF
;;
esac
EOF
......@@ -1422,15 +1440,15 @@ AC_PROG_INSTALL () {
fi
__config_files="$__config_files config.md"
AC_SUB 'INSTALL_DIR' "$__cwd/config.md"
echo "#! /bin/sh" > $__cwd/config.md
echo "# script generated" `date` "by configure.sh" >> $__cwd/config.md
echo >> $__cwd/config.md
AC_SUB 'INSTALL_DIR' "./config.md"
echo "#! /bin/sh" > ""$__cwd"/config.md"
echo "# script generated" `date` "by configure.sh" >> ""$__cwd"/config.md"
echo >> ""$__cwd"/config.md"
if [ "$__mkdir" ]; then
echo "test -d \"\$1\" || $__mkdir \"\$1\"" >> $__cwd/config.md
echo "exit $?" >> $__cwd/config.md
echo "test -d \"\$1\" || $__mkdir \"\$1\"" >> ""$__cwd"/config.md"
echo "exit $?" >> ""$__cwd"/config.md"
else
cat - >> $__cwd/config.md << \EOD
cat - >> ""$__cwd"/config.md" << \EOD
pieces=`IFS=/; for x in $1; do echo $x; done`
dir=
for x in $pieces; do
......@@ -1441,7 +1459,7 @@ done
exit 0
EOD
fi
chmod +x $__cwd/config.md
chmod +x "$__cwd"/config.md
}
#
......@@ -1513,26 +1531,28 @@ AC_FAIL() {
#
# AC_SUB writes a substitution into config.sub
AC_SUB() {
( _subst=`echo $2 | sed -e 's/;/\\;/g'`
echo "s;@$1@;$_subst;g" ) >> $__cwd/config.sub
( _target="$1"
shift
_subst=`echo "$*" | sed -e 's/;/\\;/g'`
echo "s;@$_target@;$_subst;g" ) >> "$__cwd"/config.sub
}
#
# AC_MAK writes a define into config.mak
AC_MAK() {
echo "HAVE_$1 = 1" >> $__cwd/config.mak
echo "HAVE_$1 = 1" >> "$__cwd"/config.mak
}
#
# AC_DEFINE adds a #define to config.h
AC_DEFINE() {
echo "#define $1 ${2:-1}" >> $__cwd/config.h
echo "#define $1 ${2:-1}" >> "$__cwd"/config.h
}
#
# AC_INCLUDE adds a #include to config.h
AC_INCLUDE() {
echo "#include \"$1\"" >> $__cwd/config.h
echo "#include \"$1\"" >> "$__cwd"/config.h
}
#
......
......@@ -9,11 +9,7 @@
#
ac_help='--enable-amalloc Enable memory allocation debugging
--with-tabstops=N Set tabstops to N characters (default is 4)
--with-dl=X Use Discount, Extra, or Both types of definition list
--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
--with-latex Enable latex passthrough
--enable-all-features Turn on all stable optional features
--shared Build shared libraries (default is static)'
......@@ -48,20 +44,24 @@ TARGET=markdown
AC_INIT $TARGET
__DL=`echo "$WITH_DL" | $AC_UPPERCASE`
for banned_with in dl fenced-code id-anchor github-tags urlencoded-anchor; do
banned_with_variable_ref=\$WITH_`echo "$banned_with" | $AC_UPPERCASE | tr - _`
if [ "`eval echo "$banned_with_variable_ref"`" ]; then
LOG "Setting theme default --with-$banned_with."
fi
done
case "$__DL" in
EXTRA) AC_DEFINE 'USE_EXTRA_DL' 1 ;;
DISCOUNT|1|"") AC_DEFINE 'USE_DISCOUNT_DL' 1 ;;
BOTH) AC_DEFINE 'USE_EXTRA_DL' 1
AC_DEFINE 'USE_DISCOUNT_DL' 1 ;;
*) AC_FAIL "Unknown value <$WITH_DL> for --with-dl (want 'discount', 'extra', or 'both')" ;;
# theme wants the old behavior of --with-(foo)
#
case "`echo "$WITH_DL" | $AC_UPPERCASE`" in
EXTRA) THEME_CF="MKD_DLEXTRA|MKD_NODLDISCOUNT";;
BOTH) THEME_CF="MKD_DLEXTRA";;
esac
test "$WITH_FENCED_CODE" && THEME_CF="${THEME_CF:+$THEME_CF|}MKD_FENCEDCODE"
AC_DEFINE THEME_CF "$THEME_CF"
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
......@@ -92,6 +92,7 @@ AC_C_CONST
AC_C_INLINE
AC_SCALAR_TYPES sub hdr
AC_CHECK_BASENAME
AC_CHECK_ALLOCA
AC_CHECK_HEADERS sys/types.h pwd.h && AC_CHECK_FUNCS getpwuid
......@@ -162,5 +163,6 @@ fi
[ "$OS_FREEBSD" -o "$OS_DRAGONFLY" ] || AC_CHECK_HEADERS malloc.h
[ "$WITH_PANDOC_HEADER" ] && AC_DEFINE 'PANDOC_HEADER' '1'
[ "$WITH_LATEX" ] && AC_DEFINE 'WITH_LATEX' '1'
AC_OUTPUT Makefile version.c mkdio.h
......@@ -75,11 +75,13 @@ int
mkd_generatecss(Document *d, FILE *f)
{
char *res;
int written = EOF, size = mkd_css(d, &res);
int written;
int size = mkd_css(d, &res);
if ( size > 0 )
written = fwrite(res, 1, size, f);
written = (size > 0) ? fwrite(res,1,size,f) : 0;
if ( res )
free(res);
return (written == size) ? size : EOF;
}
......@@ -145,7 +145,6 @@ mkd_dump(Document *doc, FILE *out, int flags, char *title)
dumptree(doc->code, &stack, out);
DELETE(stack);
mkd_cleanup(doc);
return 0;
}
return -1;
......
......@@ -30,6 +30,12 @@ static struct flagnames flagnames[] = {
{ MKD_NODLIST, "!DLIST" },
{ MKD_EXTRA_FOOTNOTE, "FOOTNOTE" },
{ MKD_NOSTYLE, "!STYLE" },
{ MKD_NODLDISCOUNT, "!DLDISCOUNT" },
{ MKD_DLEXTRA, "DLEXTRA" },
{ MKD_FENCEDCODE, "FENCEDCODE" },
{ MKD_IDANCHOR, "IDANCHOR" },
{ MKD_GITHUBTAGS, "GITHUBTAGS" },
{ MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" },
};
#define NR(x) (sizeof x/sizeof x[0])
......
......@@ -786,7 +786,7 @@ mangle(char *s, int len, MMIOT *f)
{
while ( len-- > 0 ) {
#if DEBIAN_GLITCH
Qprintf(f, "&#02d;", *((unsigned char*)(s++)) );
Qprintf(f, "&#%02d;", *((unsigned char*)(s++)) );
#else
Qstring("&#", f);
Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
......@@ -860,7 +860,6 @@ code(MMIOT *f, char *s, int length)
cputc(c, f);
} /* code */
/* delspan() -- write out a chunk of text, blocking with <del>...</del>
*/
static void
......@@ -1009,11 +1008,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;
}
......@@ -1064,6 +1061,8 @@ maybe_autolink(MMIOT *f)
if ( peek(f, size+2) != EOF )
++size;
}
else if ( c & 0x80 ) /* HACK: ignore utf-8 extended characters */
continue;
else if ( isspace(c) || strchr("'\"()[]{}<>`", c) || c == MKD_EOLN )
break;
}
......@@ -1208,6 +1207,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.
......@@ -1283,6 +1305,7 @@ text(MMIOT *f)
else
Qchar(c, f);
break;
case '[': if ( tag_text(f) || !linkylinky(0, f) )
Qchar(c, f);
break;
......@@ -1386,7 +1409,14 @@ text(MMIOT *f)
case EOF: Qchar('\\', f);
break;
#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);
......@@ -1412,6 +1442,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;
}
......@@ -1426,26 +1466,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);
......@@ -1812,15 +1852,19 @@ mkd_document(Document *p, char **res)