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

Incorrect space-padding in code span rule #316

Closed
martincizek opened this issue Mar 31, 2020 · 0 comments · Fixed by #317
Closed

Incorrect space-padding in code span rule #316

martincizek opened this issue Mar 31, 2020 · 0 comments · Fixed by #317

Comments

@martincizek
Copy link
Collaborator

As CommonMark spec 6.3 states, a single space character is removed from the front and back if the string both begins and ends with a space character (shortened).

But rules.code adds spaces independently, which means false spaces can be introduced into the resulting code span.

The corresponding test is actually expecting a wrong value adding a leading space to code when converted back:

  <div class="input"><code>`starting with a backtick</code></div>
  <!-- currently expected -->
  <pre class="expected">`` `starting with a backtick``</pre>

While the right output is:

  <!-- should be expected -->
  <pre class="expected">`` `starting with a backtick ``</pre>

Also, the current rule is written quite robust in several aspects - trim() suggests that whitespace-only content may come in and multiline regexp flag suggests that even newlines may come in. None of that is really relevant in current Turndown, but to keep the rule robust:

  • There is no reason to reject non-empty whitespace-only string - it would make also a valid code span if it wasn't rejected by isBlank and wasn't trimmed to empty string before.
  • Leading and trailing space should be also considered for decision regarding extra space if the incoming content was not trimmed before.
  • Newlines should be converted to spaces if they were not converted by collapse-whitespace.js before.

Disclosure: our next contributions are going to build on this robustness.

martincizek added a commit to orchitech/turndown that referenced this issue Mar 31, 2020
martincizek added a commit to orchitech/turndown that referenced this issue Apr 1, 2020
martincizek added a commit to orchitech/turndown that referenced this issue Jul 6, 2020
martincizek added a commit to orchitech/turndown that referenced this issue Jul 6, 2020
martincizek added a commit to orchitech/turndown that referenced this issue Jul 6, 2020
martincizek added a commit to orchitech/turndown that referenced this issue Jul 6, 2020
michbart pushed a commit to orchitech/turndown that referenced this issue Nov 30, 2020
michbart pushed a commit to orchitech/turndown that referenced this issue Nov 30, 2020
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 a pull request may close this issue.

1 participant