Permalink
Browse files

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.
  • Loading branch information...
1 parent b11ae91 commit acdd58b6f085693141913f1dc0d329a5306590b2 david parsons committed Feb 26, 2011
Showing with 26 additions and 2 deletions.
  1. +5 −0 configure.sh
  2. +12 −0 generate.c
  3. +1 −1 mkdio.c
  4. +5 −0 tests/toc.t
  5. +3 −1 version.c.in
View
@@ -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
View
@@ -1353,6 +1353,17 @@ 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),
@@ -1361,6 +1372,7 @@ printheader(Paragraph *pp, MMIOT *f)
Qstring("\"></a>\n", f);
}
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);
View
@@ -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);
View
@@ -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
View
@@ -18,5 +18,7 @@ char markdown_version[] = VERSION
#else
" DL=NONE"
#endif
-
+#if WITH_ID_ANCHOR
+ " ID-ANCHOR"
+#endif
;

0 comments on commit acdd58b

Please sign in to comment.