Skip to content

FIX: Add table tag passthrough support and fix quote trailing newlines#4

Open
RubenOussoren wants to merge 5 commits intomainfrom
dev/table-tag-support
Open

FIX: Add table tag passthrough support and fix quote trailing newlines#4
RubenOussoren wants to merge 5 commits intomainfrom
dev/table-tag-support

Conversation

@RubenOussoren
Copy link
Copy Markdown
Contributor

  • 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

@RubenOussoren RubenOussoren requested a review from gschlager March 10, 2026 19:43
@RubenOussoren RubenOussoren self-assigned this Mar 10, 2026
@RubenOussoren RubenOussoren force-pushed the dev/table-tag-support branch from 52e9b52 to 001c5c2 Compare March 10, 2026 19:47
@gschlager gschlager force-pushed the main branch 11 times, most recently from c8531b1 to e9c9544 Compare March 20, 2026 17:06
- 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
@gschlager gschlager force-pushed the dev/table-tag-support branch from 001c5c2 to 66379b3 Compare March 20, 2026 19:20
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
@gschlager
Copy link
Copy Markdown
Member

Discourse which has no table syntax

Discourse supports both Markdown and HTML tables, so we should aim to preserve tables rather than flatten or discard them.

Add [IMG2] BBCode handler for vBulletin 5 enhanced image tags

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.

@gschlager
Copy link
Copy Markdown
Member

@RubenOussoren I've been thinking about where the IMG2 handler should live: Since [IMG2] is vBulletin 5-specific, I'd rather keep it out of the gem's default registry and handle it in our converter instead. That way the gem stays focused on standard BBCode tags.

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 ImageHandler. It already does the raw content collection and builds AST::Image nodes. The only thing we need to override is create_element for the JSON extraction:

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants