diff --git a/generate.c b/generate.c index eded9c7..e8f8ffc 100644 --- a/generate.c +++ b/generate.c @@ -602,16 +602,19 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref) if ( image ) tag = &imaget; - else if ( (f->flags & NO_PSEUDO_PROTO) || (tag = pseudo(ref->link)) == 0 ) { + else if ( tag = pseudo(ref->link) ) { + if ( f->flags & (NO_PSEUDO_PROTO|SAFELINK) ) + return 0; + } + else if ( (f->flags & SAFELINK) && T(ref->link) + && (T(ref->link)[0] != '/') + && !isautoprefix(T(ref->link)) ) /* if SAFELINK, only accept links that are local or * a well-known protocol */ - if ( (f->flags & SAFELINK) && T(ref->link) - && (T(ref->link)[0] != '/') - && !isautoprefix(T(ref->link)) ) return 0; + else tag = &linkt; - } if ( f->flags & tag->flags ) return 0; diff --git a/main.c b/main.c index ce98ffd..8d91f31 100644 --- a/main.c +++ b/main.c @@ -48,6 +48,7 @@ static struct { { "strict", 0, MKD_STRICT }, { "header", 1, MKD_NOHEADER }, { "html", 1, MKD_NOHTML }, + { "ext", 1, MKD_NO_EXT }, { "cdata", 0, MKD_CDATA }, { "pants", 1, MKD_NOPANTS }, { "smarty", 1, MKD_NOPANTS }, diff --git a/tests/autolink.t b/tests/autolink.t index acf1f27..f1cb56f 100644 --- a/tests/autolink.t +++ b/tests/autolink.t @@ -2,7 +2,7 @@ rc=0 try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/automatic.t b/tests/automatic.t index a5b9ccc..89c3e6a 100644 --- a/tests/automatic.t +++ b/tests/automatic.t @@ -4,7 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/backslash.t b/tests/backslash.t index 9621cf5..8fde539 100644 --- a/tests/backslash.t +++ b/tests/backslash.t @@ -4,7 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/code.t b/tests/code.t index 49dc5dd..ed460f9 100644 --- a/tests/code.t +++ b/tests/code.t @@ -4,6 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/flow.t b/tests/flow.t index f352524..3541727 100644 --- a/tests/flow.t +++ b/tests/flow.t @@ -4,6 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/header.t b/tests/header.t index 77d7d33..6c24a1a 100644 --- a/tests/header.t +++ b/tests/header.t @@ -4,7 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/linkylinky.t b/tests/linkylinky.t index aee53d0..07d77c8 100644 --- a/tests/linkylinky.t +++ b/tests/linkylinky.t @@ -4,7 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/misc.t b/tests/misc.t index b28d040..e437a87 100644 --- a/tests/misc.t +++ b/tests/misc.t @@ -4,6 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/pandoc.t b/tests/pandoc.t index 51b6e97..9c1e7fb 100644 --- a/tests/pandoc.t +++ b/tests/pandoc.t @@ -3,94 +3,72 @@ rc=0 MARKDOWN_FLAGS= +try() { + unset FLAGS + case "$1" in + -*) FLAGS=$1 + shift ;; + esac + + ./echo -n " $1" '..................................' | ./cols 36 + + Q=`./echo "$2" | ./markdown $FLAGS` + + + if [ "$3" = "$Q" ]; then + ./echo " ok" + else + ./echo " FAILED" + ./echo "wanted: $3" + ./echo "got : $Q" + rc=1 + fi +} + + +HEADER='% title +% author(s) +% date' + + if ./markdown -V | grep HEADER > /dev/null; then - ./echo -n ' valid header ..................... ' - TEXT='% title + try 'valid header' "$HEADER" '' + try -F0x0100 'valid header with -F0x0100' "$HEADER" '

% title % author(s) -% date -' - count=`./echo "$TEXT" | ./markdown | grep title | wc -l` +% date

' - if [ "$count" -eq 0 ]; then - ./echo "ok" - else - ./echo "FAILED" - rc=1 - fi - - ./echo -n ' valid header with -F0x0100........ ' - TEXT='% title + try 'invalid header' \ + '% title % author(s) -% date -' - count=`./echo "$TEXT" | ./markdown -F0x0100 | grep title | wc -l` - - if [ "$count" -gt 0 ]; then - ./echo "ok" - else - ./echo "FAILED" - rc=1 - fi - - ./echo -n ' invalid header ................... ' - TEXT='% title +a pony!' \ + '

% title % author(s) -a pony!' +a pony!

' - count=`./echo "$TEXT" | ./markdown | grep title | wc -l` - - if [ "$count" -gt 0 ]; then - ./echo "ok" - else - ./echo "FAILED" - rc=1 - fi - - ./echo -n ' offset header .................... ' - TEXT=' + try 'offset header' \ + ' % title % author(s) -% date -content' - - count=`./echo "$TEXT" | ./markdown | grep title | wc -l` - - if [ "$count" -gt 0 ]; then - ./echo "ok" - else - ./echo "FAILED" - rc=1 - fi - - ./echo -n ' indented header .................. ' - TEXT=' % title - % author(s) - % date -content' - - count=`./echo "$TEXT" | ./markdown | grep title | wc -l` - - if [ "$count" -gt 0 ]; then - ./echo "ok" - else - ./echo "FAILED" - rc=1 - fi -else - ./echo -n ' ignore headers ................... ' - TEXT='% title +% date' \ + '

% title % author(s) -% date -' - count=`./echo "$TEXT" | ./markdown | grep title | wc -l` +% date

