Skip to content
Browse files

Revert "Up to version 1.2.8 ( --relaxed-emphasis, atx header pruning,…

… -nohtml)"

(drop missing changes from pell?)

This reverts commit 7d414e7.
  • Loading branch information...
1 parent 7d414e7 commit ca7c57333c031640e7a3854ea1e44ccf199591dd David Parsons committed Aug 22, 2008
Showing with 136 additions and 50 deletions.
  1. +1 −0 INSTALL
  2. +4 −4 README
  3. +9 −1 configure.sh
  4. +16 −17 generate.c
  5. +36 −25 main.c
  6. +4 −0 markdown.1
  7. +4 −1 markdown.c
  8. +1 −0 markdown.h
  9. +12 −1 mkd-extensions.7
  10. +3 −1 mkdio.c
  11. +1 −0 mkdio.h
  12. +20 −0 tests/emphasis.t
  13. +22 −0 tests/html.t
  14. +3 −0 version.c.in
View
1 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 A<sup>B</sup>
--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
View
8 README
@@ -5,10 +5,10 @@ language as described in
and passes the Markdown test suite at
<http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip>
-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.
-
+DISCOUNT is free software written by David Parsons <orc@pell.chi.il.us>;
+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.
View
10 configure.sh
@@ -7,10 +7,11 @@
# load in the configuration file
#
-ac_help='--enable-dl-tag Use the DL tag extension
+ac_help='--enable-dl-tag Use the DL tag extension
--enable-pandoc-header Use pandoc-style header blocks
--enable-superscript A^B becomes A<sup>B</sup>
--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'
View
33 generate.c
@@ -642,11 +642,11 @@ cputc(int c, MMIOT *f)
* convert an email address to a string of nonsense
*/
static void
-mangle(unsigned char *s, int len, MMIOT *f)
+mangle(char *s, int len, MMIOT *f)
{
while ( len-- > 0 ) {
Qstring("&#", f);
- Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *s++);
+ Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
}
}
@@ -659,6 +659,9 @@ forbidden_tag(MMIOT *f)
{
int c = toupper(peek(f, 1));
+ if ( f->flags & DENY_HTML )
+ return 1;
+
if ( c == 'A' && (f->flags & DENY_A) && !isalnum(peek(f,2)) )
return 1;
if ( c == 'I' && (f->flags & DENY_IMG)
@@ -941,29 +944,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) )
View
61 main.c
@@ -36,47 +36,58 @@ basename(char *p)
char *pgm = "markdown";
+static struct {
+ char *name;
+ int off;
+ int flag;
+} opts[] = {
+ { "tabstop", 0, MKD_TABSTOP },
+ { "image", 1, MKD_NOIMAGE },
+ { "links", 1, MKD_NOLINKS },
+ { "header", 1, MKD_NOHEADER },
+ { "html", 1, MKD_NOHTML },
+ { "cdata", 0, MKD_CDATA },
+} ;
+
+#define NR(x) (sizeof x / sizeof x[0])
+
+
void
set(int *flags, char *optionstring)
{
- char wtd;
- int opt;
+ int i;
+ int enable;
char *arg;
for ( arg = strtok(optionstring, ","); arg; arg = strtok(NULL, ",") ) {
if ( *arg == '+' || *arg == '-' )
- wtd = *arg++;
+ enable = (*arg++ == '+') ? 1 : 0;
else if ( strncasecmp(arg, "no", 2) == 0 ) {
arg += 2;
- wtd = '-';
+ enable = 0;
}
else
- wtd = '+';
-
- if ( strcasecmp(arg, "tabstop") == 0 )
- opt = MKD_TABSTOP;
- else if ( strcasecmp(arg, "noimage") == 0 )
- opt = MKD_NOIMAGE;
- else if ( strcasecmp(arg, "nolinks") == 0 )
- opt = MKD_NOLINKS;
- else if ( strcasecmp(arg, "noheader") == 0 )
- opt = MKD_NOHEADER;
- else if ( strcasecmp(arg, "tag") == 0 )
- opt = MKD_TAGTEXT;
- else if ( strcasecmp(arg, "cdata") == 0 )
- opt = MKD_CDATA;
- else {
- fprintf(stderr, "%s: unknown option <%s>\n", pgm, arg);
- continue;
+ enable = 1;
+
+ for ( i=0; i < NR(opts); i++ )
+ if ( strcasecmp(arg, opts[i].name) == 0 )
+ break;
+
+ if ( i < NR(opts) ) {
+ if ( opts[i].off )
+ enable = !enable;
+
+ if ( enable )
+ *flags |= opts[i].flag;
+ else
+ *flags &= ~opts[i].flag;
}
-
- if ( wtd == '+' )
- *flags |= opt;
else
- *flags &= ~opt;
+ fprintf(stderr, "%s: unknown option <%s>\n", pgm, arg);
}
}
+
float
main(int argc, char **argv)
{
View
4 markdown.1
@@ -40,6 +40,10 @@ are in a comma-delimited list, with an optional
Don't allow image tags.
.It Ar nolinks
Don't allow links.
+.It Ar nohtml
+Don't allow
+.B any
+embedded html.
.It Ar cdata
Generate valid XML output.
.It Ar noheader
View
5 markdown.c
@@ -411,6 +411,9 @@ headerblock(Paragraph *pp, int htyp)
pp->hnumber = i;
+ while ( (i < S(p->text)) && isspace(T(p->text)[i]) )
+ ++i;
+
CLIP(p->text, 0, i);
for (j=S(p->text); j && (T(p->text)[j-1] == '#'); --j)
@@ -762,7 +765,7 @@ compile(Line *ptr, int toplevel, MMIOT *f)
ptr = consume(ptr, &para);
while ( ptr ) {
- if ( toplevel && (key = isopentag(ptr)) ) {
+ if ( toplevel && !(f->flags & DENY_HTML) && (key = isopentag(ptr)) ) {
p = Pp(&d, ptr, strcmp(key, "STYLE") == 0 ? STYLE : HTML);
if ( strcmp(key, "!--") == 0 )
ptr = comment(p, key);
View
1 markdown.h
@@ -67,6 +67,7 @@ typedef struct mmiot {
#define DENY_A 0x0001
#define DENY_IMG 0x0002
#define DENY_SMARTY 0x0004
+#define DENY_HTML 0x0008
#define INSIDE_TAG 0x0020
#define NO_PSEUDO_PROTO 0x0040
#define CDATA_OUTPUT 0x0080
View
13 mkd-extensions.7
@@ -12,7 +12,8 @@ and borrowing markup from other markup languages.
.Ss Image dimensions
Markdown embedded images have been extended to allow specifying
the dimensions of the image by adding a new argument
-.Em =/height/x/width/ to the link description.
+.Em =/height/x/width/
+to the link description.
.Pp
The new image syntax is
.nf
@@ -90,6 +91,16 @@ a
.Pp
Be warned that style blocks work like footnote links -- no matter
where you define them they are valid for the entire document.
+.Ss relaxed emphasis
+If markdown was configured with
+.Ar --relaxed-emphasis ,
+the rules for emphasis are changed so that a single
+.Ar _
+will
+.Em not
+count as a emphasis character if it's in the middle of a word.
+This is primarily for documenting code, if you don't wish to
+have to backquote all code references.
.Sh AUTHOR
David Parsons
.%T http://www.pell.portland.or.us/~orc/
View
4 mkdio.c
@@ -41,7 +41,7 @@ queue(Document* a, Cstring *line)
unsigned char c;
int xp = 0;
int size = S(*line);
- unsigned char *str = T(*line);
+ unsigned char *str = (unsigned char*)T(*line);
CREATE(p->text);
ATTACH(a->content, p);
@@ -68,6 +68,7 @@ queue(Document* a, Cstring *line)
}
+#ifdef PANDOC_HEADER
/* trim leading blanks from a header line
*/
static void
@@ -76,6 +77,7 @@ snip(Line *p)
CLIP(p->text, 0, 1);
p->dle = mkd_firstnonblank(p);
}
+#endif
/* build a Document from any old input.
View
1 mkdio.h
@@ -45,6 +45,7 @@ extern char markdown_version[];
#define MKD_NOLINKS 0x0001 /* don't do link processing, block <a> tags */
#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_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[...]] */
View
20 tests/emphasis.t
@@ -2,6 +2,7 @@
rc=0
MARKDOWN_FLAGS=
+MARKDOWN_VERSION=`./markdown -V`
./echo -n ' *hi* -> <em>hi</em> .............. '
@@ -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 'A</em>B' > /dev/null; then
+ ./echo "ok"
+ else
+ ./echo "FAILED"
+ rc=1
+ fi
+ ;;
+esac
+
exit $rc
View
22 tests/html.t
@@ -93,4 +93,26 @@ else
rc=1
fi
+./echo -n ' block html with -fnohtml ......... '
+
+RSLT=`./echo "<b>hi!</b>" | ./markdown -fnohtml`
+
+if ./echo "$RSLT" | grep '<b>' >/dev/null; then
+ ./echo "FAILED"
+ rc=1
+else
+ ./echo "ok"
+fi
+
+./echo -n ' allow html with -fhtml ........... '
+
+RSLT=`./echo "<b>hi!</b>" | ./markdown -fhtml`
+
+if ./echo "$RSLT" | grep '<b>' >/dev/null; then
+ ./echo "ok"
+else
+ ./echo "FAILED"
+ rc=1
+fi
+
exit $rc
View
3 version.c.in
@@ -16,4 +16,7 @@ char markdown_version[] = VERSION
#if USE_AMALLOC
" DEBUG"
#endif
+#if RELAXED_EMPHASIS
+ " RELAXED"
+#endif
;

0 comments on commit ca7c573

Please sign in to comment.
Something went wrong with that request. Please try again.