Fix escaping with surrounds
When we assigned stop = strstr(start, search), we'd grab the first match even if it was escaped. Instead, we update stop as we go.
This commit is contained in:
parent
1df23c3882
commit
b8bb25f4a7
2 changed files with 6 additions and 2 deletions
6
smu.c
6
smu.c
|
@ -449,10 +449,12 @@ dosurround(const char *begin, const char *end, int newblock) {
|
||||||
start = begin + l;
|
start = begin + l;
|
||||||
p = start - 1;
|
p = start - 1;
|
||||||
do {
|
do {
|
||||||
|
stop = p;
|
||||||
p = strstr(p + 1, surround[i].search);
|
p = strstr(p + 1, surround[i].search);
|
||||||
} while(p && p[-1] == '\\');
|
} while(p && p[-1] == '\\');
|
||||||
if(!p || p >= end ||
|
if (p && p[-1] != '\\')
|
||||||
!(stop = strstr(start, surround[i].search)) || stop >= end)
|
stop = p;
|
||||||
|
if(!stop || stop < start || stop >= end)
|
||||||
continue;
|
continue;
|
||||||
fputs(surround[i].before, stdout);
|
fputs(surround[i].before, stdout);
|
||||||
if(surround[i].process)
|
if(surround[i].process)
|
||||||
|
|
2
testdoc
2
testdoc
|
@ -7,6 +7,8 @@ simple tests
|
||||||
first paragraph.
|
first paragraph.
|
||||||
testing surround: _emph_ then **strong** and `code`.
|
testing surround: _emph_ then **strong** and `code`.
|
||||||
|
|
||||||
|
`\`escaped backticks\``.
|
||||||
|
|
||||||
`x = *y * 6;`
|
`x = *y * 6;`
|
||||||
|
|
||||||
horizontal rule:
|
horizontal rule:
|
||||||
|
|
Loading…
Add table
Reference in a new issue