' + + try 'indented header' \ + ' % title +% author(s) +% date' \ + '

% title +% author(s) +% date

' + +else + + try 'ignore headers' "$HEADER" '

% title +% author(s) +% date

' - if [ "$count" -gt 0 ]; then - ./echo "ok" - else - ./echo "FAILED" - rc=1 - fi fi exit $rc diff --git a/tests/para.t b/tests/para.t index 6fbaa66..d867454 100644 --- a/tests/para.t +++ b/tests/para.t @@ -4,6 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/paranoia.t b/tests/paranoia.t index 2312dac..f2b1024 100644 --- a/tests/paranoia.t +++ b/tests/paranoia.t @@ -3,30 +3,29 @@ rc=0 MARKDOWN_FLAGS= -./echo -n ' bogus url (-fsafelink) ........... ' +try() { + unset FLAGS + case "$1" in + -*) FLAGS=$1 + shift ;; + esac + + ./echo -n " $1" '..................................' | ./cols 36 -TRICK='[test](bad:protocol)' + Q=`./echo "$2" | ./markdown $FLAGS` -count=`./echo "$TRICK" | ./markdown -fsafelink | grep '[test](bad:protocol)

' +try -fnosafelink 'bogus url (-fnosafelink)' '[test](bad:protocol)' '

test

' exit $rc diff --git a/tests/pseudo.t b/tests/pseudo.t index 8e165cc..e2d8b76 100644 --- a/tests/pseudo.t +++ b/tests/pseudo.t @@ -3,74 +3,33 @@ rc=0 MARKDOWN_FLAGS= -./echo -n ' [](id:) links .................... ' +try() { + unset FLAGS + case "$1" in + -*) FLAGS=$1 + shift ;; + esac + + ./echo -n " $1" '..................................' | ./cols 36 -ASK=`./echo '[foo](id:bar)' | ./markdown` -if ./echo "$ASK" | grep 'foo' >/dev/null; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi + Q=`./echo "$2" | ./markdown $FLAGS` -./echo -n ' [](id:) links with MKD_NO_EXT .... ' -ASK=`./echo '[foo](id:bar)' | MARKDOWN_FLAGS=0x0040 ./markdown` -if ./echo "$ASK" | grep 'foo' >/dev/null; then - ./echo "FAILED" - rc=1 -else - ./echo "ok" -fi + if [ "$3" = "$Q" ]; then + ./echo " ok" + else + ./echo " FAILED" + ./echo "wanted: $3" + ./echo "got : $Q" + rc=1 + fi +} -./echo -n ' [](class:) links ................. ' - -ASK=`./echo '[foo](class:bar)' | ./markdown` - -if ./echo "$ASK" | grep 'foo' >/dev/null; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' [](class:) links with MKD_NO_EXT . ' - -ASK=`./echo '[foo](class:bar)' | MARKDOWN_FLAGS=0x0040 ./markdown` - -if ./echo "$ASK" | grep 'foo' >/dev/null; then - ./echo "FAILED" - rc=1 -else - ./echo "ok" -fi - -./echo -n ' [](raw:) links ................... ' - -ASK=`./echo '[foo](raw:bar)' | ./markdown` - -count1=`./echo "$ASK" | grep foo | wc -l` -count2=`./echo "$ASK" | grep bar | wc -l` - -if [ "$count1" -eq 0 -a "$count2" -eq 1 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' [](raw:) links with MKD_NO_EXT ... ' - -ASK=`./echo '[foo](raw:bar)' | MARKDOWN_FLAGS=0x0040 ./markdown` - -count1=`./echo "$ASK" | grep 'raw:bar' | wc -l` -count2=`./echo "$ASK" | grep 'a href' | wc -l` - -if [ \( "$count1" -gt 0 \) -a \( "$count2" -gt 0 \) ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi +try '[](id:) links' '[foo](id:bar)' '

foo

' +try -fnoext '[](id:) links with -fnoext' '[foo](id:bar)' '

[foo](id:bar)

' +try '[](class:) links' '[foo](class:bar)' '

foo

' +try -fnoext '[](class:) links with -fnoext' '[foo](class:bar)' '

[foo](class:bar)

' +try '[](raw:) links' '[foo](raw:bar)' '

bar

' +try -fnoext '[](raw:) links with -fnoext' '[foo](raw:bar)' '

[foo](raw:bar)

' exit $rc diff --git a/tests/reparse.t b/tests/reparse.t index c3381d2..b6bebd8 100644 --- a/tests/reparse.t +++ b/tests/reparse.t @@ -3,7 +3,7 @@ rc=0 try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/schiraldi.t b/tests/schiraldi.t index c2e1457..5f519a9 100644 --- a/tests/schiraldi.t +++ b/tests/schiraldi.t @@ -4,7 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;; diff --git a/tests/smarty.t b/tests/smarty.t index 4d44d05..e3e6e34 100644 --- a/tests/smarty.t +++ b/tests/smarty.t @@ -4,6 +4,7 @@ rc=0 MARKDOWN_FLAGS=0x0; export MARKDOWN_FLAGS try() { + unset FLAGS case "$1" in -*) FLAGS="$1" shift ;; diff --git a/tests/snakepit.t b/tests/snakepit.t index d6fdcb0..d1f4055 100644 --- a/tests/snakepit.t +++ b/tests/snakepit.t @@ -4,7 +4,7 @@ rc=0 MARKDOWN_FLAGS= try() { - + unset FLAGS case "$1" in -*) FLAGS=$1 shift ;;