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

Avoid empty last line in editable code blocks #1836

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

mgeisler
Copy link
Contributor

@mgeisler mgeisler commented Jun 29, 2022

Before, a code block would always end with a final newline. The newline was added unconditionally by hide_lines.

When the code block is syntax highlighted by highlight.js, this is not a problem, no empty line is added for a final trailing \n character. However, when the code block is editable and thus handled by the ACE editor, a trailing newline is significant. I believe this issue is most closely described by ajaxorg/ace#2083 in the upstream repository.

The effect of the way ACE handles newlines is that a code block like

<pre>
  Some code
</pre>

will create an editor with two lines, not just one.

By trimming trailing whitespace, we ensure that we don’t accidentally create more lines in the ACE editor than necessary.

Before

After

@mgeisler mgeisler changed the title Trim trailing whitespace in Rust code blocks Avoid empty last line in editable code blocks Jun 29, 2022
@mgeisler
Copy link
Contributor Author

mgeisler commented Aug 9, 2022

@ehuss or others, would you be able to review this? I would love to help make mdBook look more uniform.

Before, a code block would always end with a final newline. The
newline was added unconditionally by `hide_lines`.

When the code block is syntax highlighted by highlight.js, this is not
a problem, no empty line is added for a final trailing `\n` character.
However, when the code block is editable and thus handled by the ACE
editor, a trailing newline _is_ significant. I believe this issue is
most closely described by ajaxorg/ace#2083
in the upstream repository.

The effect of the way ACE handles newlines is that a code block like

    <pre>
      Some code
    </pre>

will create an editor with _two_ lines, not just one.

By trimming trailing whitespace, we ensure that we don’t accidentally
create more lines in the ACE editor than necessary.
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ehuss ehuss merged commit fff067b into rust-lang:master Aug 11, 2022
@mgeisler
Copy link
Contributor Author

Thanks!

Thanks for the review!

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.

2 participants