0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-13 16:13:08 +01:00
gitea/web_src/js/markup/html2markdown.test.ts
wxiaoguang 145e266987
Support quote selected comments to reply (#32431)
Many existing tests were quite hacky, these could be improved later.

<details>

![image](https://github.com/user-attachments/assets/93aebb4f-9de5-4cb8-910b-50c64cbcd25a)

</details>
2024-11-07 03:57:07 +00:00

24 lines
1.3 KiB
TypeScript

import {convertHtmlToMarkdown} from './html2markdown.ts';
import {createElementFromHTML} from '../utils/dom.ts';
const h = createElementFromHTML;
test('convertHtmlToMarkdown', () => {
expect(convertHtmlToMarkdown(h(`<h1>h</h1>`))).toBe('# h');
expect(convertHtmlToMarkdown(h(`<strong>txt</strong>`))).toBe('**txt**');
expect(convertHtmlToMarkdown(h(`<em>txt</em>`))).toBe('_txt_');
expect(convertHtmlToMarkdown(h(`<del>txt</del>`))).toBe('~~txt~~');
expect(convertHtmlToMarkdown(h(`<a href="link">txt</a>`))).toBe('[txt](link)');
expect(convertHtmlToMarkdown(h(`<a href="https://link">https://link</a>`))).toBe('https://link');
expect(convertHtmlToMarkdown(h(`<img src="link">`))).toBe('![image](link)');
expect(convertHtmlToMarkdown(h(`<img src="link" alt="name">`))).toBe('![name](link)');
expect(convertHtmlToMarkdown(h(`<img src="link" width="1" height="1">`))).toBe('<img alt="image" width="1" height="1" src="link">');
expect(convertHtmlToMarkdown(h(`<p>txt</p>`))).toBe('txt\n');
expect(convertHtmlToMarkdown(h(`<blockquote>a\nb</blockquote>`))).toBe('> a\n> b\n');
expect(convertHtmlToMarkdown(h(`<ol><li>a<ul><li>b</li></ul></li></ol>`))).toBe('1. a\n * b\n\n');
expect(convertHtmlToMarkdown(h(`<ol><li><input checked>a</li></ol>`))).toBe('1. [x] a\n');
});