mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
1. Add the flag MKD_STRICT, which disables any configured superscripting
of A^B and non-emphasis on A_B. 2. markdown(1) now has the `strict` (enable `MKD_STRICT`) and `relax` (disable `MKD_STRICT`) flags. 3. truncate the input buffer at the end of every call to `text()` (corrects defect with --relaxed-emphasis where it was incorrectly looking back past the start of the input and triggering on the contents of the previous input (not reliably, so only detected when I put MKD_STRICT into the code.) 4. `markdown.1` manpage renamed to `markdown.1.in` and processed according to whether --relaxed-emphasis and/or --with-superscript are configured.
This commit is contained in:
+7
-4
@@ -106,7 +106,7 @@ AC_DEFINE 'TABSTOP' $TABSTOP
|
||||
AC_SUB 'TABSTOP' $TABSTOP
|
||||
|
||||
test -z "$WITH_SUPERSCRIPT" || AC_DEFINE 'SUPERSCRIPT' 1
|
||||
|
||||
test -z "$RELAXED_EMPHASIS" || AC_DEFINE 'RELAXED_EMPHASIS' 1
|
||||
|
||||
|
||||
if [ "$WITH_AMALLOC" ]; then
|
||||
@@ -116,13 +116,16 @@ else
|
||||
AC_SUB 'AMALLOC' ''
|
||||
fi
|
||||
|
||||
if [ "$RELAXED_EMPHASIS" ]; then
|
||||
AC_DEFINE 'RELAXED_EMPHASIS' 1
|
||||
if [ "$RELAXED_EMPHASIS" -o "$WITH_SUPERSCRIPT" ]; then
|
||||
AC_SUB 'STRICT' ''
|
||||
else
|
||||
AC_SUB 'STRICT' '.\"'
|
||||
fi
|
||||
|
||||
|
||||
[ "$OS_FREEBSD" -o "$OS_DRAGONFLY" ] || AC_CHECK_HEADERS malloc.h
|
||||
|
||||
[ "$WITH_DL_TAG" ] && AC_DEFINE 'DL_TAG_EXTENSION' '1'
|
||||
[ "$WITH_PANDOC_HEADER" ] && AC_DEFINE 'PANDOC_HEADER' '1'
|
||||
|
||||
AC_OUTPUT Makefile version.c
|
||||
AC_OUTPUT Makefile version.c markdown.1
|
||||
|
||||
+37
-26
@@ -74,6 +74,31 @@ cursor(MMIOT *f)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
isthisspace(MMIOT *f, int i)
|
||||
{
|
||||
int c = peek(f, i);
|
||||
|
||||
return isspace(c) || (c == EOF);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
isthisalnum(MMIOT *f, int i)
|
||||
{
|
||||
int c = peek(f, i);
|
||||
|
||||
return (c != EOF) && isalnum(c);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
isthisnonword(MMIOT *f, int i)
|
||||
{
|
||||
return isthisspace(f, i) || ispunct(peek(f,i));
|
||||
}
|
||||
|
||||
|
||||
/* return/set the current cursor position
|
||||
*/
|
||||
#define mmiotseek(f,x) (f->isp = x)
|
||||
@@ -662,11 +687,11 @@ forbidden_tag(MMIOT *f)
|
||||
if ( f->flags & DENY_HTML )
|
||||
return 1;
|
||||
|
||||
if ( c == 'A' && (f->flags & DENY_A) && !isalnum(peek(f,2)) )
|
||||
if ( c == 'A' && (f->flags & DENY_A) && !isthisalnum(f,2) )
|
||||
return 1;
|
||||
if ( c == 'I' && (f->flags & DENY_IMG)
|
||||
&& strncasecmp(cursor(f)+1, "MG", 2) == 0
|
||||
&& !isalnum(peek(f,4)) )
|
||||
&& !isthisalnum(f,4) )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -746,22 +771,6 @@ maybe_tag_or_link(MMIOT *f)
|
||||
} /* maybe_tag_or_link */
|
||||
|
||||
|
||||
static int
|
||||
isthisspace(MMIOT *f, int i)
|
||||
{
|
||||
int c = peek(f, i);
|
||||
|
||||
return isspace(c) || (c == EOF);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
isthisnonword(MMIOT *f, int i)
|
||||
{
|
||||
return isthisspace(f, i) || ispunct(peek(f,i));
|
||||
}
|
||||
|
||||
|
||||
/* smartyquote code that's common for single and double quotes
|
||||
*/
|
||||
static int
|
||||
@@ -929,7 +938,8 @@ text(MMIOT *f)
|
||||
Qchar(c, f);
|
||||
break;
|
||||
#if SUPERSCRIPT
|
||||
case '^': if ( isthisspace(f,-1) || isthisspace(f,1) )
|
||||
/* A^B -> A<sup>B</sup> */
|
||||
case '^': if ( (f->flags & STRICT) || isthisspace(f,-1) || isthisspace(f,1) )
|
||||
Qchar(c,f);
|
||||
else {
|
||||
char *sup = cursor(f);
|
||||
@@ -944,13 +954,12 @@ text(MMIOT *f)
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case '_':
|
||||
#if RELAXED_EMPHASIS
|
||||
/* If RELAXED_EMPHASIS, underscores don't count when
|
||||
* they're in the middle of a word.
|
||||
*/
|
||||
if ( (isthisspace(f,-1) && isthisspace(f,1))
|
||||
|| (isalnum(peek(f,-1)) && isalnum(peek(f,1))) ) {
|
||||
/* Underscores don't count if they're in the middle of a word */
|
||||
case '_':
|
||||
if ( (!(f->flags & STRICT))
|
||||
&& ((isthisspace(f,-1) && isthisspace(f,1))
|
||||
|| (isthisalnum(f,-1) && isthisalnum(f,1))) ){
|
||||
Qchar(c, f);
|
||||
break;
|
||||
}
|
||||
@@ -1004,7 +1013,7 @@ text(MMIOT *f)
|
||||
break;
|
||||
|
||||
case '&': j = (peek(f,1) == '#' ) ? 2 : 1;
|
||||
while ( isalnum(peek(f,j)) )
|
||||
while ( isthisalnum(f,j) )
|
||||
++j;
|
||||
|
||||
if ( peek(f,j) != ';' )
|
||||
@@ -1017,6 +1026,8 @@ text(MMIOT *f)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* truncate the input string after we've finished processing it */
|
||||
S(f->in) = f->isp = 0;
|
||||
} /* text */
|
||||
|
||||
|
||||
|
||||
@@ -41,12 +41,14 @@ static struct {
|
||||
int off;
|
||||
int flag;
|
||||
} opts[] = {
|
||||
{ "tabstop", 0, MKD_TABSTOP },
|
||||
{ "image", 1, MKD_NOIMAGE },
|
||||
{ "links", 1, MKD_NOLINKS },
|
||||
{ "tabstop", 0, MKD_TABSTOP },
|
||||
{ "image", 1, MKD_NOIMAGE },
|
||||
{ "links", 1, MKD_NOLINKS },
|
||||
{ "relax", 1, MKD_STRICT },
|
||||
{ "strict", 0, MKD_STRICT },
|
||||
{ "header", 1, MKD_NOHEADER },
|
||||
{ "html", 1, MKD_NOHTML },
|
||||
{ "cdata", 0, MKD_CDATA },
|
||||
{ "html", 1, MKD_NOHTML },
|
||||
{ "cdata", 0, MKD_CDATA },
|
||||
} ;
|
||||
|
||||
#define NR(x) (sizeof x / sizeof x[0])
|
||||
@@ -138,7 +140,6 @@ main(int argc, char **argv)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
||||
if ( text ) {
|
||||
rc = mkd_text( text, strlen(text), stdout, flags);
|
||||
adump();
|
||||
|
||||
@@ -50,6 +50,10 @@ Generate valid XML output.
|
||||
Do not process pandoc headers.
|
||||
.It Ar tabstops
|
||||
Use markdown-standard 4-space tabstops.
|
||||
@STRICT@.It Ar strict
|
||||
@STRICT@Disable superscript and relaxed emphasis.
|
||||
@STRICT@.It Ar relax
|
||||
@STRICT@Enable superscript and relaxed emphasis (this is the default.)
|
||||
.El
|
||||
.Pp
|
||||
As an example, the option
|
||||
@@ -68,6 +68,7 @@ typedef struct mmiot {
|
||||
#define DENY_IMG 0x0002
|
||||
#define DENY_SMARTY 0x0004
|
||||
#define DENY_HTML 0x0008
|
||||
#define STRICT 0x0010
|
||||
#define INSIDE_TAG 0x0020
|
||||
#define NO_PSEUDO_PROTO 0x0040
|
||||
#define CDATA_OUTPUT 0x0080
|
||||
|
||||
@@ -46,6 +46,7 @@ extern char markdown_version[];
|
||||
#define MKD_NOIMAGE 0x0002 /* don't do image processing, block <img> */
|
||||
#define MKD_NOPANTS 0x0004 /* don't run smartypants() */
|
||||
#define MKD_NOHTML 0x0008 /* don't allow raw html through AT ALL */
|
||||
#define MKD_STRICT 0x0010 /* disable SUPERSCRIPT, RELAXED_EMPHASIS */
|
||||
#define MKD_TAGTEXT 0x0020 /* don't expand `_` and `*` */
|
||||
#define MKD_NO_EXT 0x0040 /* don't allow pseudo-protocols */
|
||||
#define MKD_CDATA 0x0080 /* generate code for xml ![CDATA[...]] */
|
||||
@@ -56,4 +57,5 @@ extern char markdown_version[];
|
||||
#define MKD_NOHEADER 0x0100 /* don't process header blocks */
|
||||
#define MKD_TABSTOP 0x0200 /* expand tabs to 4 spaces */
|
||||
|
||||
|
||||
#endif/*_MKDIO_D*/
|
||||
|
||||
+9
-8
@@ -58,23 +58,24 @@ else
|
||||
rc=1
|
||||
fi
|
||||
|
||||
./echo -n ' A_B .............................. '
|
||||
case "$MARKDOWN_VERSION" in
|
||||
*RELAXED*)
|
||||
if ./echo '_A_B' | ./markdown | grep -i 'A_B' > /dev/null; then
|
||||
if ./markdown -V | grep RELAXED >/dev/null; then
|
||||
./echo -n ' _A_B with -frelax ................ '
|
||||
|
||||
if ./echo '_A_B' | ./markdown -frelax | grep -i 'A_B' > /dev/null; then
|
||||
./echo "ok"
|
||||
else
|
||||
./echo "FAILED"
|
||||
rc=1
|
||||
fi
|
||||
;;
|
||||
*) if ./echo '_A_B' | ./markdown | grep -i 'A</em>B' > /dev/null; then
|
||||
|
||||
./echo -n ' _A_B with -fstrict ............... '
|
||||
|
||||
if ./echo '_A_B' | ./markdown -fstrict | grep -i 'A</em>B' > /dev/null; then
|
||||
./echo "ok"
|
||||
else
|
||||
./echo "FAILED"
|
||||
rc=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
exit $rc
|
||||
|
||||
+9
-2
@@ -114,13 +114,20 @@ else
|
||||
fi
|
||||
|
||||
if ./markdown -V | grep SUPERSCRIPT >/dev/null; then
|
||||
./echo -n " A^B -> A<sup>B</sup> ............. "
|
||||
if ./echo "A^B" | ./markdown | grep '<sup>B</sup>' >/dev/null; then
|
||||
./echo -n " A^B -> A<sup>B</sup> (-frelax) ... "
|
||||
if ./echo "A^B" | ./markdown -frelax | grep '<sup>B</sup>' >/dev/null; then
|
||||
./echo "ok"
|
||||
else
|
||||
./echo "FAILED"
|
||||
rc=1
|
||||
fi
|
||||
./echo -n " A^B != A<sup>B</sup> (-fstrict) .. "
|
||||
if ./echo "A^B" | ./markdown -fstrict | grep '<sup>B</sup>' >/dev/null; then
|
||||
./echo "FAILED"
|
||||
rc=1
|
||||
else
|
||||
./echo "ok"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $rc
|
||||
|
||||
+3
-3
@@ -10,12 +10,12 @@ char markdown_version[] = VERSION
|
||||
#if @TABSTOP@ != 4
|
||||
" TAB=@TABSTOP@"
|
||||
#endif
|
||||
#if SUPERSCRIPT
|
||||
" SUPERSCRIPT"
|
||||
#endif
|
||||
#if USE_AMALLOC
|
||||
" DEBUG"
|
||||
#endif
|
||||
#if SUPERSCRIPT
|
||||
" SUPERSCRIPT"
|
||||
#endif
|
||||
#if RELAXED_EMPHASIS
|
||||
" RELAXED"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user