Class: Coradoc::Markdown::Extension
- Defined in:
- lib/coradoc/markdown/model/extension.rb
Overview
Represents a kramdown extension
Extension syntax: options / Common extensions:
{::toc} - table of contents
{::options key="value" /} - parser options
{::comment}content{:/} - comment
{::nomarkdown}content{:/} - raw HTML passthrough
Constant Summary collapse
- TYPES =
Known extension types
{ toc: :toc, options: :options, comment: :comment, nomarkdown: :nomarkdown, ignore: :ignore, if: :conditional, endif: :conditional }.freeze
Class Method Summary collapse
-
.comment(content = '') ⇒ Extension
Create a comment extension.
-
.nomarkdown(content) ⇒ Extension
Create a nomarkdown extension (passthrough).
-
.options(options = {}) ⇒ Extension
Create an options extension.
-
.toc(options = {}) ⇒ Extension
Create a TOC extension.
Instance Method Summary collapse
-
#self_closing? ⇒ Boolean
Check if this is a self-closing extension.
-
#to_md ⇒ String
Convert to Markdown.
-
#type?(type) ⇒ Boolean
Check if this is a specific extension type.
Methods inherited from Base
#serialize_content, #to_h, visit, #visit
Class Method Details
.comment(content = '') ⇒ Extension
Create a comment extension
48 49 50 |
# File 'lib/coradoc/markdown/model/extension.rb', line 48 def self.comment(content = '') new(name: :comment, content: content) end |
.nomarkdown(content) ⇒ Extension
Create a nomarkdown extension (passthrough)
55 56 57 |
# File 'lib/coradoc/markdown/model/extension.rb', line 55 def self.nomarkdown(content) new(name: :nomarkdown, content: content) end |
.options(options = {}) ⇒ Extension
Create an options extension
41 42 43 |
# File 'lib/coradoc/markdown/model/extension.rb', line 41 def self.( = {}) new(name: :options, options: ) end |
.toc(options = {}) ⇒ Extension
Create a TOC extension
34 35 36 |
# File 'lib/coradoc/markdown/model/extension.rb', line 34 def self.toc( = {}) new(name: :toc, options: ) end |
Instance Method Details
#self_closing? ⇒ Boolean
Check if this is a self-closing extension
68 69 70 |
# File 'lib/coradoc/markdown/model/extension.rb', line 68 def self_closing? content.nil? || content.empty? end |
#to_md ⇒ String
Convert to Markdown
74 75 76 77 78 79 80 81 |
# File 'lib/coradoc/markdown/model/extension.rb', line 74 def to_md opts = .empty? ? '' : " #{}" if self_closing? "{::#{name}#{opts} /}" else "{::#{name}#{opts}}#{content}{:/}" end end |
#type?(type) ⇒ Boolean
Check if this is a specific extension type
62 63 64 |
# File 'lib/coradoc/markdown/model/extension.rb', line 62 def type?(type) name.to_sym == type end |