Commit 507a626a authored by Alessandro Ghedini's avatar Alessandro Ghedini

Merge tag 'upstream/2.2.2'

Upstream version 2.2.2
parents 99551443 300042e4
......@@ -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, 0);
___mkd_reparse(buf, size, flags, &f, 0);
___mkd_emblock(&f);
SUFFIX(*iot, T(f.out), S(f.out));
___mkd_freemmiot(&f, 0);
......
......@@ -26,11 +26,12 @@ Configure.sh has a few options that can be set:
--libdir=DIR where to put libraries (prefix/lib)
--libexecdir=DIR where to put private executables
--mandir=DIR where to put manpages
--enable-dl-tag Use the DL tag extension
--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)
--with-tabstops=N Set tabstops to N characters (default is 4)
--with-amalloc Use my paranoid malloc library to catch memory leaks
--shared Build shared libraries
--debian-glitch When mangling email addresses, do them deterministically
so the Debian regression tester won't complain
--pkg-config Build & install a pkg-config(1) .pc file for
the discount library.
3) Installing sample programs and manpages
......
......@@ -8,7 +8,7 @@ BINDIR=@exedir@
MANDIR=@mandir@
LIBDIR=@libdir@
INCDIR=@prefix@/include
PKGDIR=$(LIBDIR)/pkgconfig
@MK_PKGCONFIG@PKGDIR=$(LIBDIR)/pkgconfig
PGMS=markdown
SAMPLE_PGMS=mkd2html makepage
......@@ -28,7 +28,9 @@ install: $(PGMS) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR) $(D
@INSTALL_PROGRAM@ $(PGMS) $(DESTDIR)$(BINDIR)
./librarian.sh install libmarkdown VERSION $(DESTDIR)$(LIBDIR)
@INSTALL_DATA@ mkdio.h $(DESTDIR)$(INCDIR)
@INSTALL_DATA@ $(MKDLIB).pc $(DESTDIR)$(PKGDIR)
@MK_PKGCONFIG@$(DESTDIR)$(PKGDIR)/$(MKDLIB).pc: $(MKDLIB).pc $(DESTDIR)$(PKGDIR)
@MK_PKGCONFIG@ @INSTALL_DATA@ $(MKDLIB).pc $(DESTDIR)$(PKGDIR)
install.everything: install install.samples install.man
......@@ -67,8 +69,8 @@ $(DESTDIR)$(INCDIR):
$(DESTDIR)$(LIBDIR):
@INSTALL_DIR@ $(DESTDIR)$(LIBDIR)
$(DESTDIR)$(PKGDIR): $(DESTDIR)$(LIBDIR)
@INSTALL_DIR@ $(DESTDIR)$(PKGDIR)
@MK_PKGCONFIG@$(DESTDIR)$(PKGDIR):
@MK_PKGCONFIG@ @INSTALL_DIR@ $(DESTDIR)$(PKGDIR)
version.o: version.c VERSION
$(CC) $(CFLAGS) -DVERSION=\"`cat VERSION`\" -c version.c
......
......@@ -441,6 +441,25 @@ EOF
}
#
# check for the existence of __attribute__((__noreturn__))
#
AC_CHECK_NORETURN() {
AC_PROG_CC
echo "extern int noreturn __attribute__((__noreturn__));" > ngc$$.c
TLOGN "Checking __attribute__((__noreturn__)) "
if $AC_CC -c ngc$$.c; then
TLOG "(yes)"
AC_DEFINE 'NORETURN' ' __attribute__((__noreturn__))'
else
TLOG "(no)"
AC_DEFINE 'NORETURN' ''
fi
}
#
# acLookFor actually looks for a program, without setting anything.
#
......@@ -548,11 +567,11 @@ AC_INIT () {
EOF
unset __share
if [ -d $AC_PREFIX/share/man ]; then
if [ -d "$AC_PREFIX/share/man" ]; then
for t in 1 2 3 4 5 6 7 8 9; do
if [ -d $AC_PREFIX/share/man/man$t ]; then
if [ -d "$AC_PREFIX/share/man/man$t" ]; then
__share=/share
elif [ -d $AC_PREFIX/share/man/cat$t ]; then
elif [ -d "$AC_PREFIX/share/man/cat$t" ]; then
__share=/share
fi
done
......@@ -560,7 +579,7 @@ EOF
__share=
fi
if [ -d $AC_PREFIX/libexec ]; then
if [ -d "$AC_PREFIX/libexec" ]; then
__libexec=libexec
else
__libexec=lib
......@@ -576,6 +595,7 @@ EOF
AC_CONFDIR=${AC_CONFDIR:-/etc}
AC_PATH=${WITH_PATH:-$PATH}
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
......@@ -963,6 +983,14 @@ EOF
}
#
# quote a string if it has spaces in it
#
__ac_quote() {
echo "$1" | sed -e 's/ /\\\\ /g'
}
#
# AC_OUTPUT generates makefiles from makefile.in's
#
......@@ -982,14 +1010,14 @@ AC_OUTPUT () {
AC_SUB 'CC' "$AC_CC"
AC_SUB 'CFLAGS' "$AC_CFLAGS"
AC_SUB 'LDFLAGS' "$AC_LDFLAGS"
AC_SUB 'srcdir' "$AC_SRCDIR"
AC_SUB 'prefix' "$AC_PREFIX"
AC_SUB 'exedir' "$AC_EXECDIR"
AC_SUB 'sbindir' "$AC_SBINDIR"
AC_SUB 'libdir' "$AC_LIBDIR"
AC_SUB 'libexec' "$AC_LIBEXEC"
AC_SUB 'confdir' "$AC_CONFDIR"
AC_SUB 'mandir' "$AC_MANDIR"
AC_SUB 'srcdir' `__ac_quote "$AC_SRCDIR"`
AC_SUB 'prefix' `__ac_quote "$AC_PREFIX"`
AC_SUB 'exedir' `__ac_quote "$AC_EXECDIR"`
AC_SUB 'sbindir' `__ac_quote "$AC_SBINDIR"`
AC_SUB 'libdir' `__ac_quote "$AC_LIBDIR"`
AC_SUB 'libexec' `__ac_quote "$AC_LIBEXEC"`
AC_SUB 'confdir' `__ac_quote "$AC_CONFDIR"`
AC_SUB 'mandir' `__ac_quote "$AC_MANDIR"`
if echo "$__config_files" | grep -v librarian.sh >/dev/null; then
# write a librarian that works with static libraries
......@@ -1017,14 +1045,14 @@ LIBRARY=\$1; shift
VERSION=\$1; shift
case "\$ACTION" in
make) ${PROG_AR} crv \$LIBRARY.a "\$@"
${PROG_RANLIB} \$LIBRARY.a
rm -f \$LIBRARY
${__dolink} \$LIBRARY.a \$LIBRARY
make) ${PROG_AR} crv "\$LIBRARY.a" "\$@"
${PROG_RANLIB} "\$LIBRARY.a"
rm -f "\$LIBRARY"
${__dolink} "\$LIBRARY.a" "\$LIBRARY"
;;
files) echo "\${LIBRARY}.a"
;;
install)$PROG_INSTALL -m 644 \${LIBRARY}.a \$1
install)$PROG_INSTALL -m 644 "\${LIBRARY}.a" "\$1"
;;
esac
EOF
......@@ -1278,21 +1306,21 @@ 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.dylib"
FULLNAME="\$LIBNAME"
case "\$ACTION" in
make) FLAGS="$AC_CFLAGS -dynamiclib"
VFLAGS="-current_version \$VERSION -compatibility_version \$MAJOR"
rm -f \$LIBRARY
if $AC_CC \$FLAGS \$VFLAGS -o \$FULLNAME "\$@"; then
$PROG_LN_S \$FULLNAME \$LIBRARY
if $AC_CC \$FLAGS \$VFLAGS -o "\$FULLNAME" "\$@"; then
$PROG_LN_S "\$FULLNAME" "\$LIBRARY"
fi
;;
files) echo "\$FULLNAME"
;;
install)$PROG_INSTALL -c \$FULLNAME "\$1"
install)$PROG_INSTALL -c "\$FULLNAME" "\$1"
;;
esac
EOF
......@@ -1323,26 +1351,26 @@ 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.so"
FULLNAME="\$LIBNAME.\$VERSION"
case "\$ACTION" in
make) FLAGS="$AC_CFLAGS -shared"
unset VFLAGS
test "$USE_SONAME" && VFLAGS="-Wl,-soname,\$LIBNAME.\$MAJOR"
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
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" "\$LIBNAME" "\$LIBNAME.\$MAJOR"
;;
install)$PROG_INSTALL -c \$FULLNAME "\$1"
$PROG_LN_S -f \$FULLNAME \$1/\$LIBNAME.\$MAJOR
$PROG_LN_S -f \$FULLNAME \$1/\$LIBNAME
install)$PROG_INSTALL -c "\$FULLNAME" "\$1"
$PROG_LN_S -f "\$FULLNAME" "\$1/\$LIBNAME.\$MAJOR"
$PROG_LN_S -f "\$FULLNAME" "\$1/\$LIBNAME"
EOF
test "$LDCONFIG" && echo ' '$LDCONFIG '"$1"' >> librarian.sh
cat >> librarian.sh << EOF
......@@ -1540,13 +1568,66 @@ AC_FAIL() {
$__fail 1
}
#
# __ac_config_sed; a C program to do escaping for AC_SUB
__ac_config_sed() {
test -x config.sed && return
echo "generating config.sed"
AC_PROG_CC
cat > ngc$$.c << \EOF
#include <stdio.h>
int
main(argc, argv)
int argc;
char **argv;
{
char *p;
if (argc != 3)
return 1;
printf("s;@%s@;", argv[1]);
for (p=argv[2]; *p; ++p) {
if ( *p == ';' )
putchar('\\');
putchar(*p);
}
puts(";g");
return 0;
}
EOF
$AC_CC -o config.sed ngc$$.c
status=$?
rm -f ngc$$.c
if [ "$status" -eq 0 ]; then
__config_files="$__config_files config.sed"
else
AC_FAIL "Cannot generate config.sed helper program"
fi
}
#
# AC_SUB writes a substitution into config.sub
AC_SUB() {
( _target="$1"
shift
_subst=`echo "$*" | sed -e 's/;/\\;/g'`
echo "s;@$_target@;$_subst;g" ) >> "$__cwd"/config.sub
_target="$1"
shift
echo "target=$_target, rest=$*"
__ac_config_sed
./config.sed "$_target" "$*" >> "$__cwd"/config.sub
}
#
......
......@@ -9,7 +9,8 @@
#
ac_help='--enable-amalloc Enable memory allocation debugging
--with-tabstops=N Set tabstops to N characters (default is 4)
--shared Build shared libraries (default is static)'
--shared Build shared libraries (default is static)
--pkg-config Install pkg-config(1) glue files'
LOCAL_AC_OPTIONS='
set=`locals $*`;
......@@ -31,6 +32,9 @@ locals() {
--DEBIAN-GLITCH)
echo DEBIAN_GLITCH=T
;;
--PKG-CONFIG)
echo PKGCONFIG=true
;;
esac
}
......@@ -63,6 +67,7 @@ AC_DEFINE THEME_CF "$THEME_CF"
test "$DEBIAN_GLITCH" && AC_DEFINE 'DEBIAN_GLITCH' 1
AC_PROG_CC
AC_CHECK_NORETURN
test "$TRY_SHARED" && AC_COMPILER_PIC && AC_CC_SHLIBS
......@@ -85,6 +90,17 @@ fi
AC_PROG ar || AC_FAIL "$TARGET requires ar"
AC_PROG ranlib
# should we create a .pc for pkg-config & GNU automake
#
if [ "$PKGCONFIG" ]; then
AC_SUB MK_PKGCONFIG ''
elif AC_PROG pkg-config || AC_PROG automake ; then
PKGCONFIG=true
AC_SUB MK_PKGCONFIG ''
else
AC_SUB MK_PKGCONFIG '#'
fi
AC_C_VOLATILE
AC_C_CONST
AC_C_INLINE
......@@ -162,4 +178,10 @@ fi
[ "$WITH_PANDOC_HEADER" ] && AC_DEFINE 'PANDOC_HEADER' '1'
AC_OUTPUT Makefile version.c mkdio.h libmarkdown.pc
GENERATE="Makefile version.c mkdio.h"
if [ "$PKGCONFIG" ]; then
GENERATE="$GENERATE libmarkdown.pc"
fi
AC_OUTPUT $GENERATE
......@@ -852,7 +852,7 @@ code(MMIOT *f, char *s, int length)
int i,c;
for ( i=0; i < length; i++ )
if ( (c = s[i]) == MKD_EOLN) /* ^C: expand back to 2 spaces */
if ( (c = s[i]) == MKD_EOLN) /* expand back to 2 spaces */
Qstring(" ", f);
else if ( c == '\\' && (i < length-1) && escaped(f, s[i+1]) )
cputc(s[++i], f);
......
......@@ -119,7 +119,8 @@ Use id= anchors instead of <a name=/> for table-of-contents links.
.It Ar MKD_GITHUBTAGS
Allow underscore and dash in passed through element names.
.It Ar MKD_URLENCODEDANCHOR
Use url-encoded chars for multibyte and nonalphanumeric chars rather than dots in toc links.
Use html5 encoding for multibyte and nonalphanumeric characters rather
than hex expansion in toc links.
.El
.Sh RETURN VALUES
.Fn markdown
......
......@@ -51,7 +51,6 @@ typedef struct paragraph {
struct line *text; /* all the text in this paragraph */
char *ident; /* %id% tag for QUOTE */
char *lang; /* lang attribute for CODE */
char *label; /* label for TOC */
enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
HTML, STYLE, DL, UL, OL, AL, LISTITEM,
HDR, HR, TABLE, SOURCE } typ;
......@@ -146,7 +145,7 @@ typedef struct mmiot {
} MMIOT;
#define MKD_EOLN 3
#define MKD_EOLN '\r'
/*
......
......@@ -166,11 +166,14 @@ char **argv;
" type=\"text/css\"\n"
" href=\"%s\" />\n", T(css)[i]);
if ( h ) {
fprintf(output," <title>");
fprintf(output," <title>");
if ( h )
mkd_generateline(h, strlen(h), output, 0);
fprintf(output, "</title>\n");
}
/* xhtml requires a <title> in the header, even if it doesn't
* contain anything
*/
fprintf(output, "</title>\n");
for ( i=0; i < S(headers); i++ )
fprintf(output, " %s\n", T(headers)[i]);
fprintf(output, "</head>\n"
......
......@@ -220,25 +220,39 @@ mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
int i, size;
char *line;
/* MKD_URLENCODEDANCHOR is now perverted to being a html5 anchor
*
* !labelformat: print all characters
* labelformat && h4anchor: prefix nonalpha label with L,
* expand all nonalnum, _, ':', '.' to hex
* except space which maps to -
* labelformat && !h4anchor:expand space to -, other isspace() & '%' to hex
*/
int h4anchor = !(flags & MKD_URLENCODEDANCHOR);
size = mkd_line(s, len, &line, IS_LABEL);
if ( !(flags & MKD_URLENCODEDANCHOR)
&& labelformat
&& (size>0) && !isalpha(line[0]) )
if ( h4anchor && labelformat && (size>0) && !isalpha(line[0]) )
(*outchar)('L',out);
for ( i=0; i < size ; i++ ) {
c = line[i];
if ( labelformat ) {
if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) )
if ( h4anchor
? (isalnum(c) || (c == '_') || (c == ':') || (c == '.' ) )
: !(isspace(c) || c == '%') )
(*outchar)(c, out);
else if ( flags & MKD_URLENCODEDANCHOR ) {
(*outchar)('%', out);
(*outchar)(hexchars[c >> 4 & 0xf], out);
(*outchar)(hexchars[c & 0xf], out);
else {
if ( c == ' ' )
(*outchar)('-', out);
else {
(*outchar)(h4anchor ? '-' : '%', out);
(*outchar)(hexchars[c >> 4 & 0xf], out);
(*outchar)(hexchars[c & 0xf], out);
if ( h4anchor )
(*outchar)('-', out);
}
}
else
(*outchar)('.', out);
}
else
(*outchar)(c,out);
......@@ -272,15 +286,14 @@ mkd_line(char *bfr, int size, char **res, DWORD flags)
mkd_parse_line(bfr, size, &f, flags);
if ( len = S(f.out) ) {
/* kludge alert; we know that T(f.out) is malloced memory,
* so we can just steal it away. This is awful -- there
* should be an opaque method that transparently moves
* the pointer out of the embedded Cstring.
*/
EXPAND(f.out) = 0;
*res = T(f.out);
T(f.out) = 0;
S(f.out) = ALLOCATED(f.out) = 0;
/* strdup() doesn't use amalloc(), so in an amalloc()ed
* build this copies the string safely out of our memory
* paranoia arena. In a non-amalloc world, it's a spurious
* memory allocation, but it avoids unintentional hilarity
* with amalloc()
*/
*res = strdup(T(f.out));
}
else {
*res = 0;
......
......@@ -65,6 +65,7 @@ main()
KW("H6");
KW("LISTING");
KW("NOBR");
KW("FORM");
KW("UL");
KW("P");
KW("OL");
......
......@@ -60,7 +60,8 @@ static struct _opt {
{ "fencedcode", "fenced code blocks", 0, 0, 1, MKD_FENCEDCODE },
{ "idanchor", "id= anchors in TOC", 0, 0, 1, MKD_IDANCHOR },
{ "githubtags", "permit - and _ in element names", 0, 0, 0, MKD_GITHUBTAGS },
{ "urlencodedanchor", "urlencode special chars in TOC links", 0, 0, 0, MKD_URLENCODEDANCHOR },
{ "urlencodedanchor", "html5-style anchors", 0, 0, 0, MKD_URLENCODEDANCHOR },
{ "html5anchor", "html5-style anchors", 0, 1, 0, MKD_URLENCODEDANCHOR },
{ "latex", "handle LaTeX escapes", 0, 0, 1, MKD_LATEX },
} ;
......
......@@ -82,5 +82,16 @@ try 'block with trailing text' '<p>this is</p>a test' \
try 'unclosed block' '<p>here we go!' '<p><p>here we go!</p>'
try '<form> block' '<form>
pie?
</form>' '<form>
pie?
</form>'
summary $0
exit $rc
......@@ -19,30 +19,30 @@ hi' \
<p>hi</p>'
try -fidanchor -fnourlencodedanchor '-T -ftoc' 'toc item with link' \
try -fidanchor -fnohtml5anchor '-T -ftoc' 'toc item with link' \
'##[H2](H2) here' \
'<ul>
<li>
<ul>
<li><a href="#H2.here">H2 here</a></li>
<li><a href="#H2-here">H2 here</a></li>
</ul>
</li>
</ul>
<h2 id="H2.here"><a href="H2">H2</a> here</h2>'
<h2 id="H2-here"><a href="H2">H2</a> here</h2>'
try -fidanchor -fnourlencodedanchor '-T -ftoc' 'toc item with non-alpha start' \
try -fidanchor -fnohtml5anchor '-T -ftoc' 'toc item with non-alpha start' \
'#1 header' \
'<ul>
<li><a href="#L1.header">1 header</a></li>
<li><a href="#L1-header">1 header</a></li>
</ul>
<h1 id="L1.header">1 header</h1>'
<h1 id="L1-header">1 header</h1>'
try -fidanchor -furlencodedanchor '-T -ftoc' 'toc item with non-alpha start (url encoded)' \
try -fidanchor -fhtml5anchor '-T -ftoc' 'toc item with non-alpha start (url encoded)' \
'#1 header' \
'<ul>
<li><a href="#1%20header">1 header</a></li>
<li><a href="#1-header">1 header</a></li>
</ul>
<h1 id="1%20header">1 header</h1>'
<h1 id="1-header">1 header</h1>'
summary $0
......@@ -67,28 +67,28 @@ try '-T -ftoc' 'toc item with link' \
'<ul>
<li>
<ul>
<li><a href="#H2.here">H2 here</a></li>
<li><a href="#H2-here">H2 here</a></li>
</ul>
</li>
</ul>
<a name="H2.here"></a>
<a name="H2-here"></a>
<h2><a href="H2">H2</a> here</h2>'
try '-T -ftoc' 'toc item with non-alpha start' \
'#1 header' \
'<ul>
<li><a href="#L1.header">1 header</a></li>
<li><a href="#L1-header">1 header</a></li>
</ul>
<a name="L1.header"></a>
<a name="L1-header"></a>
<h1>1 header</h1>'
# Be sure to save toc.t as UTF-8.
try '-T -ftoc,urlencodedanchor' 'urlencoded multibyte chars' \
try '-T -ftoc,html5anchor' 'html5 multibyte chars' \
'#It’s an apostrophe' \
'<ul>
<li><a href="#It%e2%80%99s%20an%20apostrophe">It’s an apostrophe</a></li>
<li><a href="#It’s-an-apostrophe">It’s an apostrophe</a></li>
</ul>
<a name="It%e2%80%99s%20an%20apostrophe"></a>
<a name="It’s-an-apostrophe"></a>
<h1>It’s an apostrophe</h1>'
summary $0
......
......@@ -64,9 +64,8 @@ mkd_toc(Document *p, char **doc)
S(srcp->text->text),
(mkd_sta_function_t)Csputc, &res,1,p->ctx->flags);
Csprintf(&res, "\">");
mkd_string_to_anchor(T(srcp->text->text),
S(srcp->text->text),
(mkd_sta_function_t)Csputc, &res,0,p->ctx->flags);
Csreparse(&res, T(srcp->text->text),
S(srcp->text->text), IS_LABEL);
Csprintf(&res, "</a>");
first = 0;
......
......@@ -24,9 +24,11 @@ mkd_xhtmlpage(Document *p, int flags, FILE *out)
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n") );
DO_OR_DIE( fprintf(out, "<head>\n") );
DO_OR_DIE( fprintf(out, "<title>") );
if ( title = mkd_doc_title(p) ) {
DO_OR_DIE( fprintf(out, "<title>%s</title>\n", title) );
DO_OR_DIE( fprintf(out, "%s", title) );
}
DO_OR_DIE( fprintf(out, "</title>\n") );
DO_OR_DIE( mkd_generatecss(p, out) );
DO_OR_DIE( fprintf(out, "</head>\n"
"<body>\n") );
......
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