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

HTML output without inline HTML blocks #74

Closed
skairunner opened this issue Dec 21, 2018 · 2 comments · Fixed by #204
Closed

HTML output without inline HTML blocks #74

skairunner opened this issue Dec 21, 2018 · 2 comments · Fixed by #204
Assignees
Labels
Milestone

Comments

@skairunner
Copy link

Markdown that doesn't accept inline HTML is a common use-case for comments and as a quick way to sanitize input. A contrib renderer that renders HTML while escaping inline HTML tags would be convenient to have.

I'm trying to implement this myself--unless my initial tests are wrong, it seems I can simply inherit from HTMLRenderer and override the render_html_block and render_html_span methods--and I'll have a PR up soonish.

@skairunner
Copy link
Author

skairunner commented Dec 21, 2018

One downside of the current method is that any line or lines that count as an HTMLDiv do not have a wrapping set of <p> tags.

: input
<div>hello</div>

: expected 
<p>&lt;div&gt;hello&lt;/div&gt;</p>

: current
&lt;div&gt;hello&lt;/div&gt;

This doesn't happen to tokens counted as span. I'm not sure what the best way to implement wrapping <p> on HTMLBlocks is. (1) is the quick and simple appending/prepending <p> manually on the LimitedHTMLRenderer.render_html_block method, but I wonder if this could cause problems down the line. (2) is using different tokens that counts all html as Span level tokens instead of separating some as Block. Thoughts?

Finally, the current tests feel a little brittle. Any suggestions on improvements would be really appreciated.

@pbodnar
Copy link
Collaborator

pbodnar commented Sep 18, 2021

Or, as an alternative and hopefully working solution, what about simply disabling parsing of HTML elements? I. e. change the following line in your HTMLRenderer version:

super().__init__(*chain((HTMLBlock, HTMLSpan), extras))

... to:

super().__init__(*chain((), extras))

The existing HTMLRenderer could possibly take a boolean init parameter that would encapsulate this switching.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants