Class: RedQuilt::Document
- Inherits:
-
Object
- Object
- RedQuilt::Document
- Defined in:
- lib/red_quilt/document.rb
Instance Attribute Summary collapse
-
#arena ⇒ Object
readonly
Returns the value of attribute arena.
-
#footnotes ⇒ Object
readonly
Returns the value of attribute footnotes.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#root_id ⇒ Object
readonly
Returns the value of attribute root_id.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #allow_html? ⇒ Boolean
-
#diagnostics ⇒ Object
Returns the array of diagnostics collected during parse / render.
-
#disallow_raw_html? ⇒ Boolean
When true, raw HTML output filters the 9 dangerous tags defined by GFM’s “Disallowed Raw HTML” extension (title, textarea, style, xmp, iframe, noembed, noframes, script, plaintext) by replacing their leading ‘<` with `<`.
-
#first_heading_text ⇒ Object
Returns the plain-text content of the first HEADING in the document, or nil if there is no heading.
-
#initialize(source, arena, root_id, allow_html: false, disallow_raw_html: false, references: {}, footnotes: nil) ⇒ Document
constructor
A new instance of Document.
- #root ⇒ Object
- #source_map ⇒ Object
- #to_ast ⇒ Object
-
#to_html(standalone: false, title: nil, lang: "en", css: nil, theme: :none) ⇒ Object
Renders the document to HTML.
- #to_json ⇒ Object
- #to_mdast ⇒ Object
- #walk ⇒ Object
Constructor Details
#initialize(source, arena, root_id, allow_html: false, disallow_raw_html: false, references: {}, footnotes: nil) ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 12 13 14 15 |
# File 'lib/red_quilt/document.rb', line 7 def initialize(source, arena, root_id, allow_html: false, disallow_raw_html: false, references: {}, footnotes: nil) @source = source @arena = arena @root_id = root_id @allow_html = allow_html @disallow_raw_html = disallow_raw_html @references = references @footnotes = footnotes end |
Instance Attribute Details
#arena ⇒ Object (readonly)
Returns the value of attribute arena.
5 6 7 |
# File 'lib/red_quilt/document.rb', line 5 def arena @arena end |
#footnotes ⇒ Object (readonly)
Returns the value of attribute footnotes.
5 6 7 |
# File 'lib/red_quilt/document.rb', line 5 def footnotes @footnotes end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
5 6 7 |
# File 'lib/red_quilt/document.rb', line 5 def references @references end |
#root_id ⇒ Object (readonly)
Returns the value of attribute root_id.
5 6 7 |
# File 'lib/red_quilt/document.rb', line 5 def root_id @root_id end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/red_quilt/document.rb', line 5 def source @source end |
Instance Method Details
#allow_html? ⇒ Boolean
17 18 19 |
# File 'lib/red_quilt/document.rb', line 17 def allow_html? @allow_html end |
#diagnostics ⇒ Object
Returns the array of diagnostics collected during parse / render. The array is mutable and shared with the parser / renderer; new entries appear here without further calls.
82 83 84 |
# File 'lib/red_quilt/document.rb', line 82 def diagnostics @diagnostics ||= [] end |
#disallow_raw_html? ⇒ Boolean
When true, raw HTML output filters the 9 dangerous tags defined by GFM’s “Disallowed Raw HTML” extension (title, textarea, style, xmp, iframe, noembed, noframes, script, plaintext) by replacing their leading ‘<` with `<`. Only meaningful when allow_html? is true; when allow_html? is false everything is already escaped.
26 27 28 |
# File 'lib/red_quilt/document.rb', line 26 def disallow_raw_html? @disallow_raw_html end |
#first_heading_text ⇒ Object
Returns the plain-text content of the first HEADING in the document, or nil if there is no heading. Used by callers (e.g. the CLI’s –auto-title) to derive a document title.
71 72 73 |
# File 'lib/red_quilt/document.rb', line 71 def first_heading_text first_heading_text_walk(@root_id) end |
#root ⇒ Object
30 31 32 |
# File 'lib/red_quilt/document.rb', line 30 def root NodeRef.new(self, @root_id) end |
#source_map ⇒ Object
75 76 77 |
# File 'lib/red_quilt/document.rb', line 75 def source_map @source_map ||= SourceMap.new(@source) end |
#to_ast ⇒ Object
55 56 57 |
# File 'lib/red_quilt/document.rb', line 55 def to_ast root.to_h end |
#to_html(standalone: false, title: nil, lang: "en", css: nil, theme: :none) ⇒ Object
Renders the document to HTML.
standalone: when true, wrap the rendered body in a ‘<!DOCTYPE html>`
template with `<head>` (charset / title / optional stylesheet)
and `<body>`. When false (the default), only the rendered body
fragment is returned.
title / lang / css / theme: applied only when standalone is true. theme: a bundled stylesheet to inline (‘:none` embeds nothing, keeping
the bare template; `:default` embeds RedQuilt's default theme). `css`
(an external stylesheet link) is independent and may be combined.
48 49 50 51 52 53 |
# File 'lib/red_quilt/document.rb', line 48 def to_html(standalone: false, title: nil, lang: "en", css: nil, theme: :none) body = Renderer::HTML.new(self).render return body unless standalone wrap_standalone_html(body, title: title.to_s, lang: lang.to_s, css: css, theme: Theme.css(theme)) end |
#to_json ⇒ Object
59 60 61 62 |
# File 'lib/red_quilt/document.rb', line 59 def to_json(*) require "json" JSON.pretty_generate(to_mdast) end |
#to_mdast ⇒ Object
64 65 66 |
# File 'lib/red_quilt/document.rb', line 64 def to_mdast Renderer::Mdast.new(self).render end |
#walk ⇒ Object
34 35 36 |
# File 'lib/red_quilt/document.rb', line 34 def walk(&) root.walk(&) end |