diff --git a/src/nvim/help.c b/src/nvim/help.c index f88670c31d..745c133c0e 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -939,10 +939,15 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool } p1 = p2; } - size_t len = strlen(IObuff); - if ((len == 2 && strcmp(&IObuff[len - 2], ">\n") == 0) - || (len >= 3 && strcmp(&IObuff[len - 3], " >\n") == 0)) { - in_example = true; + size_t off = strlen(IObuff); + if (off >= 2 && IObuff[off - 1] == '\n') { + off -= 2; + while (off > 0 && (ASCII_ISLOWER(IObuff[off]) || ascii_isdigit(IObuff[off]))) { + off--; + } + if (IObuff[off] == '>' && (off == 0 || IObuff[off - 1] == ' ')) { + in_example = true; + } } line_breakcheck(); } diff --git a/test/old/testdir/test_help.vim b/test/old/testdir/test_help.vim index 2befcad6b8..d2943e1b96 100644 --- a/test/old/testdir/test_help.vim +++ b/test/old/testdir/test_help.vim @@ -157,11 +157,17 @@ func Test_helptag_cmd() call delete('Xtagdir/tags') " Test parsing tags - call writefile(['*tag1*', 'Example: >', ' *notag*', 'Example end: *tag2*'], + call writefile(['*tag1*', 'Example: >', ' *notag1*', 'Example end: *tag2*', + \ '>', ' *notag2*', '<', + \ '*tag3*', 'Code: >vim', ' *notag3*', 'Code end: *tag4*', + \ '>i3config', ' *notag4*', '<'], \ 'Xtagdir/a/doc/sample.txt') helptags Xtagdir call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*", - \ "tag2\ta/doc/sample.txt\t/*tag2*"], readfile('Xtagdir/tags')) + \ "tag2\ta/doc/sample.txt\t/*tag2*", + \ "tag3\ta/doc/sample.txt\t/*tag3*", + \ "tag4\ta/doc/sample.txt\t/*tag4*"], + \ readfile('Xtagdir/tags')) " Duplicate tags in the help file call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt')