Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions addon/utils/compile-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ function compactParagraphs(tokens) {
let tokenText = token.text || '';
let textWithoutCode = tokenText.replace(/`[\s\S]*?`/g, '');

if (token.type === 'code') {
textWithoutCode = ''
}

balance += count(/{{#/g, textWithoutCode);
balance += count(/<[A-Z]/g, textWithoutCode);
balance -= count(/[A-Z][^<>]+\/>/g, textWithoutCode);
Expand Down
42 changes: 42 additions & 0 deletions tests-node/unit/utils/compile-markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,46 @@ describe('Unit | compile-markdown', function(hooks) {

assert.equal(result, expected);
});

it('using code block simple case', function() {
let input = stripIndent`
\`\`\`hbs
<FooBar>Hello</FooBar>
\`\`\`

This is after code block
`;

let result = compileMarkdown(input, { targetHandlebars: true });
let expected = stripIndent`
<div class="docs-md"><pre class="docs-md__code"><code class="undefinedhbs"><span class="xml"> <span class="hljs-tag">&lt;<span class="hljs-name">FooBar</span>&gt;</span>Hello<span class="hljs-tag">&lt;/<span class="hljs-name">FooBar</span>&gt;</span></span></code></pre>
<p>This is after code block</p></div>
`;

assert.equal(result, expected);
});

it('using code block with self-closing tag inside', function() {
let input = stripIndent`
\`\`\`hbs
<form.Text
@fieldName="name.first"
@label="First Name"
/>
\`\`\`

This is after code block
`;

let result = compileMarkdown(input, { targetHandlebars: true });
let expected = stripIndent`
<div class="docs-md"><pre class="docs-md__code"><code class="undefinedhbs"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form.Text</span>
@<span class="hljs-attr">fieldName</span>=<span class="hljs-string">"name.first"</span>
@<span class="hljs-attr">label</span>=<span class="hljs-string">"First Name"</span>
/&gt;</span></span></code></pre>
<p>This is after code block</p></div>
`;

assert.equal(result, expected);
});
});
22 changes: 11 additions & 11 deletions tests/dummy/app/pods/docs/quickstart/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ AddonDocs is unopinionated about how you style your application, so you can use

The `docs` route is the entry point for your guides and API docs. Create a new `docs/template.hbs` file for the `docs` route and add the `<DocsViewer />` component:

{{#docs-snippet name="quickstart-skeleton.hbs" language="htmlbars" title="tests/dummy/app/templates/docs.hbs"}}
{{#docs-viewer as |viewer|}}
{{#viewer.nav as |nav|}}
{{nav.item "Introduction" "docs.index"}}
{{/viewer.nav}}

{{#viewer.main}}
{{outlet}}
{{/viewer.main}}
{{/docs-viewer}}
{{/docs-snippet}}
{{#docs-snippet name="quickstart-skeleton.hbs" language="htmlbars" title="tests/dummy/app/templates/docs.hbs"}}
{{#docs-viewer as |viewer|}}
{{#viewer.nav as |nav|}}
{{nav.item "Introduction" "docs.index"}}
{{/viewer.nav}}

{{#viewer.main}}
{{outlet}}
{{/viewer.main}}
{{/docs-viewer}}
{{/docs-snippet}}

If you visit `/docs` or click the Documentation link in the header, you should see the viewer's nav on the left-hand side and an area in the center where your guides content will go.

Expand Down