Skip to content

Inline tag content is doesn't include nested tags #209

@khanlou

Description

@khanlou

Sample program:

let markdown = "*Here's some **markdown** with a [link](https://khanlou.com)*"

let html = HTMLFormatter.format(markdown)

print(html)

Output:

<p><em>Here’s some markdown with a link</em></p>

Expected output:

<p><em>Here's some <strong>markdown</strong> with a <a href="https://khanlou.com">link</a></em></p>

Version:

Commit 82f9258

As far as I can tell, this is because Emphasis.inlineText doesn't include any nested content, it just includes the displayed text.

This can be fixed by changing the implementation of visitEmphasis from this:

public mutating func visitEmphasis(_ emphasis: Emphasis) -> () {
    printInline(tag: "em", emphasis)
}

To this:

public mutating func visitEmphasis(_ emphasis: Emphasis) -> () {
    result += "<em>"
    descendInto(emphasis)
    result += "</em>"
}

The same thing probably needs to be done to the del tag and the strong tag. If there is interest in this fix I can open a PR?

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