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

HTML to Markdown: extra newline characters around un-converted tags #621

Open
andosteinmetz opened this issue Nov 14, 2018 · 2 comments
Open
Assignees

Comments

@andosteinmetz
Copy link

andosteinmetz commented Nov 14, 2018

I'm encountering an issue where two newlines (i.e. markdown paragraphs) are inserted after <span> elements. The same happens if it is a <div> or a made-up <pqr> tag.

Here's a very simple test case:

const showdown = require('showdown');

const converter = new showdown.Converter();

const sampleText = '<p>A test <span>case</span> to see if I can <span>reproduce</span> the extra newline <span>problem</span>.</p>';

const ret = converter.makeMarkdown(sampleText);

console.log(ret);

Where I'd expect the result to be:
A test <span>case</span> to see if I can <span>reproduce</span>the extra newline <span>problem</span>.\n\n

I get:
A test <span>case</span>\n\n to see if I can <span>reproduce</span>\n\n the extra newline <span>problem</span>\n\n.

I don't expect this is the desired behavior... Is there an option I'm missing that would solve this problem? Or is it a bug?

UPDATE:
I seem to have fixed the problem for myself by overriding showdown.makeMarkdown.node, where rather than

default: 
  txt = node.outerHTML + '\n\n';
  break;

I have:

  default:
    txt = node.outerHTML;
    break;
}
@tivie tivie self-assigned this Nov 14, 2018
@tivie
Copy link
Member

tivie commented Nov 14, 2018

Thanks. I will look into it.

@DogCatPuppyLover
Copy link

@SyntaxRules This is still an issue, and I can't figure out how to override it like @andosteinmetz did.

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

No branches or pull requests

3 participants