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: 2 additions & 2 deletions src/DocsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class DocsParser {
| ElementDocumentationContainer
)[] = [];
const contents = await fs.readFile(filePath, 'utf8');
const md = new MarkdownIt();
const md = new MarkdownIt({ html: true });

const allTokens = md.parse(contents, {});

Expand Down Expand Up @@ -263,7 +263,7 @@ export class DocsParser {

private async parseStructure(filePath: string): Promise<StructureDocumentationContainer> {
const contents = await fs.readFile(filePath, 'utf8');
const md = new MarkdownIt();
const md = new MarkdownIt({ html: true });

const tokens = md.parse(contents, {});
const baseInfos = await this.parseBaseContainers(filePath, contents, tokens);
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/__snapshots__/markdown-helpers.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ exports[`markdown-helpers safelyJoinTokens snapshots should be correct for parag
Hey"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-br-tag 1`] = `
"Process: Main
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._

Process: Main
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._

Process: Main
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-inline-code 1`] = `"This is a \`inline code\` block that is \`code\` tagged."`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-links 1`] = `"This paragraph has a bunch of stuff. Also some links Foo, these links should be stripped."`;
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/block-parsers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parseMethodBlocks } from '../block-parsers';

describe('block parsers', () => {
it('should parse a method', async () => {
const md = new MarkdownIt();
const md = new MarkdownIt({ html: true });
const contents = `
# \`test.foo(x)\`
* \`x\` Integer - x
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/fixtures/paragraph-with-br-tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Process: [Main](../glossary.md#main-process)<br />
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._

Process: [Main](../glossary.md#main-process)<br/>
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._

Process: [Main](../glossary.md#main-process)<br>
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._
2 changes: 1 addition & 1 deletion src/__tests__/markdown-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { DocumentationTag } from '../ParsedDocumentation';

const getTokens = (md: string) => {
const markdown = new MarkdownIt();
const markdown = new MarkdownIt({ html: true });
return markdown.parse(md, {});
};

Expand Down
9 changes: 9 additions & 0 deletions src/markdown-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ export const safelyJoinTokens = (tokens: Token[], options: JoinTokenOptions = {}
's_close',
'blockquote_open',
'blockquote_close',
'html_block',
'html_inline',
],
'We only support plain text, links, softbreaks, inline code, strong tags and paragraphs inside joinable tokens',
);
Expand Down Expand Up @@ -640,6 +642,13 @@ export const safelyJoinTokens = (tokens: Token[], options: JoinTokenOptions = {}
break;
case 'paragraph_open':
case 'blockquote_close':
case 'html_block':
break;
case 'html_inline':
// Replace <br> elements with a newline
if (tokenToCheck.content.match(/<br\s*\/?>/)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the $ and ^ anchors here? Worst case we get a bunch of newlines but not sure how this works 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing on https://markdown-it.github.io/ (need to toggle the html option), html_inline is always going to have a token that starts with < and ends with >, so I don't think we need anchors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I was just thinking about some truly garbage HTML
image
Or some less garbage HTML that's just nested
image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are both html_block so they'll get chomped entirely by this change, which is I think what we want?

joinedContent += '\n';
}
break;
case 'fence':
if (options.parseCodeFences) {
Expand Down