const renderMarkdownFactory = require('./renderMarkdown');
describe('remark: renderMarkdown service', () => {
let renderMarkdown;
beforeEach(() => {
renderMarkdown = renderMarkdownFactory();
});
it('should convert markdown to HTML', () => {
const content = '# heading 1\n' +
'\n' +
'A paragraph with **bold** and _italic_.\n' +
'\n' +
'* List item 1\n' +
'* List item 2';
const output = renderMarkdown(content);
expect(output).toEqual(
'
heading 1
\n' +
'A paragraph with bold and italic.
\n' +
'\n' +
'- List item 1
\n' +
'- List item 2
\n' +
'
\n');
});
it('should not process markdown inside inline tags', () => {
const content = '* list item {@link some_url_path}';
const output = renderMarkdown(content);
expect(output).toEqual('\n- list item {@link some_url_path}
\n
\n');
});
it('should not put block level inline tags inside paragraphs', () => {
const content = 'A paragraph.\n' +
'\n' +
'{@example blah **blah** blah }\n' +
'\n' +
'Another paragraph {@link _containing_ } an inline tag';
const output = renderMarkdown(content);
expect(output).toEqual(
'A paragraph.
\n' +
'{@example blah **blah** blah }\n' +
'Another paragraph {@link _containing_ } an inline tag
\n');
});
it('should not format the contents of tags marked as unformatted ', () => {
const content = '\n\n **abc**\n\n def\n\n\n\n\n **abc**\n\n def\n';
const output = renderMarkdown(content);
expect(output).toEqual('\n\n **abc**\n\n def\n\n\n\n **abc**\n\n def\n\n');
});
it('should handle recursive tags marked as unformatted', () => {
const content = '\n\n \n\n **abc**\n\n def\n\n\n\n\n\nhij\n\n\n\nklm';
const output = renderMarkdown(content);
expect(output).toEqual('\n\n \n\n **abc**\n\n def\n\n\n\n\nhij
\n\n\nklm\n');
});
it('should raise an error if a tag marked as unformatted is not closed', () => {
const content = '\n\n **abc**\n\n def\n\n\n\n\n **abc**\n\n def\n';
expect(() => renderMarkdown(content)).toThrowError('Unmatched plain HTML block tag ');
});
it('should not remove spaces after anchor tags', () => {
var input =
'A aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa\n' +
'[foo](path/to/foo) bbb.';
var output =
'' +
'A aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa\n' +
'foo bbb.' +
'
\n';
expect(renderMarkdown(input)).toEqual(output);
});
it('should not format indented text as code', () => {
const content = 'some text\n\n indented text\n\nother text';
const output = renderMarkdown(content);
expect(output).toEqual('some text
\n indented text
\nother text
\n');
});
it('should format triple backtick code blocks as `code-example` tags', () => {
const content =
'```ts\n' +
' class MyClass {\n' +
' method1() { ... }\n' +
' }\n' +
'```';
const output = renderMarkdown(content);
expect(output).toEqual(
'\n' +
' class MyClass {\n' +
' method1() { ... }\n' +
' }\n' +
'\n'
);
});
});