df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 1 | import assert from 'node:assert/strict'; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 2 | import { test } from 'node:test'; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 3 | import { codeToHtml, parseCode } from '../src/lib/code.ts'; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 4 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 5 | test('plain text has no formatted body', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 6 | assert.equal(codeToHtml('hello <b>'), null); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 7 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 8 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 9 | test('splits inline code', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 10 | assert.deepEqual(parseCode('run `ls -l` now'), [ |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 11 | { kind: 'text', text: 'run ' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 12 | { kind: 'inline', text: 'ls -l' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 13 | { kind: 'text', text: ' now' } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 14 | ]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 15 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 16 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 17 | test('parses fenced blocks with language', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 18 | assert.deepEqual(parseCode('see\n```rust\nfn main() {}\n```\nok'), [ |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 19 | { kind: 'text', text: 'see\n' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 20 | { kind: 'block', text: 'fn main() {}', lang: 'rust' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 21 | { kind: 'text', text: 'ok' } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 22 | ]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 23 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 24 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 25 | test('backticks inside a block stay literal', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 26 | assert.deepEqual(parseCode('```\na `b` c\n```'), [{ kind: 'block', text: 'a `b` c', lang: null }]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 27 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 28 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 29 | test('unclosed backtick is text', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 30 | assert.deepEqual(parseCode('a ` b'), [{ kind: 'text', text: 'a ` b' }]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 31 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 32 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 33 | test('html escapes and keeps line breaks', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 34 | assert.equal( |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 35 | codeToHtml('x<y\n`a&b`\n```js\n<p>\n```'), |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 36 | 'x<y<br><code>a&b</code><br><pre><code class="language-js"><p></code></pre>' |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 37 | ); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 38 | }); |