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

resolves #1082 HTMLTable formatter delegates to format method of inner formatter #1083

Conversation

mojavelinux
Copy link
Contributor

resolves #1082

  • HTMLTable formatter delegates to format method of inner formatter instead of span method
  • append trailing newline if missing (but don't wrap as whitespace token)
  • add test

@mojavelinux
Copy link
Contributor Author

Note that this line wasn't doing anything:

@inner.span(Token::Tokens::Text::Whitespace, "\n") { |str| formatted << str }

I've restored the functionality of appending the newline, but I decided not to format it as whitespace. That makes the formatting inconsistent with how other newlines are handled.

@mojavelinux
Copy link
Contributor Author

Is it really necessary to yield more than once? I'd like to write the yield statement as follows:

yield %(<table class="#{@table_class}"><tbody><tr><td class="#{@gutter_class} gl"><pre class="lineno">#{formatted_line_numbers}</pre></td><td class="#{@code_class}"><pre>#{formatted}</pre></td></tr></tbody></table>)

@pyrmont
Copy link
Contributor

pyrmont commented May 28, 2019

@mojavelinux This is separate to #1085, right? Will that have any impact on this?

@pyrmont pyrmont added the author-action The PR has been reviewed but action by the author is needed label May 28, 2019
@mojavelinux mojavelinux force-pushed the issue-1082-html-table-formatter-delegation branch from 1388482 to 159bb0f Compare May 29, 2019 09:19
@mojavelinux
Copy link
Contributor Author

Yes, this is separate from #1085. However, the whole purpose of this change is so that it can be used in combination with the line-wise formatter.

I'd still like to avoid the multiple yields, so I'm interested in getting feedback on that aspect. Yielding multiple times just seems wasteful.

@pyrmont
Copy link
Contributor

pyrmont commented May 29, 2019

@mojavelinux I wonder if the multiple yields are a way of making the HTML easier to read without breaking the tests? When I try to use HEREDOC syntax with a single yield (or just insert newlines into your proposed single yield statement) the Rouge::Formatters::HTMLLinewise spec fails. What do you think?

@mojavelinux
Copy link
Contributor Author

@pyrmont I'm fine with splitting up the string to make it easier to read, but the multiple calls to yield introduce a different contract. Whatever it's yielding to is now receiving disconnected fragments of HTML instead of something whole, making it virtually impossible to do anything meaningful with them. I think the HTML needs to be assembled first, then yielded. We're mixing style with function here.

@mojavelinux
Copy link
Contributor Author

I'll make an attempt to yield once and verify we can still pass the tests.

…od of inner formatter

- HTMLTable formatter delegates to format method of inner formatter instead of span method
- append trailing newline if missing (but don't wrap as whitespace token)
- add test
- only yield once in stream method of HTMLTable formatter
@mojavelinux mojavelinux force-pushed the issue-1082-html-table-formatter-delegation branch from 159bb0f to dcd2ded Compare June 1, 2019 23:39
@mojavelinux
Copy link
Contributor Author

I've updated as we discussed and all tests are passing.

@pyrmont pyrmont merged commit a050f9e into rouge-ruby:master Jun 2, 2019
@pyrmont
Copy link
Contributor

pyrmont commented Jun 2, 2019

Thanks @mojavelinux :)

@pyrmont pyrmont removed the author-action The PR has been reviewed but action by the author is needed label Jun 2, 2019
@mojavelinux mojavelinux deleted the issue-1082-html-table-formatter-delegation branch June 2, 2019 08:44
@ashmaroli
Copy link
Contributor

@mojavelinux Is there a possibility that this introduced an extra newline at the end of the rendered output?

Failure:
TestTags#test_: with the rouge highlighter post content has highlight tag should render markdown with rouge with line numbers.  [/home/travis/build/jekyll/jekyll/test/test_tags.rb:151]
Minitest::Assertion:

Expected
  /<table\ class="rouge\-table"><tbody><tr><td\ class="gutter\ gl"><pre\ class="lineno">1\n<\/pre><\/td><td\ class="code"><pre>test<\/pre><\/td><\/tr><\/tbody><\/table>/

to match
  "<table class=\"rouge-table\"><tbody><tr><td class=\"gutter gl\"><pre class=\"lineno\">1\n</pre></td><td class=\"code\"><pre>test\n</pre></td></tr></tbody></table>".

@mojavelinux
Copy link
Contributor Author

Yes, I believe so. It's this line: https://github.com/rouge-ruby/rouge/blob/master/lib/rouge/formatters/html_table.rb#L29. I don't remember whether that was supposed to be part of this PR or not. The rationale is that it's important for the end of the lines stay clean to allow postprocessing to operate on all lines in the same way. When the closing </pre> bumps up against the last line, it requires special processing. The browser always ignores this trailing newline. (Notice the lineno pre is already this way).

@mojavelinux
Copy link
Contributor Author

I'd recommend updating the test in Jekyll to make this trailing newline optional in the assertion.

@ashmaroli
Copy link
Contributor

The rationale is that it's important for the end of the lines stay clean to allow postprocessing to operate on all lines in the same way. When the closing </pre> bumps up against the last line, it requires special processing.

I see.. Thanks for the above insight.

@ashmaroli
Copy link
Contributor

@mojavelinux One more question: What is ?\n supposed to be? I see it repeated multiple times. Are all of them the same object or can it be stashed in a class constant?

@pyrmont
Copy link
Contributor

pyrmont commented Jun 3, 2019

It's a character literal.

@mojavelinux
Copy link
Contributor Author

...and it's effectively a constant.

@ashmaroli
Copy link
Contributor

It's a character literal.

...and it's effectively a constant.

TIL 🥂 to both of you 😄

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.

HTMLTable formatter cannot wrap HTMLLinewise formatter
3 participants