build(aio): remove unused Rho package
This commit is contained in:
parent
df619adc76
commit
69b37fff26
|
@ -1,9 +0,0 @@
|
|||
var Package = require('dgeni').Package;
|
||||
|
||||
/**
|
||||
* @dgPackage rho
|
||||
* @description Overrides the renderMarkdown service with an implementation based on Rho
|
||||
*/
|
||||
module.exports = new Package('rho', ['nunjucks'])
|
||||
|
||||
.factory(require('./services/renderMarkdown'));
|
|
@ -1,68 +0,0 @@
|
|||
const rho = require('rho');
|
||||
const { prettyPrint } = require('html');
|
||||
|
||||
const defaultUnformattedTags = [
|
||||
'a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym',
|
||||
'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre',
|
||||
'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
||||
|
||||
/**
|
||||
* @dgService renderMarkdown
|
||||
* @description
|
||||
* Render the markdown in the given string as HTML.
|
||||
*/
|
||||
module.exports = function renderMarkdown() {
|
||||
|
||||
|
||||
// TODO(petebd): We might want to remove the leading whitespace from the code
|
||||
// block before it gets to the markdown code render function
|
||||
|
||||
// We need to teach Rho about inline tags so that it doesn't try to process
|
||||
// the inside of the tag
|
||||
const emitNormal = rho.InlineCompiler.prototype.emitNormal;
|
||||
rho.InlineCompiler.prototype.emitNormal = function(walk) {
|
||||
if (this.emitText(walk)) return;
|
||||
if (tryDgeniInlineTag(this, walk)) return;
|
||||
emitNormal.call(this, walk);
|
||||
};
|
||||
|
||||
rho.BlockCompiler.prototype.emitBlock = function(walk) {
|
||||
walk.skipBlankLines();
|
||||
this.countBlockIndent(walk);
|
||||
if (this.tryUnorderedList(walk)) return;
|
||||
if (this.tryOrderedList(walk)) return;
|
||||
if (this.tryDefinitionList(walk)) return;
|
||||
if (this.tryHeading(walk)) return;
|
||||
if (this.tryCodeBlock(walk)) return;
|
||||
if (this.tryDiv(walk)) return;
|
||||
if (this.tryHtml(walk)) return;
|
||||
if (tryDgeniInlineTag(this, walk, true)) return;
|
||||
if (this.tryHrTable(walk)) return;
|
||||
this.emitParagraph(walk);
|
||||
};
|
||||
|
||||
function tryDgeniInlineTag(compiler, walk, isBlock) {
|
||||
if (!walk.at('{@')) return false;
|
||||
|
||||
const startIdx = walk.position;
|
||||
var endIdx = walk.indexOf('}');
|
||||
|
||||
if (endIdx === null) return false;
|
||||
|
||||
if (isBlock) compiler.out.push('<div>');
|
||||
compiler.out.push(walk.substring(startIdx, endIdx + 1));
|
||||
if (isBlock) compiler.out.push('</div>\n');
|
||||
|
||||
walk.startFrom(endIdx + 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
renderMarkdownImpl.unformattedTags = [];
|
||||
|
||||
return renderMarkdownImpl;
|
||||
|
||||
function renderMarkdownImpl(content) {
|
||||
const rawHtml = new rho.BlockCompiler(rho.options).toHtml(content);
|
||||
return prettyPrint(rawHtml, { indent_size: 2, max_char: 0, unformatted: [...defaultUnformattedTags, ...renderMarkdownImpl.unformattedTags]});
|
||||
}
|
||||
};
|
|
@ -1,65 +0,0 @@
|
|||
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>');
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue