Class: Markbridge::Parsers::BBCode::Parser
- Inherits:
-
Object
- Object
- Markbridge::Parsers::BBCode::Parser
- Defined in:
- lib/markbridge/parsers/bbcode/parser.rb
Overview
Parses BBCode into an AST using handlers from HandlerRegistry
Instance Attribute Summary collapse
-
#auto_closed_tags_count ⇒ Object
readonly
Returns the value of attribute auto_closed_tags_count.
-
#depth_exceeded_count ⇒ Object
readonly
Returns the value of attribute depth_exceeded_count.
-
#unclosed_raw_tags ⇒ Object
readonly
Returns the value of attribute unclosed_raw_tags.
-
#unknown_tags ⇒ Object
readonly
Returns the value of attribute unknown_tags.
Instance Method Summary collapse
-
#initialize(handlers: nil) {|HandlerRegistry| ... } ⇒ Parser
constructor
Create a new parser with optional custom handlers.
-
#parse(input) ⇒ AST::Document
Parse BBCode string into an AST.
Constructor Details
#initialize(handlers: nil) {|HandlerRegistry| ... } ⇒ Parser
Create a new parser with optional custom handlers
24 25 26 27 28 29 30 31 32 |
# File 'lib/markbridge/parsers/bbcode/parser.rb', line 24 def initialize(handlers: nil, &block) @handlers = if block_given? HandlerRegistry.build_from_default(&block) else handlers || HandlerRegistry.default end @unknown_tags = Hash.new(0) end |
Instance Attribute Details
#auto_closed_tags_count ⇒ Object (readonly)
Returns the value of attribute auto_closed_tags_count.
8 9 10 |
# File 'lib/markbridge/parsers/bbcode/parser.rb', line 8 def @auto_closed_tags_count end |
#depth_exceeded_count ⇒ Object (readonly)
Returns the value of attribute depth_exceeded_count.
8 9 10 |
# File 'lib/markbridge/parsers/bbcode/parser.rb', line 8 def depth_exceeded_count @depth_exceeded_count end |
#unclosed_raw_tags ⇒ Object (readonly)
Returns the value of attribute unclosed_raw_tags.
8 9 10 |
# File 'lib/markbridge/parsers/bbcode/parser.rb', line 8 def @unclosed_raw_tags end |
#unknown_tags ⇒ Object (readonly)
Returns the value of attribute unknown_tags.
8 9 10 |
# File 'lib/markbridge/parsers/bbcode/parser.rb', line 8 def @unknown_tags end |
Instance Method Details
#parse(input) ⇒ AST::Document
Parse BBCode string into an AST
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/markbridge/parsers/bbcode/parser.rb', line 37 def parse(input) @unknown_tags.clear normalized = normalize_line_endings(input) document = AST::Document.new context = ParserState.new(document) scanner = Scanner.new(normalized) parse_tokens(scanner, context) @auto_closed_tags_count = context.auto_closed_count @depth_exceeded_count = context.depth_exceeded_count @unclosed_raw_tags = context. document end |