Class: NRSER::MeanStreak
- Defined in:
- lib/nrser/mean_streak.rb,
lib/nrser/mean_streak/document.rb
Overview
Declarations
Defined Under Namespace
Classes: Document
Instance Attribute Summary collapse
-
#type_renderers ⇒ Hash<Symbol, Proc>
readonly
TODO document ‘type_renderers` attribute.
Class Method Summary collapse
-
.default ⇒ NRSER::MeanStreak
Get the default instance, which has the default configuration and is used by the class methods.
-
.parse(source, options = :DEFAULT, extensions = []) ⇒ CommonMarker::Node
Public: Parses a Markdown string into a ‘document` node.
Instance Method Summary collapse
-
#initialize(&block) ⇒ MeanStreak
constructor
A new instance of MeanStreak.
- #parse(source, **options) ⇒ Object
-
#render(doc_or_source) ⇒ String
Render a Document or a source string.
-
#render_type(type, &renderer) ⇒ Object
Instance Methods ============================================================================.
Constructor Details
#initialize(&block) ⇒ MeanStreak
Returns a new instance of MeanStreak.
79 80 81 82 |
# File 'lib/nrser/mean_streak.rb', line 79 def initialize &block @type_renderers = {} block.call( self ) if block end |
Instance Attribute Details
Class Method Details
.default ⇒ NRSER::MeanStreak
Get the default instance, which has the default configuration and is used by the class methods.
51 52 53 54 |
# File 'lib/nrser/mean_streak.rb', line 51 def self.default # TODO cache? new end |
.parse(source, options = :DEFAULT, extensions = []) ⇒ CommonMarker::Node
66 67 68 |
# File 'lib/nrser/mean_streak.rb', line 66 def self.parse source, = :DEFAULT, extensions = [] default.parse source, cm_options: , cm_extensions: extensions end |
Instance Method Details
#parse(source, **options) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/nrser/mean_streak.rb', line 93 def parse source, ** NRSER::MeanStreak::Document.parse \ source, **, mean_streak: self end |
#render(doc_or_source) ⇒ String
Render a Document or a source string.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/nrser/mean_streak.rb', line 109 def render doc_or_source case doc_or_source when NRSER::MeanStreak::Document doc_or_source.render when '' # Short-circuit for empty strings because CommonMark's document # node for empty strings returns a weird `#sourcepos` that ends before it # begins (start: line 1, column 1; end: line 0, column 0). # # Going to protect against line 0 / column 0 in # {NRSER::MeanStreak::Document#source_byte_indexes} too but since the # empty strings just renders the empty string we can just return that # here. # '' else parse( doc_or_source ).render end end |
#render_type(type, &renderer) ⇒ Object
Instance Methods
88 89 90 |
# File 'lib/nrser/mean_streak.rb', line 88 def render_type type, &renderer @type_renderers[type] = renderer end |