trentm / python-markdown2

markdown2: A fast and complete implementation of Markdown in Python
Other
2.64k stars 431 forks source link

Impossible to use stylesheets #523

Closed dims12 closed 1 year ago

dims12 commented 1 year ago

Describe the bug Native markdown supports stylesheets while markdown2 doesn't

To Reproduce Add stylesheet at the beginning of MD file like this

<style>
code {
    white-space:pre;
    font-family: "Lucida Console", "Courier New", monospace;
    background-color: darkblue;
    color: lightyellow;
    line-height: 1;
}
pre > code {
    display: block;
}
</style>

add some inline code and code blocks then render it.

You will see that stylessheet will be corrupted with <p> tags and pre > code will be rendered as pre &gt; code.

Expected behavior The stylesheet should move to the rendered file as is. The block code reagions should then get pre > code style, while inline code regions should get only code style.

Crozzers commented 1 year ago

Can probably add an extra to ignore certain html blocks. Markdown ignores script and style tags, although I don't know whether that's extra functionality or standard. For ease of implementation I think it would end up requiring the blocks to be formatted nicely, with opening tags on a newline and closing tags on a final newline. EG:

<script> // like this
</script>

abc <script> // and not like this
</script>

<script>
console.log('or this')</script>
Crozzers commented 1 year ago

Ah, I'm overthinking this. The style tag is missing from the list of block tags. script is already in there so adding style is easy