Class: TipTap::Nodes::Codeblock
- Inherits:
-
TipTap::Node
- Object
- TipTap::Node
- TipTap::Nodes::Codeblock
- Defined in:
- lib/tip_tap/nodes/codeblock.rb
Instance Attribute Summary
Attributes included from HtmlRenderable
Attributes included from HasContent
Instance Method Summary collapse
Methods included from PlainTextRenderable
Methods included from JsonRenderable
#include_empty_content_in_json?, #to_h
Methods included from HtmlRenderable
#html_attributes, #html_class_name, #html_tag, included, #inline_styles, #to_html
Methods included from HasContent
#add_content, #blank?, #each, #find_node, included, #initialize, #size
Methods included from Registerable
Instance Method Details
#code(text) ⇒ Object
11 12 13 |
# File 'lib/tip_tap/nodes/codeblock.rb', line 11 def code(text) add_content(Text.new(text, marks: [{type: "code"}])) end |
#to_markdown(context = Markdown::Context.root) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/tip_tap/nodes/codeblock.rb', line 15 def to_markdown(context = Markdown::Context.root) fence_language = attrs["language"].presence || attrs["lang"].presence fence_header = "```#{fence_language}" code_context = context.with_code_block body = content.map { |node| node.to_markdown(code_context) }.join body = "#{body}\n" unless body.end_with?("\n") || body.empty? "#{fence_header}\n#{body}```" end |