Skip to content

Commit

Permalink
Make githubtags configurable at runtime for issue Orc#124.
Browse files Browse the repository at this point in the history
Instead of `./configure.sh --with-github-tags`, specify `-fgithubtags`
or `MKD_GITHUBTAGS`. Shows up in `markdown -VV` as `GITHUBTAGS`
instead of `GITHUB-TAGS` now.
  • Loading branch information
binki committed Jul 13, 2015
1 parent 2ff7c1f commit 5790b66
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 13 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-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
--shared Build shared libraries (default is static)'
Expand Down Expand Up @@ -45,14 +44,13 @@ TARGET=markdown

AC_INIT $TARGET

for banned_with in dl fenced-code id-anchor; do
for banned_with in dl fenced-code id-anchor github-tags; 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_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 @@ -34,6 +34,7 @@ static struct flagnames flagnames[] = {
{ MKD_DLEXTRA, "DLEXTRA" },
{ MKD_FENCEDCODE, "FENCEDCODE" },
{ MKD_IDANCHOR, "IDANCHOR" },
{ MKD_GITHUBTAGS, "GITHUBTAGS" },
};
#define NR(x) (sizeof x/sizeof x[0])

Expand Down
8 changes: 3 additions & 5 deletions generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,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;
}

Expand Down
2 changes: 2 additions & 0 deletions markdown.1
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Extract <style> blocks from the output.
Allow fenced code blocks (not default).
.It Ar idanchor
Use id= anchors for table-of-contents links instead of <a name=/> (not default).
.It Ar githubtags
Allow underscore and dash in passed through element names (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 @@ -116,6 +116,8 @@ Do not extract (omit) <style/> blocks from the output.
Allow fenced code blocks.
.It Ar MKD_IDANCHOR
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.
.El
.Sh RETURN VALUES
.Fn markdown
Expand Down
5 changes: 3 additions & 2 deletions markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ typedef struct mmiot {
#define MKD_DLEXTRA 0x01000000
#define MKD_FENCEDCODE 0x02000000
#define MKD_IDANCHOR 0x04000000
#define IS_LABEL 0x08000000
#define USER_FLAGS 0x0FFFFFFF
#define MKD_GITHUBTAGS 0x08000000
#define IS_LABEL 0x40000000
#define USER_FLAGS 0x7FFFFFFF
#define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)

Callback_data *cb;
Expand Down
1 change: 1 addition & 0 deletions mkdio.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void mkd_ref_prefix(MMIOT*, char*);
#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_GITHUBTAGS 0x08000000 /* allow dash and underscore in element names */

#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 @@ -59,6 +59,7 @@ static struct _opt {
{ "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 },
{ "githubtags", "permit - and _ in element names", 0, 0, 0, MKD_GITHUBTAGS },
} ;

#define NR(x) (sizeof x / sizeof x[0])
Expand Down
23 changes: 23 additions & 0 deletions tests/githubtags.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
. tests/functions.sh

title "github tags"

rc=0
MARKDOWN_FLAGS=

SRC='<element-name>content</element-name>'

try 'github tags disabled by default' \
"$SRC" \
'<p>&lt;element-name>content&lt;/element-name></p>'

try -fgithubtags 'github tags' \
"$SRC" \
'<p><element-name>content</element-name></p>'

try 'normal tags pass through' \
'<a>sdf</a>' \
'<p><a>sdf</a></p>'

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 @@ -6,8 +6,5 @@ char markdown_version[] = VERSION
#endif
#if USE_AMALLOC
" DEBUG"
#endif
#if WITH_GITHUB_TAGS
" GITHUB-TAGS"
#endif
;

0 comments on commit 5790b66

Please sign in to comment.