Skip to content

Overhaul HTML Formatter Delegation#2286

Merged
jneen merged 12 commits into
mainfrom
maint.html-table-legacy
May 16, 2026
Merged

Overhaul HTML Formatter Delegation#2286
jneen merged 12 commits into
mainfrom
maint.html-table-legacy

Conversation

@jneen
Copy link
Copy Markdown
Member

@jneen jneen commented May 4, 2026

Fixes #2279.

Reverts #1156 and #1083, and adds warning comments to all the HTML* formatters that take delegators.

In the above patches, there was a strict assumption that all HTML formatters were capable of being wrapped, which they are not, which caused all manner of confusion, extra newlines, extra wrapping tags, etc. In general, it is only safe to call the #span(tok, val) method of a delegator, which will yield precisely a span for that token. Calling #stream directly can be safe, but only for the non-nesting HTML formatters, which are HTML, HTMLInline, and HTMLDebug, which guarantee no newline-handling or wrapping of their input.

I have also added a temporary polyfill for #1082, with a deprecation warning. HTMLTable.new(...), when passed a Formatter other than one of the three non-nesting HTML formatters, will become an HTMLLegacyTable and warn. Those using that kind of nesting should maintain their own formatters for their application going into the future. Other unsupported combinations will raise. Users who have written their own formatters should not be affected by any of these changes.

If there is a desire for a more packaged approach, then others are welcome to publish a plugin with fancier HTML formatters. As it is, this stack is far too complicated for Rouge core.

Request for comment from @UlyssesZh, @mojavelinux, and @ashmaroli.

@jneen
Copy link
Copy Markdown
Member Author

jneen commented May 4, 2026

In particular, @mojavelinux, I think asciidoctor should be using a custom formatter. I am happy to contribute one.

@jneen
Copy link
Copy Markdown
Member Author

jneen commented May 4, 2026

Actually it looks like asciidoctor is using custom formatters, which is nice to see. It does seem to be passing an ignored parameter :inline_style into the plain Rouge::Formatters::HTML though.

Comment thread spec/formatters/html_linewise_spec.rb
@jneen jneen force-pushed the maint.html-table-legacy branch from e94b375 to 5d9590f Compare May 5, 2026 12:33
@jneen jneen force-pushed the maint.html-table-legacy branch from 5d9590f to 6fb8078 Compare May 15, 2026 22:24
@jneen jneen added this pull request to the merge queue May 16, 2026
Merged via the queue into main with commit 2a39d31 May 16, 2026
10 checks passed
@jneen jneen deleted the maint.html-table-legacy branch May 16, 2026 04:47
@jneen jneen mentioned this pull request May 26, 2026
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.

HTML formatter stack is in a very confusing state

2 participants