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

Only use turndown formatted code if it introduces non-whitespace changes #1401

Closed
wants to merge 1 commit into from

Conversation

GreenGremlin
Copy link
Contributor

@GreenGremlin GreenGremlin commented Oct 2, 2018

Since the local copy of cledit seems to have diverged from the public copy, I assume the local copy of cledit is a fork and that you're ok with modifying it.

This change ensures code pasted from text editors is not formatted improperly.

If there are only white-space changes between the text version and the Turndown formatted version, then we should just use the text version.

Fixes #1364

An alternative solution would be to search the html for html tags that would produce markdown syntax and would not be in code pasted from a text editor. Something like this:

const MARKDOWN_TAG_RE = /<(p|br|h[1-6]|em|i|strong|b|img)(\s|>|\/)/i;

          [...]
          const html = clipboardData.getData('text/html');
          if (html && MARKDOWN_TAG_RE.test(html)) {

If that seems like a preferable solution, I don't mind closing this PR and opening a new one.

@GreenGremlin GreenGremlin changed the title Only use turndown formatted code if it makes not white-space changes Only use turndown formatted code if it makes non-whitespace changes Oct 2, 2018
@GreenGremlin GreenGremlin changed the title Only use turndown formatted code if it makes non-whitespace changes Only use turndown formatted code if it introduces non-whitespace changes Oct 2, 2018
This change ensures code pasted from text editors is not formatted improperly.
@GreenGremlin
Copy link
Contributor Author

Anything I can do to help get this merged?

@GreenGremlin
Copy link
Contributor Author

Just checking back in, wondering if I should just close this PR.

@vekien
Copy link

vekien commented May 1, 2019

@benweet could we get this merged? This is still an issue and makes using code blocks 100% impossible with the current version.

@kkoenen
Copy link

kkoenen commented May 18, 2019

Voting to merge this. Need correct code blocks.

//edit; workaround: try adding 4 spaces before every line of code.

@benweet
Copy link
Owner

benweet commented Jun 23, 2019

Sorry for the late response.
What does this change fix? Can you illustrate the addressed issue?

@GreenGremlin
Copy link
Contributor Author

GreenGremlin commented Jun 23, 2019

Sorry for the late response.
What does this change fix? Can you illustrate the addressed issue?

This change ensures code copy / pasted into Stackedit from a text editor is not mangled.
See #1364 for more info.

@GreenGremlin
Copy link
Contributor Author

Sorry for the late response.
What does this change fix? Can you illustrate the addressed issue?

Here's a more detailed breakdown of the issue.

Steps to reproduce

  1. Open code like javascript in a text editor like VSCode, Sublime, or any editor that supports copy / paste with syntax highlighting. e.g. When you copy / paste code into a word processor it maintains colors and fonts.
  2. Copy a block of code.
  3. Paste the block of code into Stackedit

Expected Result

The code is pasted in with formatting in-tact.

Actual Result

Indentation is stripped and extra blank lines are added.

@rehmatworks
Copy link

@benweet Will you please fix this issue and keep this awesome software usable? @GreenGremlin why was this PR closed? I'm desperately waiting for this fix and your PR seemed a hope.

@GreenGremlin
Copy link
Contributor Author

Because it's received no attention. I'd love to see this merged, but as far as I can tell this project is no longer maintained.

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

Successfully merging this pull request may close these issues.

Pasting code blocks messes up the formatting
5 participants