Class: GfmToBlockkit::Converters::Base
- Inherits:
-
Object
- Object
- GfmToBlockkit::Converters::Base
- Defined in:
- lib/gfm_to_blockkit/converters/base.rb
Direct Known Subclasses
BlockQuote, CodeBlock, FootnoteDefinition, Heading, HtmlBlock, Image, List, Paragraph, Table, Table::Native, Table::Preformatted, ThematicBreak
Class Attribute Summary collapse
-
.registry ⇒ Object
readonly
Returns the value of attribute registry.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(node) ⇒ Object
-
#initialize(context) ⇒ Base
constructor
A new instance of Base.
-
#render_child_as_elements(node) ⇒ Object
Render a block-level child node as an array of rich text inline elements.
Constructor Details
#initialize(context) ⇒ Base
Returns a new instance of Base.
20 21 22 |
# File 'lib/gfm_to_blockkit/converters/base.rb', line 20 def initialize(context) @context = context end |
Class Attribute Details
.registry ⇒ Object (readonly)
Returns the value of attribute registry.
9 10 11 |
# File 'lib/gfm_to_blockkit/converters/base.rb', line 9 def registry @registry end |
Class Method Details
.converter_for(node_type) ⇒ Object
15 16 17 |
# File 'lib/gfm_to_blockkit/converters/base.rb', line 15 def converter_for(node_type) registry[node_type] end |
Instance Method Details
#convert(node) ⇒ Object
24 25 26 |
# File 'lib/gfm_to_blockkit/converters/base.rb', line 24 def convert(node) raise NotImplementedError, "#{self.class} must implement #convert" end |
#render_child_as_elements(node) ⇒ Object
Render a block-level child node as an array of rich text inline elements. This is the shared path used by any converter that needs to represent block-level children inside a rich_text container (blockquotes, list items, etc.) rather than emitting top-level Block Kit blocks.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gfm_to_blockkit/converters/base.rb', line 33 def render_child_as_elements(node) case node.type when :paragraph rich_text_renderer.render(node) when :code_block [{type: "text", text: node.string_content.chomp, style: {code: true}}] when :heading [{type: "text", text: plain_text_from(node), style: {bold: true}}] else rendered = rich_text_renderer.render(node) rendered.empty? ? nil : rendered end end |