1. If a full tick match isn't found, choose the closest

substring match.
2. Move code test cases to code.t
3. Add new code test cases to check that the code handler
   works like the standard does.
This commit is contained in:
David Parsons
2010-03-06 15:07:46 -08:00
parent b238e8e3c3
commit 1f7b8057df
3 changed files with 21 additions and 10 deletions
+16 -6
View File
@@ -21,7 +21,7 @@ typedef int (*stfu)(const void*,const void*);
/* forward declarations */
static int matchticks(MMIOT*, int);
static int matchticks(MMIOT*, int*);
static void codeblock(MMIOT*);
static void codespan(MMIOT*, int);
static int nrticks(int, MMIOT*);
@@ -1071,7 +1071,7 @@ text(MMIOT *f)
else {
int size, tick = nrticks(0, f);
if ( size = matchticks(f, tick) ) {
if ( size = matchticks(f, &tick) ) {
shift(f, tick);
codespan(f, size-tick);
shift(f, size-1);
@@ -1126,19 +1126,29 @@ text(MMIOT *f)
static int
matchticks(MMIOT *f, int escape)
matchticks(MMIOT *f, int *escape)
{
int size, tick, c;
int subsize=0, subtick=0;
for (size = escape; (c=peek(f,size)) != EOF; ) {
for (size = *escape; (c=peek(f,size)) != EOF; ) {
if ( c == '`' )
if ( (tick=nrticks(size,f)) == escape )
if ( (tick=nrticks(size,f)) == *escape )
return size;
else
else {
if ( !subsize ) {
subsize = size;
subtick = tick;
}
size += tick;
}
else
size++;
}
if ( subsize ) {
*escape = subtick;
return subsize;
}
return 0;
} /* matchticks */
+5
View File
@@ -15,6 +15,11 @@ code
try 'unclosed single backtick' '`hi there' '<p>`hi there</p>'
try 'unclosed double backtick' '``hi there' '<p>``hi there</p>'
try 'remove space around code' '`` hi there ``' '<p><code>hi there</code></p>'
try '`` a```b ``' '`` a```b ``' '<p><code>a```b</code></p>'
try '`a\`' '`a\`' '<p><code>a\</code></p>'
try '`>`' '`>`' '<p><code>&gt;</code></p>'
try '`` ` ``' '`` ` ``' '<p><code>`</code></p>'
try '````` ``` `' '````` ``` `' '<p><code>``</code> `</p>'
summary $0
exit $rc
-4
View File
@@ -7,10 +7,6 @@ MARKDOWN_FLAGS=
try 'single paragraph' 'AAA' '<p>AAA</p>'
try '< -> &lt;' '<' '<p>&lt;</p>'
try '`>` -> <code>&gt;</code>' '`>`' '<p><code>&gt;</code></p>'
try '`` ` `` -> <code>`</code>' '`` ` ``' '<p><code>`</code></p>'
try '`` a```b ``' '`` a```b ``' '<p><code>a```b</code></p>'
try '`a^A` -> <code>a^A</code>' '`a^A`' '<p><code>a^A</code></p>'
summary $0
exit $rc