Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add block param to html renderer #2768

Merged
merged 1 commit into from
May 2, 2023
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
2 changes: 1 addition & 1 deletion docs/USING_PRO.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ console.log(marked.parse('# heading+'));

- <code>**code**(*string* code, *string* infostring, *boolean* escaped)</code>
- <code>**blockquote**(*string* quote)</code>
- <code>**html**(*string* html)</code>
- <code>**html**(*string* html, *boolean* block)</code>
- <code>**heading**(*string* text, *number* level, *string* raw, *Slugger* slugger)</code>
- <code>**hr**()</code>
- <code>**list**(*string* body, *boolean* ordered, *number* start)</code>
Expand Down
3 changes: 1 addition & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ export class Parser {
continue;
}
case 'html': {
// TODO parse inline content if parameter markdown=1
out += this.renderer.html(token.text);
out += this.renderer.html(token.text, token.block);
continue;
}
case 'paragraph': {
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Renderer {
return `<blockquote>\n${quote}</blockquote>\n`;
}

html(html) {
html(html, block) {
return html;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export class Tokenizer {
if (cap) {
const token = {
type: 'html',
block: true,
raw: cap[0],
pre: !this.options.sanitizer
&& (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
Expand Down Expand Up @@ -519,6 +520,7 @@ export class Tokenizer {
raw: cap[0],
inLink: this.lexer.state.inLink,
inRawBlock: this.lexer.state.inRawBlock,
block: false,
text: this.options.sanitize
? (this.options.sanitizer
? this.options.sanitizer(cap[0])
Expand Down
16 changes: 13 additions & 3 deletions test/unit/Lexer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ paragraph
type: 'html',
raw: '<div>html</div>',
pre: false,
block: true,
text: '<div>html</div>'
}
]
Expand All @@ -787,6 +788,7 @@ paragraph
type: 'html',
raw: '<pre>html</pre>',
pre: true,
block: true,
text: '<pre>html</pre>'
}
]
Expand All @@ -802,6 +804,7 @@ paragraph
type: 'paragraph',
raw: '<div>html</div>',
pre: false,
block: true,
text: '&lt;div&gt;html&lt;/div&gt;',
tokens: [{
type: 'text',
Expand Down Expand Up @@ -884,9 +887,9 @@ paragraph
expectInlineTokens({
md: '<div>html</div>',
tokens: [
{ type: 'html', raw: '<div>', inLink: false, inRawBlock: false, text: '<div>' },
{ type: 'html', raw: '<div>', inLink: false, inRawBlock: false, block: false, text: '<div>' },
{ type: 'text', raw: 'html', text: 'html' },
{ type: 'html', raw: '</div>', inLink: false, inRawBlock: false, text: '</div>' }
{ type: 'html', raw: '</div>', inLink: false, inRawBlock: false, block: false, text: '</div>' }
]
});
});
Expand All @@ -896,7 +899,14 @@ paragraph
md: '<div>html</div>',
options: { sanitize: true },
tokens: [
{ type: 'text', raw: '<div>html</div>', inLink: false, inRawBlock: false, text: '&lt;div&gt;html&lt;/div&gt;' }
{
type: 'text',
raw: '<div>html</div>',
inLink: false,
inRawBlock: false,
block: false,
text: '&lt;div&gt;html&lt;/div&gt;'
}
]
});
});
Expand Down