| 38 | }; |
| 39 | |
| 40 | const parseCode = () => { |
| 41 | // Note: the caller has not consumed the initial backtick |
| 42 | |
| 43 | // A quintuple backtick is a code span for a single backtick |
| 44 | if (match('`````')) return { tag: 'code', s: '`' }; |
| 45 | // A triple backtick is also a code span for a single backtick |
| 46 | if (match('```')) return { tag: 'code', s: '`' }; |
| 47 | i += 1; |
| 48 | let s = ''; |
| 49 | |
| 50 | if (t[i] === '`' && t[i + 1] === '`') { |
| 51 | // In a double backtick code span, there are no escape sequences |
| 52 | // and single backticks are preserved verbatim |
| 53 | i += 2; |
| 54 | // Inside a code span, characters are not escaped, so don't use consume() |
| 55 | while (t[i] !== '`' && t[i + 1] !== '`' && i < t.length) { |
| 56 | s += t[i]; |
| 57 | i += 1; |
| 58 | } |
| 59 | i += 2; |
| 60 | spans.push({ tag: 'code', s }); |
| 61 | } |
| 62 | |
| 63 | // In a single backtick code span, backticks can be escaped |
| 64 | // with \` and backslashes can be escaped with \\ |
| 65 | while (t[i] !== '`' && i < t.length) { |
| 66 | if (t[i] === '\\' && t[i + 1] !== undefined) { |
| 67 | i += 1; |
| 68 | // Inside a code span, characters are not escaped, so don't use consume() |
| 69 | if (t[i] === '`') s += '`'; |
| 70 | if (t[i] === '\\') s += '\\'; |
| 71 | else s += `\\${t[i]}`; |
| 72 | } else s += t[i]; |
| 73 | i++; |
| 74 | } |
| 75 | i += 1; |
| 76 | spans.push({ tag: 'code', s }); |
| 77 | }; |
| 78 | |
| 79 | const parseBold = (delim: string) => { |
| 80 | let s = ''; |