Convert --with-dl to runtime flags for issue #124.

Instead of specifying `./configure.sh --with-dl=both`, specify
`-fdlextra` or `MKD_DLEXTRA` at runtime.
This commit is contained in:
Nathan Phillip Brink
2015-07-13 03:24:29 +00:00
parent af67d351f8
commit 811a8560dd
10 changed files with 71 additions and 65 deletions
+3 -8
View File
@@ -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
@@ -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`.
+6 -10
View File
@@ -9,7 +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
@@ -48,15 +47,12 @@ TARGET=markdown
AC_INIT $TARGET
__DL=`echo "$WITH_DL" | $AC_UPPERCASE`
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
for banned_with in dl; do
banned_with_variable_ref=\$WITH_`echo "$banned_with" | $AC_UPPERCASE`
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_FENCED_CODE" && AC_DEFINE "WITH_FENCED_CODE" 1
test "$WITH_ID_ANCHOR" && AC_DEFINE 'WITH_ID_ANCHOR' 1
+2
View File
@@ -30,6 +30,8 @@ static struct flagnames flagnames[] = {
{ MKD_NODLIST, "!DLIST" },
{ MKD_EXTRA_FOOTNOTE, "FOOTNOTE" },
{ MKD_NOSTYLE, "!STYLE" },
{ MKD_NODLDISCOUNT, "!DLDISCOUNT" },
{ MKD_DLEXTRA, "DLEXTRA" },
};
#define NR(x) (sizeof x/sizeof x[0])
+9 -1
View File
@@ -106,7 +106,15 @@ 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
+15 -16
View File
@@ -434,10 +434,11 @@ end_of_block(Line *t)
static Line*
is_discount_dt(Line *t, int *clip)
is_discount_dt(Line *t, int *clip, DWORD flags)
{
#if USE_DISCOUNT_DL
if ( t && t->next
if ( !(flags & MKD_NODLDISCOUNT)
&& t
&& t->next
&& (S(t->text) > 2)
&& (t->dle == 0)
&& (T(t->text)[0] == '=')
@@ -447,9 +448,8 @@ is_discount_dt(Line *t, int *clip)
return t;
}
else
return is_discount_dt(t->next, clip);
return is_discount_dt(t->next, clip, flags);
}
#endif
return 0;
}
@@ -463,11 +463,11 @@ is_extra_dd(Line *t)
static Line*
is_extra_dt(Line *t, int *clip)
is_extra_dt(Line *t, int *clip, DWORD flags)
{
#if USE_EXTRA_DL
if ( t && t->next && S(t->text) && T(t->text)[0] != '='
if ( flags & MKD_DLEXTRA
&& t
&& t->next && S(t->text) && T(t->text)[0] != '='
&& T(t->text)[S(t->text)-1] != '=') {
Line *x;
@@ -479,25 +479,24 @@ is_extra_dt(Line *t, int *clip)
return t;
}
if ( x=is_extra_dt(t->next, clip) )
if ( x=is_extra_dt(t->next, clip, flags) )
return x;
}
#endif
return 0;
}
static Line*
isdefinition(Line *t, int *clip, int *kind)
isdefinition(Line *t, int *clip, int *kind, DWORD flags)
{
Line *ret;
*kind = 1;
if ( ret = is_discount_dt(t,clip) )
if ( ret = is_discount_dt(t,clip,flags) )
return ret;
*kind=2;
return is_extra_dt(t,clip);
return is_extra_dt(t,clip,flags);
}
@@ -510,7 +509,7 @@ islist(Line *t, int *clip, DWORD flags, int *list_type)
if ( end_of_block(t) )
return 0;
if ( !(flags & (MKD_NODLIST|MKD_STRICT)) && isdefinition(t,clip,list_type) )
if ( !(flags & (MKD_NODLIST|MKD_STRICT)) && isdefinition(t,clip,list_type,flags) )
return DL;
if ( strchr("*-+", T(t->text)[t->dle]) && isspace(T(t->text)[t->dle+1]) ) {
@@ -902,7 +901,7 @@ definition_block(Paragraph *top, int clip, MMIOT *f, int kind)
while (( labels = q )) {
if ( (q = isdefinition(labels, &z, &kind)) == 0 )
if ( (q = isdefinition(labels, &z, &kind, f->flags)) == 0 )
break;
if ( (text = skipempty(q->next)) == 0 )
+2
View File
@@ -129,6 +129,8 @@ typedef struct mmiot {
#define MKD_NODLIST 0x00100000
#define MKD_EXTRA_FOOTNOTE 0x00200000
#define MKD_NOSTYLE 0x00400000
#define MKD_NODLDISCOUNT 0x00800000
#define MKD_DLEXTRA 0x01000000
#define IS_LABEL 0x08000000
#define USER_FLAGS 0x0FFFFFFF
#define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
+3
View File
@@ -106,6 +106,9 @@ void mkd_ref_prefix(MMIOT*, char*);
#define MKD_NODLIST 0x00100000 /* forbid definition lists */
#define MKD_EXTRA_FOOTNOTE 0x00200000 /* enable markdown extra-style footnotes */
#define MKD_NOSTYLE 0x00400000 /* don't extract <style> blocks */
#define MKD_NODLDISCOUNT 0x00800000 /* disable discount-style definition lists */
#define MKD_DLEXTRA 0x01000000 /* enable extra-style definition lists */
#define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT
/* special flags for mkd_in() and mkd_string()
+3 -1
View File
@@ -25,7 +25,7 @@ static struct _opt {
char *name;
char *desc;
int off;
int skip;
int skip; /* this opt is a synonym */
int sayenable;
mkd_flag_t flag;
} opts[] = {
@@ -55,6 +55,8 @@ static struct _opt {
{ "footnotes", "markdown extra footnotes", 0, 0, 1, MKD_EXTRA_FOOTNOTE },
{ "footnote", "markdown extra footnotes", 0, 1, 1, MKD_EXTRA_FOOTNOTE },
{ "style", "extract style blocks", 1, 0, 1, MKD_NOSTYLE },
{ "dldiscount", "discount-style definition lists", 1, 0, 1, MKD_NODLDISCOUNT },
{ "dlextra", "extra-style definition lists", 0, 0, 1, MKD_DLEXTRA },
} ;
#define NR(x) (sizeof x / sizeof x[0])
+28 -18
View File
@@ -2,10 +2,6 @@
title "definition lists"
eval `./markdown -V | tr ' ' '\n' | grep '^DL='`
DL=${DL:-BOTH}
rc=0
MARKDOWN_FLAGS=
@@ -22,11 +18,11 @@ RSLT='<dl>
<dd>eh?</dd>
</dl>'
if [ "$DL" = "DISCOUNT" -o "$DL" = "BOTH" ]; then
try -fdefinitionlist '=tag= generates definition lists' "$SRC" "$RSLT"
# discount style
try -fdefinitionlist '=tag= generates definition lists' "$SRC" "$RSLT"
try 'one item with two =tags=' \
'=this=
try 'one item with two =tags=' \
'=this=
=is=
A test, eh?' \
'<dl>
@@ -35,16 +31,14 @@ if [ "$DL" = "DISCOUNT" -o "$DL" = "BOTH" ]; then
<dd>A test, eh?</dd>
</dl>'
try -fnodefinitionlist '=tag= does nothing' "$SRC" \
'<p>=this=
# extra style
try -fnodefinitionlist,dlextra '=tag= does nothing' "$SRC" \
'<p>=this=
is an ugly
=test=
eh?</p>'
fi
if [ "$DL" = "EXTRA" -o "$DL" = "BOTH" ]; then
try 'markdown extra-style definition lists' \
try -fdlextra 'markdown extra-style definition lists' \
'foo
: bar' \
'<dl>
@@ -52,7 +46,7 @@ if [ "$DL" = "EXTRA" -o "$DL" = "BOTH" ]; then
<dd>bar</dd>
</dl>'
try '... with two <dt>s in a row' \
try -fdlextra '... with two <dt>s in a row' \
'foo
bar
: baz' \
@@ -62,7 +56,7 @@ bar
<dd>baz</dd>
</dl>'
try '... with two <dd>s in a row' \
try -fdlextra '... with two <dd>s in a row' \
'foo
: bar
: baz' \
@@ -72,7 +66,7 @@ bar
<dd>baz</dd>
</dl>'
try '... with blanks between list items' \
try -fdlextra '... with blanks between list items' \
'foo
: bar
@@ -85,7 +79,23 @@ zip
<dd>zap</dd>
</dl>'
fi
# Hmm, redundancy...
SRC='foo
: bar
=this=
is ugly'
RSLT='<p>foo
: bar</p>
<p>=this=
is ugly</p>'
try -fnodldiscount '... with definitionlists enabled but all styles disabled' \
"$SRC" \
"$RSLT"
try -fnodefinitionlist,dldiscount,dlextra '... with definitionlists disabled but all styles enabled' \
"$SRC" \
"$RSLT"
summary $0
exit $rc
-11
View File
@@ -7,17 +7,6 @@ char markdown_version[] = VERSION
#if USE_AMALLOC
" DEBUG"
#endif
#if USE_DISCOUNT_DL
# if USE_EXTRA_DL
" DL=BOTH"
# else
" DL=DISCOUNT"
# endif
#elif USE_EXTRA_DL
" DL=EXTRA"
#else
" DL=NONE"
#endif
#if WITH_ID_ANCHOR
" ID-ANCHOR"
#endif