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

keep() and remove() does not work for all HTML tags #455

Open
trymeouteh opened this issue Mar 16, 2024 · 1 comment
Open

keep() and remove() does not work for all HTML tags #455

trymeouteh opened this issue Mar 16, 2024 · 1 comment

Comments

@trymeouteh
Copy link

Some tags such as <b> and <i> do not work when passed in the keep() and remove() methods. The tags are still converted to markdown even when it was instructed to either keep the tags or remove the tags.

Here is an example to reproduce this...

Turndown v7.1.3

<script src="node_modules/turndown/dist/turndown.js"></script>

<script>
    const myTurndownA = new TurndownService();
    console.log(myTurndownA.turndown('<b>Hello <i>World</i></b>'));

    myTurndownA.keep(['b', 'i']);
    console.log(myTurndownA.turndown('<b>Hello <i>World</i></b>'));



    const myTurndownB = new TurndownService();
    console.log(myTurndownB.turndown('<b>Hello <i>World</i></b>'));

    myTurndownB.keep(['b', 'i']);
    console.log(myTurndownB.turndown('<b>Hello <i>World</i></b>'));
</script>
@hwiorn
Copy link

hwiorn commented May 11, 2024

Because the current implementation uses the pre-defined replacement rules before keep-rules and remove-rules. The fix is changing order of rules simply. But I can't say it's backward compatible.

The same issue is happen when user defined the custom replacement rules of strikethrough(del tag) or underline(ins tag).

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

No branches or pull requests

2 participants