Skip to content

function pretty_codeblock leaves an end tag for code element which is not open #214

@milmazz

Description

@milmazz

The current pretty_codeblock function in html.ex generates invalid HTML code, this function leaves an end tag for the code element which is not open.

iex> bin = "<pre><code>Hello world</code></pre><pre><code class=\"\">Hello world</code></pre>"
"<pre><code>Hello world</code></pre><pre><code class=\"\">Hello world</code></pre>"
iex> Regex.replace(~r/<pre><code\s*(class=\"\")?>/, bin, "<pre class=\"codeblock\">")
"<pre class=\"codeblock\">Hello world</code></pre><pre class=\"codeblock\">Hello world</code></pre>"

One way to solve this is updating the regex:

iex> Regex.replace(~r/<pre><code\s*(class=\"\")?>(.+?)<\/code><\/pre>/, bin, "<pre class=\"codeblock\">\\2</pre>")
"<pre class=\"codeblock\">Hello world</pre><pre class=\"codeblock\">Hello world</pre>"

But, if we look further, right now there is no rule for the .codeblock CSS class. So, I suggest to delete this pretty_codeblock and try to control the look of the <pre> and <code> tags in the CSS files, because there is where the rules that are in control of the style of HTML blocks belongs.

But, I really want to know your opinion about this matter before I propose a Pull Request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions