From acdd58b6f085693141913f1dc0d329a5306590b2 Mon Sep 17 00:00:00 2001 From: david parsons Date: Fri, 25 Feb 2011 22:43:04 -0800 Subject: [PATCH] Add new config options to support old-style table of contents links. --with-id-anchor makes discount use `id=` instead of `a name=`, and --with-anchor-default=C makes discount use the character C instead of `.` for illegal characters in anchors. --- configure.sh | 5 +++++ generate.c | 12 ++++++++++++ mkdio.c | 2 +- tests/toc.t | 5 +++++ version.c.in | 4 +++- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/configure.sh b/configure.sh index 870181d7..1f987be1 100755 --- a/configure.sh +++ b/configure.sh @@ -10,6 +10,8 @@ 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-anchor-default=C Use C instead of illegal characters in anchors --enable-all-features Turn on all stable optional features --shared Build shared libraries (default is static)' @@ -51,6 +53,9 @@ BOTH) AC_DEFINE 'USE_EXTRA_DL' 1 *) AC_FAIL "Unknown value <$WITH_DL> for --with-dl (want 'discount', 'extra', or 'both')" ;; esac +test "$WITH_ID_ANCHOR" && AC_DEFINE 'WITH_ID_ANCHOR' 1 +AC_DEFINE 'ANCHOR_DEFAULT_CHAR' "'${WITH_ANCHOR_DEFAULT:-.}'" + AC_PROG_CC test "$TRY_SHARED" && AC_COMPILER_PIC && AC_CC_SHLIBS diff --git a/generate.c b/generate.c index 5d03c565..f6f39937 100644 --- a/generate.c +++ b/generate.c @@ -1353,6 +1353,17 @@ text(MMIOT *f) static void printheader(Paragraph *pp, MMIOT *f) { +#if WITH_ID_ANCHOR + Qprintf(f, "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("text->text), @@ -1361,6 +1372,7 @@ printheader(Paragraph *pp, MMIOT *f) Qstring("\">\n", f); } Qprintf(f, "", pp->hnumber); +#endif push(T(pp->text->text), S(pp->text->text), f); text(f); Qprintf(f, "", pp->hnumber); diff --git a/mkdio.c b/mkdio.c index 5cead412..7b9aa13d 100644 --- a/mkdio.c +++ b/mkdio.c @@ -233,7 +233,7 @@ mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar, if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) ) (*outchar)(c, out); else - (*outchar)('.',out); + (*outchar)(ANCHOR_DEFAULT_CHAR, out); } else (*outchar)(c,out); diff --git a/tests/toc.t b/tests/toc.t index 7ba98f03..33046c52 100644 --- a/tests/toc.t +++ b/tests/toc.t @@ -1,5 +1,10 @@ . tests/functions.sh +# don't bother to test the table of contents code +# if we're using id= for labelling things +# +./markdown -V | grep ID-ANCHOR >/dev/null && exit 0 + title "table-of-contents support" rc=0 diff --git a/version.c.in b/version.c.in index 219b9354..02af3670 100644 --- a/version.c.in +++ b/version.c.in @@ -18,5 +18,7 @@ char markdown_version[] = VERSION #else " DL=NONE" #endif - +#if WITH_ID_ANCHOR + " ID-ANCHOR" +#endif ;