Skip to content

Commit

Permalink
Merge pull request #125 from binki/master
Browse files Browse the repository at this point in the history
#124: Convert much compiletime configuration to runtime flags
  • Loading branch information
David Parsons committed Jul 13, 2015
2 parents af67d35 + 5da3388 commit bde87f6
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 208 deletions.
11 changes: 3 additions & 8 deletions Plan9/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# *Discount* Markdown compiler on Plan 9

## Build
% CONFIG='--with-dl=both' mk config
% CONFIG='--with-tabstops=7' mk config
% mk test
% mk install
% markdown -V
markdown: discount X.Y.Z DL=BOTH
markdown: discount X.Y.Z TAB=7

### Configuration
To select features and extensions, `--with-dl=both` may be replaced by zero or more of:
To select features and extensions, `--with-tabstops=7` may be replaced by zero or more of:

* `--enable-dl-tag`: Enable the definition list tag extension with the default (`discount`) tag style
* `--with-dl=`*tagstyle*: Set the tags that define `<dl>`s to *tagstyle*. *Tagstyle* must be one of `discount`, `extra`, or `both`. Implies `--enable-dl-tag`.
* `--enable-pandoc-header`: Use pandoc-style header blocks
* `--enable-superscript`: `A^B` becomes A<sup>B</sup>
* `--enable-amalloc`: Enable memory allocation debugging
Expand All @@ -33,6 +31,3 @@ Installation is optional. Plan 9 binaries are statically linked.
* `install.progs`: Extra programs. *makepage* writes complete XHTML
documents, rather than fragments. *mkd2html* is similar, but produces
HTML.

3. `CONFIG`, the argument list given to `../configure.sh`, must contain at least `--with-dl=both` to produce a binary that
passes `../discount/tests/dl.t`.
24 changes: 6 additions & 18 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
#
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-github-tags Allow `_` and `-` in <> tags
--with-fenced-code Allow fenced code blocks
--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 @@ -48,20 +43,13 @@ TARGET=markdown

AC_INIT $TARGET

__DL=`echo "$WITH_DL" | $AC_UPPERCASE`
for banned_with in dl fenced-code id-anchor github-tags urlencoded-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

case "$__DL" in
EXTRA) AC_DEFINE 'USE_EXTRA_DL' 1 ;;
DISCOUNT|1|"") AC_DEFINE 'USE_DISCOUNT_DL' 1 ;;
BOTH) AC_DEFINE 'USE_EXTRA_DL' 1
AC_DEFINE 'USE_DISCOUNT_DL' 1 ;;
*) AC_FAIL "Unknown value <$WITH_DL> for --with-dl (want 'discount', 'extra', or 'both')" ;;
esac

test "$WITH_FENCED_CODE" && AC_DEFINE "WITH_FENCED_CODE" 1
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

AC_PROG_CC
Expand Down
6 changes: 6 additions & 0 deletions flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ static struct flagnames flagnames[] = {
{ MKD_NODLIST, "!DLIST" },
{ MKD_EXTRA_FOOTNOTE, "FOOTNOTE" },
{ MKD_NOSTYLE, "!STYLE" },
{ MKD_NODLDISCOUNT, "!DLDISCOUNT" },
{ MKD_DLEXTRA, "DLEXTRA" },
{ MKD_FENCEDCODE, "FENCEDCODE" },
{ MKD_IDANCHOR, "IDANCHOR" },
{ MKD_GITHUBTAGS, "GITHUBTAGS" },
{ MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" },
};
#define NR(x) (sizeof x/sizeof x[0])

Expand Down
46 changes: 22 additions & 24 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 Expand Up @@ -1426,26 +1424,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, f->flags);
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, f->flags);
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
20 changes: 18 additions & 2 deletions markdown.1
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,27 @@ blocks.
.It Ar alphalist
Allow alphabetic lists.
.It Ar definitionlist
Allow definition lists.
Allow definition lists at all (default). Use
.Em dldiscount
and
.Em dlextra
to control which syntaxes are respected.
.It Ar dldiscount
Enable discount-style definition lists (default).
.It Ar dlextra
Enable extra-style definition lists (not default). Both styles may be enabled simultaneously.
.It Ar footnote
Allow markdown extra-style footnotes.
.It Ar styles
.It Ar style
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).
.It Ar githubtags
Allow underscore and dash in passed through element names (not default).
.It Ar urlencodedanchor
Use url-encoded chars for multibyte and nonalphanumeric chars rather than dots in toc links.
.El
.Pp
As an example, the option
Expand Down
14 changes: 14 additions & 0 deletions markdown.3
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,22 @@ blocks.
Forbid alphabetic lists.
.It Ar MKD_NODLIST
Forbid definition lists.
.It Ar MKD_NODLDISCOUNT
Disable the discount definition list syntax style.
.It Ar MKD_DLEXTRA
Enable the extra definition list syntax style.
.It Ar MKD_EXTRA_FOOTNOTE
Enable markdown extra-style footnotes.
.It Ar MKD_NOSTYLE
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.
.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.
.El
.Sh RETURN VALUES
.Fn markdown
Expand Down
Loading

0 comments on commit bde87f6

Please sign in to comment.