diff --git a/INSTALL b/INSTALL index 3d1f8bd..c591387 100644 --- a/INSTALL +++ b/INSTALL @@ -30,6 +30,7 @@ Configure.sh has a few options that can be set: --enable-pandoc-header Use pandoc-style header blocks --enable-superscript A^B expands to AB --enable-amalloc Use a debugging memory allocator (to detect leaks) +--relaxed-emphasis Don't treat _ in the middle of a word as emphasis --with-tabstops=N Set tabstops to N characters (default is 4) 3) Installing sample programs and manpages diff --git a/README b/README index 1857bc8..96df998 100644 --- a/README +++ b/README @@ -9,7 +9,6 @@ DISCOUNT is free software; it is released under a BSD-style license that allows you to do as you wish with it as long as you don't attempt to claim it as your own work. - Most of the programs included in the DISCOUNT distribution have manual pages describing how they work. diff --git a/configure.sh b/configure.sh index e904828..b69b66b 100755 --- a/configure.sh +++ b/configure.sh @@ -11,6 +11,7 @@ ac_help='--enable-dl-tag Use the DL tag extension --enable-pandoc-header Use pandoc-style header blocks --enable-superscript A^B becomes AB --enable-amalloc Enable memory allocation debugging +--relaxed_emphasis underscores aren'\''t special in the middle of words --with-tabstops=N Set tabstops to N characters (default is 4)' LOCAL_AC_OPTIONS=' @@ -25,6 +26,9 @@ fi' locals() { K=`echo $1 | tr '[a-z]' '[A-Z]'` case "$K" in + --RELAXED_EMPHAS*) + echo RELAXED_EMPHASIS=T + ;; --ENABLE-*) enable=`echo $K | sed -e 's/--ENABLE-/WITH-/' | tr '-' '_'` echo ${enable}=T ;; @@ -112,6 +116,10 @@ else AC_SUB 'AMALLOC' '' fi +if [ "$RELAXED_EMPHASIS" ]; then + AC_DEFINE 'RELAXED_EMPHASIS' 1 +fi + [ "$OS_FREEBSD" -o "$OS_DRAGONFLY" ] || AC_CHECK_HEADERS malloc.h [ "$WITH_DL_TAG" ] && AC_DEFINE 'DL_TAG_EXTENSION' '1' diff --git a/generate.c b/generate.c index 7a85bd0..813e550 100644 --- a/generate.c +++ b/generate.c @@ -941,29 +941,25 @@ text(MMIOT *f) } break; #endif - case '*': - case '_': if ( tag_text(f) ) - Qchar(c, f); + case '_': #if RELAXED_EMPHASIS - else if ( peek(f,1) == c ) { - for ( rep = 1; peek(f,1) == c; pull(f) ) - ++rep; - - Qem(f, c, rep); - } - else if ( (isthisspace(f,-1) && isthisspace(f,1)) - || (isalnum(peek(f,-1)) && isalnum(peek(f,1))) ) + /* 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))) ) { Qchar(c, f); - else { - Qem(f, c, 1); + break; } -#else + /* else fall into the regular old emphasis case */ +#endif + case '*': if ( tag_text(f) ) + Qchar(c, f); else { for (rep = 1; peek(f,1) == c; pull(f) ) ++rep; Qem(f,c,rep); } -#endif break; case '`': if ( tag_text(f) ) diff --git a/tests/emphasis.t b/tests/emphasis.t index fa26c5c..99ef911 100644 --- a/tests/emphasis.t +++ b/tests/emphasis.t @@ -2,6 +2,7 @@ rc=0 MARKDOWN_FLAGS= +MARKDOWN_VERSION=`./markdown -V` ./echo -n ' *hi* -> hi .............. ' @@ -57,4 +58,23 @@ 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 + ./echo "ok" + else + ./echo "FAILED" + rc=1 + fi + ;; +*) if ./echo '_A_B' | ./markdown | grep -i 'AB' > /dev/null; then + ./echo "ok" + else + ./echo "FAILED" + rc=1 + fi + ;; +esac + exit $rc diff --git a/version.c.in b/version.c.in index 0f4b349..3bd4213 100644 --- a/version.c.in +++ b/version.c.in @@ -15,5 +15,8 @@ char markdown_version[] = VERSION #endif #if USE_AMALLOC " DEBUG" +#endif +#if RELAXED_EMPHASIS + " RELAXED" #endif ;