diff --git a/aio/content/marketing/test.html b/aio/content/marketing/test.html index 2e47ce34da..3a0c48a9fb 100644 --- a/aio/content/marketing/test.html +++ b/aio/content/marketing/test.html @@ -5,8 +5,8 @@

No linenums at code-tabs level

class { - foo(param: string) {} - } + foo(param: string) {} +} <h1>Heading</h1> { "key": "value" } @@ -15,8 +15,8 @@

linenums=true at code-tabs level

class { - foo(param: string) {} - } + foo(param: string) {} +} <h1>Heading</h1> { "key": "value" } @@ -25,8 +25,8 @@

No linenums at code-tabs level; linenums=true for HTML pane

class { - foo(param: string) {} - } + foo(param: string) {} +} <h1>Heading</h1> { "key": "value" } diff --git a/aio/package.json b/aio/package.json index 37c1edd7be..d8427c8896 100644 --- a/aio/package.json +++ b/aio/package.json @@ -38,7 +38,6 @@ "@angular/router": "next", "@angular/service-worker": "^1.0.0-beta.8", "core-js": "^2.4.1", - "rho": "https://github.com/petebacondarwin/rho#master", "rxjs": "^5.2.0", "zone.js": "^0.8.4" }, @@ -53,6 +52,7 @@ "dgeni-packages": "0.17.0", "entities": "^1.1.1", "firebase-tools": "^3.2.1", + "html": "^1.0.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", @@ -63,6 +63,7 @@ "karma-jasmine-html-reporter": "^0.2.2", "lodash": "^4.17.4", "protractor": "~5.1.0", + "rho": "https://github.com/petebacondarwin/rho#master", "rimraf": "^2.6.1", "ts-node": "~2.0.0", "tslint": "~4.5.0", diff --git a/aio/transforms/angular.io-package/index.js b/aio/transforms/angular.io-package/index.js index fce16ed848..4a8316c621 100644 --- a/aio/transforms/angular.io-package/index.js +++ b/aio/transforms/angular.io-package/index.js @@ -201,7 +201,7 @@ module.exports = // Configure nunjucks rendering of docs via templates .config(function( - renderDocsProcessor, versionInfo, templateFinder, templateEngine, getInjectables) { + renderDocsProcessor, versionInfo, templateFinder, templateEngine, getInjectables, renderMarkdown) { // Where to find the templates for the doc rendering templateFinder.templateFolders = [TEMPLATES_PATH]; @@ -228,6 +228,12 @@ module.exports = renderDocsProcessor.helpers.relativePath = function(from, to) { return path.relative(from, to); }; + + // Tell the HTML formatter not to format code-example blocks + renderMarkdown.unformattedTags = [ + 'code-example', + 'code-pane' + ]; }) diff --git a/aio/transforms/rho-package/services/renderMarkdown.js b/aio/transforms/rho-package/services/renderMarkdown.js index bcc858e87c..34e7f4d12c 100644 --- a/aio/transforms/rho-package/services/renderMarkdown.js +++ b/aio/transforms/rho-package/services/renderMarkdown.js @@ -1,4 +1,10 @@ -var rho = require('rho'); +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 @@ -45,11 +51,18 @@ module.exports = function renderMarkdown() { if (isBlock) compiler.out.push('
'); compiler.out.push(walk.substring(startIdx, endIdx + 1)); - if (isBlock) compiler.out.push('
'); + if (isBlock) compiler.out.push('\n'); walk.startFrom(endIdx + 2); return true; }; - return function renderMarkdownImpl(content) { return rho.toHtml(content, true); }; + renderMarkdownImpl.unformattedTags = []; + + return renderMarkdownImpl; + + function renderMarkdownImpl(content) { + const rawHtml = new rho.BlockCompiler(rho.options).toHtml(content); + return prettyPrint(rawHtml, { indent_size: 2, unformatted: [...defaultUnformattedTags, ...renderMarkdownImpl.unformattedTags]}); + }; }; \ No newline at end of file diff --git a/aio/transforms/rho-package/services/renderMarkdown.spec.js b/aio/transforms/rho-package/services/renderMarkdown.spec.js index 9790ffab1b..e93b97882e 100644 --- a/aio/transforms/rho-package/services/renderMarkdown.spec.js +++ b/aio/transforms/rho-package/services/renderMarkdown.spec.js @@ -1,7 +1,11 @@ const renderMarkdownFactory = require('./renderMarkdown'); -const renderMarkdown = renderMarkdownFactory(); describe('rho: renderMarkdown service', () => { + let renderMarkdown; + beforeEach(() => { + renderMarkdown = renderMarkdownFactory(); + }); + it('should convert markdown to HTML', () => { const content = '# heading 1\n' + '\n' + @@ -17,13 +21,13 @@ describe('rho: renderMarkdown service', () => { '\n'); + ''); }); it('should not process markdown inside inline tags', () => { const content = '# heading {@link some_url_path}'; const output = renderMarkdown(content); - expect(output).toEqual('

heading {@link some_url_path}

\n'); + expect(output).toEqual('

heading {@link some_url_path}

'); }); it('should not put block level inline tags inside paragraphs', () => { @@ -36,6 +40,13 @@ describe('rho: renderMarkdown service', () => { expect(output).toEqual( '

A paragraph.

\n' + '
{@example blah **blah** blah }
\n' + - '

Another paragraph

\n'); + '

Another paragraph

'); + }); + + it('should not format the contents of tags marked as unformatted ', () => { + renderMarkdown.unformattedTags = ['code-example']; + const content = '\n abc\n def\n'; + const output = renderMarkdown(content); + expect(output).toEqual('\n abc\n def\n'); }); }); diff --git a/aio/yarn.lock b/aio/yarn.lock index 4e01a52327..04cfa33f66 100644 --- a/aio/yarn.lock +++ b/aio/yarn.lock @@ -2604,7 +2604,7 @@ html-webpack-plugin@^2.19.0: pretty-error "^2.0.2" toposort "^1.0.0" -html@*: +html@*, html@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/html/-/html-1.0.0.tgz#a544fa9ea5492bfb3a2cca8210a10be7b5af1f61" dependencies: @@ -5781,14 +5781,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@2.2.0: +typescript@2.2.0, "typescript@>=2.0.0 <2.3.0": version "2.2.0" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.0.tgz#626f2fc70087d2480f21ebb12c1888288c8614e3" -"typescript@>=2.0.0 <2.3.0": - version "2.1.6" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.6.tgz#40c7e6e9e5da7961b7718b55505f9cac9487a607" - typescript@^1.7.5: version "1.8.10" resolved "https://registry.yarnpkg.com/typescript/-/typescript-1.8.10.tgz#b475d6e0dff0bf50f296e5ca6ef9fbb5c7320f1e"