FIX: Add table tag passthrough support and fix quote trailing newlines#4
FIX: Add table tag passthrough support and fix quote trailing newlines#4RubenOussoren wants to merge 5 commits intomainfrom
Conversation
RubenOussoren
commented
Mar 10, 2026
- Add AST classes Table, TableRow, TableCell (passthrough: strip wrapper tags, preserve cell content for Discourse which has no table syntax)
- Register table/tr/td/th handlers in BBCode handler registry
- Register passthrough renderer tags in Discourse TagLibrary
- Append \n\n after named [quote] blocks to ensure paragraph separation
- Add unit specs for Table/TableRow/TableCell AST classes
- Add TagLibrary registration tests for all three table classes
- Pin table system tests to exact eq outputs; add empty/whitespace-cell edge cases
52e9b52 to
001c5c2
Compare
c8531b1 to
e9c9544
Compare
- Add AST classes Table, TableRow, TableCell (passthrough: strip wrapper tags, preserve cell content for Discourse which has no table syntax) - Register table/tr/td/th handlers in BBCode handler registry - Register passthrough renderer tags in Discourse TagLibrary - Append \n\n after named [quote] blocks to ensure paragraph separation - Add unit specs for Table/TableRow/TableCell AST classes - Add TagLibrary registration tests for all three table classes - Pin table system tests to exact eq outputs; add empty/whitespace-cell edge cases Made-with: Cursor
001c5c2 to
66379b3
Compare
Parse [IMG2=JSON]{'src':'...'}[/IMG2] tags by extracting the src URL
from the JSON payload and producing AST::Image nodes. Also handles
bare [IMG2]url[/IMG2] without JSON. Includes unit and integration tests.
…Presenter - Use Ruby 3.1+ hash shorthand in Img2Handler (src: instead of src: src) - Fix img2_handler_spec to use AST::Text#text instead of nonexistent #value - Add Table to ASTPresenter's CATEGORY_MAP and ICON_MAP
Discourse supports both Markdown and HTML tables, so we should aim to preserve tables rather than flatten or discard them.
I need to think this through. I’m torn between two approaches: either keeping this out of the gem and handling it at a higher level (e.g. in our converter), or introducing configurable BBCode dialects that can extend or override handlers as needed. |
|
@RubenOussoren I've been thinking about where the IMG2 handler should live: Since The good news is the registry pattern makes this easy: require "markbridge"
require_relative "img2_handler"
parser = Markbridge::Parsers::BBCode::Parser.new do |registry|
registry.register("img2", Img2Handler.new)
end
ast = parser.parse('[IMG2=JSON]{"src":"https://example.com/photo.jpg"}[/IMG2]')
puts Markbridge::Renderers::Discourse::Renderer.new.render(ast)Or using the top-level API: handlers = Markbridge::Parsers::BBCode::HandlerRegistry.default
handlers.register("img2", Img2Handler.new)
markdown = Markbridge.bbcode_to_markdown(input, handlers:)I think that the handler itself could also be simplified quite a bit by extending class Img2Handler < ImageHandler
private
def create_element(token:, content:)
src = if token.attrs[:option]&.downcase == "json" && content.start_with?("{")
$1 if content =~ /"src"\s*:\s*"([^"]+)"/
else
content
end
return AST::Text.new(token.source) if src.nil? || src.empty?
AST::Image.new(src:)
end
end The handler code can just move to the converter repo as-is. And if we end up with more vBulletin-specific handlers down the road, we can always bundle them together there. Regarding table support: I've got a separate PR up (#13) that renders tables as Markdown pipe-tables with HTML fallback for complex cases, rather than the passthrough approach. Still needs more testing, but that should cover it. What do you think? |