fix(aio): preserve space after anchor elements

Sometimes, depending on the length of lines, anchor elements would be formatted
incorrectly by `html.prettyPrint` and the space right after the element was
removed.

This was apparently caused by a bug in `html.prettyPrint` in combination with
its default behavior of wrapping lines at a specific limit (70 chars). Since the
output is only meant to be used as JSON string data, wrapping the lines makes it
less readable by adding unnecessary `\n`.

This commit disables the line wrapping, which effectively avoids the bug that
was responsible for incorrectly formatting anchor elements and surrounding
space.

Related to #15681.
This commit is contained in:
Georgios Kalpakas 2017-04-01 17:51:32 +03:00 committed by Pete Bacon Darwin
parent c8be3960a0
commit 8c726ea87e
2 changed files with 15 additions and 2 deletions

View File

@ -63,6 +63,6 @@ module.exports = function renderMarkdown() {
function renderMarkdownImpl(content) { function renderMarkdownImpl(content) {
const rawHtml = new rho.BlockCompiler(rho.options).toHtml(content); const rawHtml = new rho.BlockCompiler(rho.options).toHtml(content);
return prettyPrint(rawHtml, { indent_size: 2, unformatted: [...defaultUnformattedTags, ...renderMarkdownImpl.unformattedTags]}); return prettyPrint(rawHtml, { indent_size: 2, max_char: 0, unformatted: [...defaultUnformattedTags, ...renderMarkdownImpl.unformattedTags]});
}; };
}; };

View File

@ -49,4 +49,17 @@ describe('rho: renderMarkdown service', () => {
const output = renderMarkdown(content); const output = renderMarkdown(content);
expect(output).toEqual('<code-example>\n abc\n def\n</code-example>'); expect(output).toEqual('<code-example>\n abc\n def\n</code-example>');
}); });
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 =
'<p>' +
'A aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa\n' +
'<a href="path/to/foo">foo</a> bbb.' +
'</p>';
expect(renderMarkdown(input)).toEqual(output);
});
}); });