Skip to content

Support backticks inside inline code spans #226

@projetmbc

Description

@projetmbc

With the version 1.1.0, the following code

from markdownify import markdownify as md

print(
    md(
        '<code>We have to `manage` this.</code>',
    )
)

should print

``We have to `manage` this.``

instead of

`We have to `manage` this.`

In one of my project, I have fixed this using the following lines of code.

    def convert_code(self, el, text, parent_tags = None):
        if el.parent.name == "pre":
            return text

        code = el.get_text()

        if "`" in code:
            code = f"`{code}`"

        return f"`{code}`"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions