From 811a8560dd5fddf345dd8aae38f8d6ff8b18d150 Mon Sep 17 00:00:00 2001 From: Nathan Phillip Brink Date: Sun, 12 Jul 2015 21:05:42 +0000 Subject: [PATCH 1/7] Convert --with-dl to runtime flags for issue #124. Instead of specifying `./configure.sh --with-dl=both`, specify `-fdlextra` or `MKD_DLEXTRA` at runtime. --- Plan9/README.md | 11 +++-------- configure.sh | 16 ++++++---------- flags.c | 2 ++ markdown.1 | 10 +++++++++- markdown.c | 31 +++++++++++++++---------------- markdown.h | 2 ++ mkdio.h.in | 3 +++ pgm_options.c | 4 +++- tests/dl.t | 46 ++++++++++++++++++++++++++++------------------ version.c.in | 11 ----------- 10 files changed, 71 insertions(+), 65 deletions(-) diff --git a/Plan9/README.md b/Plan9/README.md index 342a93e1..b0ec8e3e 100644 --- a/Plan9/README.md +++ b/Plan9/README.md @@ -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 `
`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 AB * `--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`. diff --git a/configure.sh b/configure.sh index bc73383a..ef0307dd 100755 --- a/configure.sh +++ b/configure.sh @@ -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 diff --git a/flags.c b/flags.c index cc1c589a..cda0f0f8 100644 --- a/flags.c +++ b/flags.c @@ -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]) diff --git a/markdown.1 b/markdown.1 index 60ad8c61..0fd0703b 100644 --- a/markdown.1 +++ b/markdown.1 @@ -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 diff --git a/markdown.c b/markdown.c index f43f5144..7f5b8448 100644 --- a/markdown.c +++ b/markdown.c @@ -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 ) diff --git a/markdown.h b/markdown.h index 8edd3024..34439fee 100644 --- a/markdown.h +++ b/markdown.h @@ -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) diff --git a/mkdio.h.in b/mkdio.h.in index 2527b8ef..4408cef9 100644 --- a/mkdio.h.in +++ b/mkdio.h.in @@ -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