Class: Markbridge::Parsers::BBCode::Handlers::AttachmentHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Markbridge::Parsers::BBCode::Handlers::AttachmentHandler
- Defined in:
- lib/markbridge/parsers/bbcode/handlers/attachment_handler.rb
Overview
Handler for ATTACH/ATTACHMENT tags across platforms (phpBB, vBulletin, XenForo, SMF mods).
Examples:
- attachment=0]image.jpg[/attachment
-
# phpBB (index + filename)
- ATTACH=CONFIG]1234[/ATTACH
-
# vBulletin (id)
- ATTACH type=“full” alt=“diagram”]5678[/ATTACH
-
# XenForo (id + alt)
- attach id=2 msg=9876
-
# SMF-style self-contained attributes
Instance Attribute Summary
Attributes inherited from BaseHandler
Instance Method Summary collapse
-
#initialize(collector: RawContentCollector.new) ⇒ AttachmentHandler
constructor
A new instance of AttachmentHandler.
-
#on_close(token:, context:, registry:, tokens: nil) ⇒ Object
Closing tags are consumed during collection; if one leaks through, treat as text.
- #on_open(token:, context:, registry:, tokens: nil) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize(collector: RawContentCollector.new) ⇒ AttachmentHandler
Returns a new instance of AttachmentHandler.
15 16 17 18 |
# File 'lib/markbridge/parsers/bbcode/handlers/attachment_handler.rb', line 15 def initialize(collector: RawContentCollector.new) @collector = collector @element_class = AST::Attachment end |
Instance Method Details
#on_close(token:, context:, registry:, tokens: nil) ⇒ Object
Closing tags are consumed during collection; if one leaks through, treat as text.
28 29 30 |
# File 'lib/markbridge/parsers/bbcode/handlers/attachment_handler.rb', line 28 def on_close(token:, context:, registry:, tokens: nil) context.add_child(AST::Text.new(token.source)) end |
#on_open(token:, context:, registry:, tokens: nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/markbridge/parsers/bbcode/handlers/attachment_handler.rb', line 20 def on_open(token:, context:, registry:, tokens: nil) content = collect_content(token:, tokens:) = (token:, content:) context.add_child() end |