Skip to content

Commit

Permalink
Convert compiletime ID Anchor setting to runtime flag for issue Orc#124.
Browse files Browse the repository at this point in the history
Now specify flag `-fidanchor` or `MKD_IDANCHOR` instead of
`./configure.sh --with-id-anchor`. In `markdown -VV` displays as
`IDANCHOR` or `!IDANCHOR` rather than `ID-ANCHOR`.
  • Loading branch information
binki committed Jul 13, 2015
1 parent 157dad9 commit dad15d5
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 50 deletions.
4 changes: 1 addition & 3 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#
ac_help='--enable-amalloc Enable memory allocation debugging
--with-tabstops=N Set tabstops to N characters (default is 4)
--with-id-anchor Use id= anchors for table-of-contents links
--with-github-tags Allow `_` and `-` in <> tags
--with-urlencoded-anchor Use url-encoded chars to multibyte chars in toc links
--enable-all-features Turn on all stable optional features
Expand Down Expand Up @@ -46,14 +45,13 @@ TARGET=markdown

AC_INIT $TARGET

for banned_with in dl fenced-code; do
for banned_with in dl fenced-code id-anchor; do
banned_with_variable_ref=\$WITH_`echo "$banned_with" | $AC_UPPERCASE | tr - _`
if [ "`eval echo "$banned_with_variable_ref"`" ]; then
AC_FAIL "Invalid option: --with-$banned_with. Please use a runtime flag to configure this feature."
fi
done

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
Expand Down
1 change: 1 addition & 0 deletions flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static struct flagnames flagnames[] = {
{ MKD_NODLDISCOUNT, "!DLDISCOUNT" },
{ MKD_DLEXTRA, "DLEXTRA" },
{ MKD_FENCEDCODE, "FENCEDCODE" },
{ MKD_IDANCHOR, "IDANCHOR" },
};
#define NR(x) (sizeof x/sizeof x[0])

Expand Down
38 changes: 19 additions & 19 deletions generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,26 +1426,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);
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);
}
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);
Expand Down
2 changes: 2 additions & 0 deletions markdown.1
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Allow markdown extra-style footnotes.
Extract <style> blocks from the output.
.It Ar fencedcode
Allow fenced code blocks (not default).
.It Ar idanchor
Use id= anchors for table-of-contents links instead of <a name=/> (not default).
.El
.Pp
As an example, the option
Expand Down
2 changes: 2 additions & 0 deletions markdown.3
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Enable markdown extra-style footnotes.
Do not extract (omit) <style/> blocks from the output.
.It Ar MKD_FENCEDCODE
Allow fenced code blocks.
.It Ar MKD_IDANCHOR
Use id= anchors instead of <a name=/> for table-of-contents links.
.El
.Sh RETURN VALUES
.Fn markdown
Expand Down
1 change: 1 addition & 0 deletions markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ typedef struct mmiot {
#define MKD_NODLDISCOUNT 0x00800000
#define MKD_DLEXTRA 0x01000000
#define MKD_FENCEDCODE 0x02000000
#define MKD_IDANCHOR 0x04000000
#define IS_LABEL 0x08000000
#define USER_FLAGS 0x0FFFFFFF
#define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
Expand Down
1 change: 1 addition & 0 deletions mkdio.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void mkd_ref_prefix(MMIOT*, char*);
#define MKD_NODLDISCOUNT 0x00800000 /* disable discount-style definition lists */
#define MKD_DLEXTRA 0x01000000 /* enable extra-style definition lists */
#define MKD_FENCEDCODE 0x02000000 /* enabled fenced code blocks */
#define MKD_IDANCHOR 0x04000000 /* use id= anchors for TOC links */

#define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT

Expand Down
1 change: 1 addition & 0 deletions pgm_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static struct _opt {
{ "dldiscount", "discount-style definition lists", 1, 0, 1, MKD_NODLDISCOUNT },
{ "dlextra", "extra-style definition lists", 0, 0, 1, MKD_DLEXTRA },
{ "fencedcode", "fenced code blocks", 0, 0, 1, MKD_FENCEDCODE },
{ "idanchor", "id= anchors in TOC", 0, 0, 1, MKD_IDANCHOR },
} ;

#define NR(x) (sizeof x / sizeof x[0])
Expand Down
49 changes: 24 additions & 25 deletions tests/toc.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
rc=0
MARKDOWN_FLAGS=

if ./markdown -V | grep ID-ANCHOR >/dev/null; then
# old-style; uses id= tag (and collides
# with #-style css)

title "(old) table-of-contents support"

try '-T -ftoc' 'table of contents' \
'#H1
# old-style; uses id= tag (and collides
# with #-style css)

title "(old) table-of-contents support"

try -fidanchor '-T -ftoc' 'table of contents' \
'#H1
hi' \
'<ul>
<li><a href="#H1">H1</a></li>
Expand All @@ -20,8 +19,8 @@ hi' \
<p>hi</p>'

try '-T -ftoc' 'toc item with link' \
'##[H2](H2) here' \
try -fidanchor '-T -ftoc' 'toc item with link' \
'##[H2](H2) here' \
'<ul>
<li>
<ul>
Expand All @@ -31,21 +30,22 @@ hi' \
</ul>
<h2 id="H2.here"><a href="H2">H2</a> here</h2>'

try '-T -ftoc' 'toc item with non-alpha start' \
'#1 header' \
try -fidanchor '-T -ftoc' 'toc item with non-alpha start' \
'#1 header' \
'<ul>
<li><a href="#L1.header">1 header</a></li>
</ul>
<h1 id="L1.header">1 header</h1>'

else
# new-style; uses a (depreciated) name=
# inside a null <a> tag

title "(new) table-of-contents support"

try '-T -ftoc' 'table of contents' \
'#H1
summary $0

# new-style; uses a (depreciated) name=
# inside a null <a> tag

title "(new) table-of-contents support"

try '-T -ftoc' 'table of contents' \
'#H1
hi' \
'<ul>
<li><a href="#H1">H1</a></li>
Expand All @@ -55,8 +55,8 @@ hi' \
<p>hi</p>'

try '-T -ftoc' 'toc item with link' \
'##[H2](H2) here' \
try '-T -ftoc' 'toc item with link' \
'##[H2](H2) here' \
'<ul>
<li>
<ul>
Expand All @@ -67,14 +67,13 @@ hi' \
<a name="H2.here"></a>
<h2><a href="H2">H2</a> here</h2>'

try '-T -ftoc' 'toc item with non-alpha start' \
'#1 header' \
try '-T -ftoc' 'toc item with non-alpha start' \
'#1 header' \
'<ul>
<li><a href="#L1.header">1 header</a></li>
</ul>
<a name="L1.header"></a>
<h1>1 header</h1>'
fi

summary $0
exit $rc
3 changes: 0 additions & 3 deletions version.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ char markdown_version[] = VERSION
#if USE_AMALLOC
" DEBUG"
#endif
#if WITH_ID_ANCHOR
" ID-ANCHOR"
#endif
#if WITH_GITHUB_TAGS
" GITHUB-TAGS"
#endif
Expand Down

0 comments on commit dad15d5

Please sign in to comment.