Module: Metanorma::Mirror::Output::HtmlRenderers::BlockRenderers
- Included in:
- Metanorma::Mirror::Output::HtmlRenderer
- Defined in:
- lib/metanorma/mirror/output/html_renderers/block_renderers.rb
Constant Summary collapse
- ADMONITION_TITLES =
{ "danger" => "Danger", "caution" => "Caution", "warning" => "Warning", "important" => "Important", "safety precautions" => "Safety Precautions", "editorial" => "Editorial", "tip" => "Tip", "note" => "Note", "commentary" => "Commentary" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #render_admonition(node, depth: 0) ⇒ Object
- #render_example(node, depth: 0) ⇒ Object
- #render_figure(node, depth: 0) ⇒ Object
- #render_formula(node, depth: 0) ⇒ Object
- #render_image(node, depth: 0) ⇒ Object
- #render_note(node, depth: 0) ⇒ Object
- #render_paragraph(node, depth: 0) ⇒ Object
- #render_quote(node, depth: 0) ⇒ Object
- #render_review(_node, depth: 0) ⇒ Object
- #render_sourcecode(node, depth: 0) ⇒ Object
- #render_term(node, depth: 0) ⇒ Object
Class Method Details
.register(registry) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 17 def self.register(registry) registry.register_node_handler("paragraph", instance_method(:render_paragraph)) registry.register_node_handler("note", instance_method(:render_note)) registry.register_node_handler("admonition", instance_method(:render_admonition)) registry.register_node_handler("example", instance_method(:render_example)) registry.register_node_handler("figure", instance_method(:render_figure)) registry.register_node_handler("image", instance_method(:render_image)) registry.register_node_handler("sourcecode", instance_method(:render_sourcecode)) registry.register_node_handler("formula", instance_method(:render_formula)) registry.register_node_handler("quote", instance_method(:render_quote)) registry.register_node_handler("review", instance_method(:render_review)) registry.register_node_handler("term", instance_method(:render_term)) end |
Instance Method Details
#render_admonition(node, depth: 0) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 63 def render_admonition(node, depth: 0) adm_type = node.attrs["type"] || "note" title = ADMONITION_TITLES[adm_type] || adm_type.capitalize HtmlRenderers.build do |doc| attrs = { class: "mn-admonition mn-admonition--#{adm_type}" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.div(attrs) do doc.div(class: "admonition-content") do doc.div(class: "admonition-title") { doc.text title } HtmlRenderers.(doc, render_children(node, depth:)) end end end end |
#render_example(node, depth: 0) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 79 def render_example(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-example" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.div(attrs) do HtmlRenderers.(doc, render_children(node, depth:)) end end end |
#render_figure(node, depth: 0) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 89 def render_figure(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-figure" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.figure(attrs) do HtmlRenderers.(doc, render_children(node, depth:)) if node.attrs["title"] doc.figcaption { doc.text node.attrs["title"] } end end end end |
#render_formula(node, depth: 0) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 131 def render_formula(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-formula" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.div(attrs) do doc.span(class: "formula-math") do math = node.attrs["mathml"] if math HtmlRenderers.(doc, math) elsif node.attrs["asciimath"] doc.text node.attrs["asciimath"] else doc.text node.attrs["math_text"] || "" end end end end end |
#render_image(node, depth: 0) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 102 def render_image(node, depth: 0) HtmlRenderers.build do |doc| attrs = { src: node.attrs["src"] || "", alt: node.attrs["alt"] || "", loading: "lazy", } attrs[:height] = node.attrs["height"] if node.attrs["height"] attrs[:width] = node.attrs["width"] if node.attrs["width"] doc.img(attrs) end end |
#render_note(node, depth: 0) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 52 def render_note(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-note" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.div(attrs) do doc.div(class: "note-title") { doc.text "Note" } HtmlRenderers.(doc, render_children(node, depth:)) end end end |
#render_paragraph(node, depth: 0) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 42 def render_paragraph(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-paragraph" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.p(attrs) do HtmlRenderers.(doc, render_inline(node.content)) end end end |
#render_quote(node, depth: 0) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 150 def render_quote(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-quote" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.blockquote(attrs) do HtmlRenderers.(doc, render_children(node)) end end end |
#render_review(_node, depth: 0) ⇒ Object
160 161 162 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 160 def render_review(_node, depth: 0) "" end |
#render_sourcecode(node, depth: 0) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 115 def render_sourcecode(node, depth: 0) lang = node.attrs["language"] lang_class = lang ? " language-#{lang}" : "" HtmlRenderers.build do |doc| attrs = { class: "mn-sourcecode#{lang_class}" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.div(attrs) do doc.span(class: "code-language-badge") { doc.text lang } if lang doc.pre(class: "code-block") do doc.code { doc.text node.attrs["text"] || "" } end end end end |
#render_term(node, depth: 0) ⇒ Object
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/metanorma/mirror/output/html_renderers/block_renderers.rb', line 164 def render_term(node, depth: 0) HtmlRenderers.build do |doc| attrs = { class: "mn-term" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.div(attrs) do HtmlRenderers.(doc, render_children(node, depth: depth + 1)) end end end |