Skip to content

Commit 43b5393

Browse files
authored
fix: filter out HTML (#113)
1 parent d95a2a2 commit 43b5393

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

src/DocsParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class DocsParser {
157157
| ElementDocumentationContainer
158158
)[] = [];
159159
const contents = await fs.readFile(filePath, 'utf8');
160-
const md = new MarkdownIt();
160+
const md = new MarkdownIt({ html: true });
161161

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

@@ -263,7 +263,7 @@ export class DocsParser {
263263

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

268268
const tokens = md.parse(contents, {});
269269
const baseInfos = await this.parseBaseContainers(filePath, contents, tokens);

src/__tests__/__snapshots__/markdown-helpers.spec.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,17 @@ exports[`markdown-helpers safelyJoinTokens snapshots should be correct for parag
341341
Hey"
342342
`;
343343

344+
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-br-tag 1`] = `
345+
"Process: Main
346+
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._
347+
348+
Process: Main
349+
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._
350+
351+
Process: Main
352+
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._"
353+
`;
354+
344355
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-inline-code 1`] = `"This is a \`inline code\` block that is \`code\` tagged."`;
345356

346357
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."`;

src/__tests__/block-parsers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { parseMethodBlocks } from '../block-parsers';
33

44
describe('block parsers', () => {
55
it('should parse a method', async () => {
6-
const md = new MarkdownIt();
6+
const md = new MarkdownIt({ html: true });
77
const contents = `
88
# \`test.foo(x)\`
99
* \`x\` Integer - x
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Process: [Main](../glossary.md#main-process)<br />
2+
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._
3+
4+
Process: [Main](../glossary.md#main-process)<br/>
5+
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._
6+
7+
Process: [Main](../glossary.md#main-process)<br>
8+
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._

src/__tests__/markdown-helpers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { DocumentationTag } from '../ParsedDocumentation';
1919

2020
const getTokens = (md: string) => {
21-
const markdown = new MarkdownIt();
21+
const markdown = new MarkdownIt({ html: true });
2222
return markdown.parse(md, {});
2323
};
2424

src/markdown-helpers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ export const safelyJoinTokens = (tokens: Token[], options: JoinTokenOptions = {}
578578
's_close',
579579
'blockquote_open',
580580
'blockquote_close',
581+
'html_block',
582+
'html_inline',
581583
],
582584
'We only support plain text, links, softbreaks, inline code, strong tags and paragraphs inside joinable tokens',
583585
);
@@ -640,6 +642,13 @@ export const safelyJoinTokens = (tokens: Token[], options: JoinTokenOptions = {}
640642
break;
641643
case 'paragraph_open':
642644
case 'blockquote_close':
645+
case 'html_block':
646+
break;
647+
case 'html_inline':
648+
// Replace <br> elements with a newline
649+
if (tokenToCheck.content.match(/<br\s*\/?>/)) {
650+
joinedContent += '\n';
651+
}
643652
break;
644653
case 'fence':
645654
if (options.parseCodeFences) {

0 commit comments

Comments
 (0)