atagen

malice

public
Star0
Watch0
2021154f9e16d427af2b4379df1017f1c9e10072
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git
web/test/markdown.test.tsTypescript29 lines1.3 KB
1
import assert from 'node:assert/strict';
2
import { test } from 'node:test';
3
import { formatBody, insideOpenFence } from '../src/lib/markdown.ts';
4
5
test('plain text stays unformatted', () => {
6
  assert.equal(formatBody('hello\nthere', [], true), null);
7
  assert.equal(formatBody('**bold**', [], false), null);
8
});
9
10
test('renders the common chat markdown', () => {
11
  assert.equal(formatBody('*it* **bold** ~~gone~~', [], true), '<p><em>it</em> <strong>bold</strong> <del>gone</del></p>');
12
  assert.equal(formatBody('> quoted\nstill', [], true), '<blockquote>quoted<br></blockquote>still');
13
  assert.equal(formatBody('run `ls <x>`', [], true), '<p>run <code>ls &lt;x&gt;</code></p>');
14
  assert.equal(
15
    formatBody('```js\nlet a = "<b>";\n```', [], true),
16
    '<pre><code class="language-js">let a = &quot;&lt;b&gt;&quot;;\n</code></pre>'
17
  );
18
});
19
20
test('raw html is escaped, not passed through', () => {
21
  assert.equal(formatBody('<b>hi</b> **x**', [], true), '<p>&lt;b&gt;hi&lt;/b&gt; <strong>x</strong></p>');
22
  assert.equal(formatBody('<script>alert(1)</script>', [], true), null);
23
});
24
25
test('enter stays a newline inside an open fence', () => {
26
  assert.equal(insideOpenFence('```\ncode', 8), true);
27
  assert.equal(insideOpenFence('```\ncode\n```\n', 13), false);
28
  assert.equal(insideOpenFence('say ``` mid line', 16), false);
29
});