Class: Presently::Slide::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/presently/slide.rb

Overview

A fragment of a Markly AST document.

Wraps a ‘Markly::Node` of type `:document` and provides rendering helpers. Used for both content sections and presenter notes so callers can choose their output format without the parser pre-committing to one.

Constant Summary collapse

EXTENSIONS =

Markly extensions enabled for all slide Markdown rendering.

[:table, :tasklist, :strikethrough, :autolink]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Fragment

Initialize a fragment from a Markly document node.



28
29
30
# File 'lib/presently/slide.rb', line 28

def initialize(node)
	@node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



33
34
35
# File 'lib/presently/slide.rb', line 33

def node
  @node
end

#The underlying AST document node.(underlyingASTdocumentnode.) ⇒ Object (readonly)



33
# File 'lib/presently/slide.rb', line 33

attr :node

Instance Method Details

#empty?Boolean

Whether the fragment has no content.

Returns:

  • (Boolean)


37
38
39
# File 'lib/presently/slide.rb', line 37

def empty?
	@node.first_child.nil?
end

#to_commonmarkObject Also known as: to_s

Render the fragment back to CommonMark Markdown.



51
52
53
# File 'lib/presently/slide.rb', line 51

def to_commonmark
	@node.to_commonmark
end

#to_htmlObject

Render the fragment to HTML using the Presently renderer.

Mermaid fenced code blocks are rendered as ‘<mermaid-diagram>` elements.



45
46
47
# File 'lib/presently/slide.rb', line 45

def to_html
	Renderer.new(flags: Markly::UNSAFE, extensions: EXTENSIONS).render(@node)
end