Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes
Markup.trim
andMarkup.pretty_print
to respect whitespace in HTML phrasing ("inline") content. So, applyingMarkup.trim
toproduces
and, notionally the inverse, applying
Markup.pretty_print
toproduces
The important thing is that
Markup.trim
did not remove whitespace around</em>
, andMarkup.pretty_print
did not introduce whitespace around</em>
. This preserves the word breaks in the HTML.I went for the simplest possible pretty-printer that is correct with respect to word breaks. It doesn't try to limit the line length or do anything else that could be considered fancy. It just indents the flow ("block") content, and passes phrasing ("inline", word) content straight through. This can result in long lines, but we can adjust that later with more elaborate implementations. The point is that from now, no matter how simple or fancy, or how nice or ugy the output looks,
Markup.pretty_print
should be correct and safe to use on HTML, modulo bugs :)As an aside, pretty-printing HTML is not correct in the general case, because the significance of whitespace in each element is up to CSS, and that is outside HTML. Each pretty-printer basically has to make a guess that the input is valid, and that the CSS uses the default interpretations of whitespace for each kind of element.
cc @Ostera, @Drup
Resolves #35.