
The markdown renderer passes its output through an HTML pretty printer. While this is good in most cases, it makes a mess of elements that expect their content to be left untouched. The pretty printer already ignores `pre` tags (and other built-ins) by default. This fix allows us to specify other tags that should be left alone. Further it actually specifies this option for `code-example` and `code-pane` tags, which expect to contain preformatted content.
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
const renderMarkdownFactory = require('./renderMarkdown');
|
|
|
|
describe('rho: 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(
|
|
'<h1>heading 1</h1>\n' +
|
|
'<p>A paragraph with <strong>bold</strong> and <em>italic</em>.</p>\n' +
|
|
'<ul>\n' +
|
|
' <li>List item 1</li>\n' +
|
|
' <li>List item 2</li>\n' +
|
|
'</ul>');
|
|
});
|
|
|
|
it('should not process markdown inside inline tags', () => {
|
|
const content = '# heading {@link some_url_path}';
|
|
const output = renderMarkdown(content);
|
|
expect(output).toEqual('<h1>heading {@link some_url_path}</h1>');
|
|
});
|
|
|
|
it('should not put block level inline tags inside paragraphs', () => {
|
|
const content = 'A paragraph.\n' +
|
|
'\n' +
|
|
'{@example blah **blah** blah }\n' +
|
|
'\n' +
|
|
'Another paragraph';
|
|
const output = renderMarkdown(content);
|
|
expect(output).toEqual(
|
|
'<p>A paragraph.</p>\n' +
|
|
'<div>{@example blah **blah** blah }</div>\n' +
|
|
'<p>Another paragraph</p>');
|
|
});
|
|
|
|
it('should not format the contents of tags marked as unformatted ', () => {
|
|
renderMarkdown.unformattedTags = ['code-example'];
|
|
const content = '<code-example>\n abc\n def\n</code-example>';
|
|
const output = renderMarkdown(content);
|
|
expect(output).toEqual('<code-example>\n abc\n def\n</code-example>');
|
|
});
|
|
});
|