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 is not working for the tag names that starts with capital letters #396

Closed
Ki6an opened this issue Aug 23, 2021 · 2 comments
Closed

Comments

@Ki6an
Copy link

Ki6an commented Aug 23, 2021

var TurndownService = require('turndown')

var turndownService = new TurndownService()

turndownService.keep(['Square'])
const markdown = turndownService.turndown('<p>Hello <Square>world</Square> </p>')

console.log(markdown)

result is :

Hello world

not

Hello <Square>world</Square>

however, it works fine with the square

the following also does not work.

turndownService.keep(['square'])
const markdown = turndownService.turndown('<p>Hello</p> <square/>')
>>>  Hello
@Ki6an Ki6an changed the title keep is not working with the tag names that starts with capital letters keep is not working for the tag names that starts with capital letters Aug 23, 2021
martincizek added a commit that referenced this issue Nov 22, 2021
@martincizek
Copy link
Collaborator

There can be unexpected consequences of changing the behavior, so I've updated the docs for now.

Regarding to your second example, the issue is that this is because square is not defined as "meaningful when blank". This list is unfortunately hardcoded, but you can work around this by redefining the blankReplacement if it is really important.

@kalyan02
Copy link

kalyan02 commented Jun 30, 2022

Thanks for the tip about blankReplacement.

Thought I'll leave this code snippet here for someone looking in the future.

Ckeditor5 + markdown strips out oembed tags and I wanted to preserve them. However the oembed tags are actually empty so I modified the blank rule to get it to work.

function oembedRule( turndownService ) {
	var originalBlankRule = turndownService.rules.blankRule.replacement;
	turndownService.rules.blankRule.replacement = function( content, node ) {
		if (node.nodeName == "OEMBED" || node.nodeName == "FIGURE") {
			return node.outerHTML;
		}
		return originalBlankRule(content, node);
	}
};
turndownService.use(oembedRule)

Cheers

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

3 participants