mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-24 18:16:15 +01:00
145e266987
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>
25 lines
1.3 KiB
TypeScript
25 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');
|
|
});
|