From b52ec440d488e510a0109d6d47dd3a88fc421008 Mon Sep 17 00:00:00 2001 From: david parsons Date: Sun, 14 Apr 2019 20:56:55 -0700 Subject: [PATCH] strip out MKD_STRICT as a single flag (convert it into a composite flag that turns off a whole bunch of extensions); use that flagbit to disable github checkbox items, strip out MKD_DLIST as a single flag (convert it into a mask of MKD_DLDISCOUNT|MKD_DLEXTRA, and rework pgm_options so that 'strict' and 'relaxed' apply only to emphasis and 'standard' is the flag that sets & clears flags to make it closer to the standard. Version 3 because I'm fucking with the published interface --- VERSION | 2 +- configure.sh | 19 +++++----- dumptree.c | 2 - flags.c | 5 +-- generate.c | 13 +------ github_flavoured.c | 3 +- main.c | 6 ++- markdown.c | 17 +++------ markdown.h | 14 ++++--- mkdio.c | 2 +- mkdio.h.in | 11 ++++-- pgm_options.c | 92 +++++++++++++++++++++++++-------------------- tests/dl.t | 14 +++---- tests/list.t | 4 +- tests/superscript.t | 4 +- version.c.in | 6 ++- 16 files changed, 111 insertions(+), 103 deletions(-) diff --git a/VERSION b/VERSION index bda8fbe..00750ed 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.6 +3 diff --git a/configure.sh b/configure.sh index da9fa14..5b91399 100755 --- a/configure.sh +++ b/configure.sh @@ -45,12 +45,11 @@ locals() { --CXX-BINDING) echo CXX_BINDING=T ;; - --GITHUB-CHECKBOX) - echo GITHUB_CHECKBOX=T + --GITHUB-CHECKBOX|--GITHUB-CHECKBOX=ENTITY) + echo GITHUB_CHECKBOX_STYLE=entity ;; --GITHUB-CHECKBOX=INPUT) - echo GITHUB_CHECKBOX=T - echo GITHUB_CHECKBOX_AS_INPUT=T + echo GITHUB_CHECKBOX_STYLE=input ;; esac } @@ -79,8 +78,9 @@ done # theme wants the old behavior of --with-(foo) # case "`echo "$WITH_DL" | $AC_UPPERCASE`" in - EXTRA) THEME_CF="MKD_DLEXTRA|MKD_NODLDISCOUNT";; - BOTH) THEME_CF="MKD_DLEXTRA";; + DISCOUNT) THEME_CF="MKD_DLDISCOUNT";; + EXTRA) THEME_CF="MKD_DLEXTRA";; + BOTH) THEME_CF="MKD_DLIST";; esac test "$WITH_FENCED_CODE" && THEME_CF="${THEME_CF:+$THEME_CF|}MKD_FENCEDCODE" @@ -232,9 +232,10 @@ else AC_SUB 'H1TITLE' '' fi -if [ "$GITHUB_CHECKBOX" ]; then - AC_DEFINE 'GITHUB_CHECKBOX' '1' - test "$GITHUB_CHECKBOX_AS_INPUT" && AC_DEFINE 'CHECKBOX_AS_INPUT' '1' +if [ "$GITHUB_CHECKBOX_STYLE" = "entity" ]; then + AC_DEFINE 'CHECKBOX_AS_INPUT' '0' +else + AC_DEFINE 'CHECKBOX_AS_INPUT' '1' fi diff --git a/dumptree.c b/dumptree.c index e3fbaf3..2fca134 100644 --- a/dumptree.c +++ b/dumptree.c @@ -115,10 +115,8 @@ dumptree(Paragraph *pp, Stack *sp, FILE *f) if ( pp->ident ) d += fprintf(f, " %s", pp->ident); -#ifdef GITHUB_CHECKBOX if ( pp->flags ) d += fprintf(f, " %x", pp->flags); -#endif if ( pp->align > 1 ) d += fprintf(f, ", <%s>", Begin[pp->align]); diff --git a/flags.c b/flags.c index 78ff3dc..2742d53 100644 --- a/flags.c +++ b/flags.c @@ -11,7 +11,6 @@ static struct flagnames flagnames[] = { { MKD_NOIMAGE, "!IMAGE" }, { MKD_NOPANTS, "!PANTS" }, { MKD_NOHTML, "!HTML" }, - { MKD_STRICT, "STRICT" }, { MKD_TAGTEXT, "TAGTEXT" }, { MKD_NO_EXT, "!EXT" }, { MKD_CDATA, "CDATA" }, @@ -27,14 +26,14 @@ static struct flagnames flagnames[] = { { MKD_TABSTOP, "TABSTOP" }, { MKD_NODIVQUOTE, "!DIVQUOTE" }, { MKD_NOALPHALIST, "!ALPHALIST" }, - { MKD_NODLIST, "!DLIST" }, { MKD_EXTRA_FOOTNOTE, "FOOTNOTE" }, { MKD_NOSTYLE, "!STYLE" }, - { MKD_NODLDISCOUNT, "!DLDISCOUNT" }, + { MKD_DLDISCOUNT, "DLDISCOUNT" }, { MKD_DLEXTRA, "DLEXTRA" }, { MKD_FENCEDCODE, "FENCEDCODE" }, { MKD_IDANCHOR, "IDANCHOR" }, { MKD_GITHUBTAGS, "GITHUBTAGS" }, + { MKD_NORMAL_LISTITEM, "NORMAL_LISTITEM" }, { MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" }, { MKD_LATEX, "LATEX" }, { MKD_EXPLICITLIST, "EXPLICITLIST" }, diff --git a/generate.c b/generate.c index 0831925..30acb64 100644 --- a/generate.c +++ b/generate.c @@ -1352,7 +1352,6 @@ text(MMIOT *f) break; /* A^B -> AB */ case '^': if ( is_flag_set(f->flags, MKD_NOSUPERSCRIPT) - || is_flag_set(f->flags, MKD_STRICT) || is_flag_set(f->flags, MKD_TAGTEXT) || (f->last == 0) || ((ispunct(f->last) || isspace(f->last)) @@ -1390,7 +1389,7 @@ text(MMIOT *f) break; case '_': /* Underscores don't count if they're in the middle of a word */ - if ( !(is_flag_set(f->flags, MKD_NORELAXED) || is_flag_set(f->flags, MKD_STRICT)) + if ( !is_flag_set(f->flags, MKD_NORELAXED) && isthisalnum(f,-1) && isthisalnum(f,1) ) { Qchar(c, f); break; @@ -1413,7 +1412,6 @@ text(MMIOT *f) break; case '~': if ( is_flag_set(f->flags, MKD_NOSTRIKETHROUGH) - || is_flag_set(f->flags, MKD_STRICT) || is_flag_set(f->flags, MKD_TAGTEXT) || ! tickhandler(f,c,2,0, delspan) ) Qchar(c, f); @@ -1437,8 +1435,7 @@ text(MMIOT *f) } break; - case '^': if ( is_flag_set(f->flags, MKD_STRICT) - || is_flag_set(f->flags, MKD_NOSUPERSCRIPT) ) { + case '^': if ( is_flag_set(f->flags, MKD_NOSUPERSCRIPT) ) { Qchar('\\', f); shift(f,-1); break; @@ -1779,7 +1776,6 @@ htmlify_paragraphs(Paragraph *p, MMIOT *f) } -#ifdef GITHUB_CHECKBOX static void li_htmlify(Paragraph *p, char *arguments, mkd_flag_t flags, MMIOT *f) { @@ -1808,7 +1804,6 @@ li_htmlify(Paragraph *p, char *arguments, mkd_flag_t flags, MMIOT *f) Qprintf(f, ""); ___mkd_emblock(f); } -#endif static void @@ -1860,11 +1855,7 @@ listdisplay(int typ, Paragraph *p, MMIOT* f) Qprintf(f, ">\n"); for ( ; p ; p = p->next ) { -#ifdef GITHUB_CHECKBOX li_htmlify(p->down, p->ident, p->flags, f); -#else - htmlify(p->down, "li", p->ident, f); -#endif Qchar('\n', f); } diff --git a/github_flavoured.c b/github_flavoured.c index 019f783..f7a40cd 100644 --- a/github_flavoured.c +++ b/github_flavoured.c @@ -59,8 +59,7 @@ gfm_populate(getc_func getc, void* ctx, int flags) DELETE(line); - if ( (pandoc == 3) && !(is_flag_set(flags, MKD_NOHEADER) - || is_flag_set(flags, MKD_STRICT)) ) { + if ( (pandoc == 3) && !is_flag_set(flags, MKD_NOHEADER) ) { /* the first three lines started with %, so we have a header. * clip the first three lines out of content and hang them * off header. diff --git a/main.c b/main.c index 65985f2..79f83ce 100644 --- a/main.c +++ b/main.c @@ -263,8 +263,10 @@ main(int argc, char **argv) if ( version ) { printf("%s: discount %s%s", pgm, markdown_version, with_html5 ? " +html5":""); - if ( version > 1 ) + if ( version == 2 ) mkd_flags_are(stdout, flags, 0); + if ( version >= 3 ) + printf(" MARKDOWN_FLAGS=0x%08x", flags); putchar('\n'); exit(0); } @@ -308,7 +310,7 @@ main(int argc, char **argv) if ( squash ) mkd_e_anchor(doc, (mkd_callback_t) anchor_format); if ( use_e_codefmt ) - mkd_e_code_format(doc, external_codefmt); + mkd_e_code_format(doc, (mkd_callback_t)external_codefmt); if ( use_e_codefmt || squash ) mkd_e_free(doc, free_it); diff --git a/markdown.c b/markdown.c index 9ff8c28..2e068e2 100644 --- a/markdown.c +++ b/markdown.c @@ -445,7 +445,7 @@ end_of_block(Line *t, mkd_flag_t flags) static Line* is_discount_dt(Line *t, int *clip, mkd_flag_t flags) { - if ( !is_flag_set(flags, MKD_NODLDISCOUNT) + if ( is_flag_set(flags, MKD_DLDISCOUNT) && t && t->next && (S(t->text) > 2) @@ -518,8 +518,7 @@ islist(Line *t, int *clip, mkd_flag_t flags, int *list_type) if ( end_of_block(t, flags) ) return 0; - if ( !(is_flag_set(flags, MKD_NODLIST) || is_flag_set(flags, MKD_STRICT)) - && isdefinition(t,clip,list_type,flags) ) + if ( is_flag_set(flags, MKD_DLIST) && isdefinition(t,clip,list_type,flags) ) return DL; if ( strchr("*-+", T(t->text)[t->dle]) && isspace(T(t->text)[t->dle+1]) ) { @@ -532,7 +531,7 @@ islist(Line *t, int *clip, mkd_flag_t flags, int *list_type) if ( (j = nextblank(t,t->dle)) > t->dle ) { if ( T(t->text)[j-1] == '.' ) { - if ( !(is_flag_set(flags, MKD_NOALPHALIST) || is_flag_set(flags, MKD_STRICT)) + if ( !is_flag_set(flags, MKD_NOALPHALIST) && (j == t->dle + 2) && isalpha(T(t->text)[t->dle]) ) { j = nextnonblank(t,j); @@ -755,7 +754,7 @@ isdivmarker(Line *p, int start, mkd_flag_t flags) char *s; int last, i; - if ( is_flag_set(flags, MKD_NODIVQUOTE) || is_flag_set(flags, MKD_STRICT) ) + if ( is_flag_set(flags, MKD_NODIVQUOTE) ) return 0; start = nextnonblank(p, start); @@ -854,20 +853,17 @@ listitem(Paragraph *p, int indent, mkd_flag_t flags, linefn check) Line *t, *q; int clip = indent; int z; -#ifdef GITHUB_CHECKBOX int firstpara = 1; int ischeck; #define CHECK_NOT 0 #define CHECK_NO 1 #define CHECK_YES 2 -#endif for ( t = p->text; t ; t = q) { UNCHECK(t); __mkd_trim_line(t, clip); -#ifdef GITHUB_CHECKBOX - if ( firstpara ) { + if ( firstpara && !is_flag_set(flags, MKD_NORMAL_LISTITEM) ) { ischeck = CHECK_NOT; if ( strncmp(T(t->text)+t->dle, "[ ]", 3) == 0 ) ischeck = CHECK_NO; @@ -882,7 +878,6 @@ listitem(Paragraph *p, int indent, mkd_flag_t flags, linefn check) } firstpara = 0; } -#endif /* even though we had to trim a long leader off this item, * the indent for trailing paragraphs is still 4... @@ -1268,7 +1263,7 @@ actually_a_table(MMIOT *f, Line *pp) int c; /* tables need to be turned on */ - if ( is_flag_set(f->flags, MKD_STRICT) || is_flag_set(f->flags, MKD_NOTABLES) ) + if ( is_flag_set(f->flags, MKD_NOTABLES) ) return 0; /* tables need three lines */ diff --git a/markdown.h b/markdown.h index 5cb897f..438a489 100644 --- a/markdown.h +++ b/markdown.h @@ -55,11 +55,9 @@ typedef struct paragraph { HDR, HR, TABLE, SOURCE } typ; enum { IMPLICIT=0, PARA, CENTER} align; int hnumber; /* for typ == HDR */ -#if GITHUB_CHECKBOX int flags; #define GITHUB_CHECK 0x01 #define IS_CHECKED 0x02 -#endif } Paragraph; enum { ETX, SETEXT }; /* header types */ @@ -135,7 +133,7 @@ typedef struct mmiot { #define MKD_NOIMAGE 0x00000002 #define MKD_NOPANTS 0x00000004 #define MKD_NOHTML 0x00000008 -#define MKD_STRICT 0x00000010 +#define MKD_NORMAL_LISTITEM 0x00000010 #define MKD_TAGTEXT 0x00000020 #define MKD_NO_EXT 0x00000040 #define MKD_CDATA 0x00000080 @@ -151,10 +149,9 @@ typedef struct mmiot { #define MKD_TABSTOP 0x00020000 #define MKD_NODIVQUOTE 0x00040000 #define MKD_NOALPHALIST 0x00080000 -#define MKD_NODLIST 0x00100000 #define MKD_EXTRA_FOOTNOTE 0x00200000 #define MKD_NOSTYLE 0x00400000 -#define MKD_NODLDISCOUNT 0x00800000 +#define MKD_DLDISCOUNT 0x00800000 #define MKD_DLEXTRA 0x01000000 #define MKD_FENCEDCODE 0x02000000 #define MKD_IDANCHOR 0x04000000 @@ -166,6 +163,13 @@ typedef struct mmiot { #define USER_FLAGS 0xFFFFFFFF #define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP) +/* composite flags */ +#define MKD_DLIST MKD_DLDISCOUNT|MKD_DLEXTRA +#define MKD_STRICT MKD_NOSUPERSCRIPT|MKD_NORELAXED|MKD_NOSTRIKETHROUGH| \ + MKD_NOHEADER|MKD_NOALPHALIST|MKD_NODIVQUOTE| \ + MKD_NOTABLES|MKD_NO_EXT|MKD_NOSTYLE|MKD_NORMAL_LISTITEM| \ + MKD_TABSTOP + Callback_data *cb; } MMIOT; diff --git a/mkdio.c b/mkdio.c index 78e18fe..6bdcbdf 100644 --- a/mkdio.c +++ b/mkdio.c @@ -128,7 +128,7 @@ populate(getc_func getc, void* ctx, mkd_flag_t flags) DELETE(line); - if ( (pandoc == 3) && !(is_flag_set(flags, MKD_NOHEADER) || is_flag_set(flags, MKD_STRICT)) ) { + if ( (pandoc == 3) && !is_flag_set(flags, MKD_NOHEADER) ) { /* the first three lines started with %, so we have a header. * clip the first three lines out of content and hang them * off header. diff --git a/mkdio.h.in b/mkdio.h.in index 251437c..7a9a581 100644 --- a/mkdio.h.in +++ b/mkdio.h.in @@ -87,7 +87,7 @@ void mkd_ref_prefix(MMIOT*, char*); #define MKD_NOIMAGE 0x00000002 /* don't do image processing, block */ #define MKD_NOPANTS 0x00000004 /* don't run smartypants() */ #define MKD_NOHTML 0x00000008 /* don't allow raw html through AT ALL */ -#define MKD_STRICT 0x00000010 /* disable SUPERSCRIPT, RELAXED_EMPHASIS */ +#define MKD_NORMAL_LISTITEM 0x00000010 /* disable github-style checkbox lists */ #define MKD_TAGTEXT 0x00000020 /* process text inside an html tag; no * , no , no html or [] expansion */ #define MKD_NO_EXT 0x00000040 /* don't allow pseudo-protocols */ @@ -105,10 +105,9 @@ void mkd_ref_prefix(MMIOT*, char*); #define MKD_TABSTOP 0x00020000 /* expand tabs to 4 spaces */ #define MKD_NODIVQUOTE 0x00040000 /* forbid >%class% blocks */ #define MKD_NOALPHALIST 0x00080000 /* forbid alphabetic lists */ -#define MKD_NODLIST 0x00100000 /* forbid definition lists */ #define MKD_EXTRA_FOOTNOTE 0x00200000 /* enable markdown extra-style footnotes */ #define MKD_NOSTYLE 0x00400000 /* don't extract