Class: Yaml::Converter::MarkdownEmitter
- Inherits:
-
Object
- Object
- Yaml::Converter::MarkdownEmitter
- Defined in:
- lib/yaml/converter/markdown_emitter.rb
Overview
High-level emitter orchestrates parsing tokens and applying the state machine,
producing a Markdown document with fenced YAML blocks and extracted notes.
Constant Summary collapse
- START_YAML =
"```yaml"- END_YAML =
"```"- VALIDATED_STR =
"YAML validation:"- NOTE_STR =
"note:"
Instance Method Summary collapse
-
#emit(lines) ⇒ Array<String>
Convert input lines to markdown using parser + state machine, then append a footer.
-
#initialize(options) ⇒ MarkdownEmitter
constructor
A new instance of MarkdownEmitter.
-
#set_validation_status(status) ⇒ void
Set the validation status used when injecting the validation status line.
Constructor Details
#initialize(options) ⇒ MarkdownEmitter
Returns a new instance of MarkdownEmitter.
18 19 20 21 22 23 24 25 26 |
# File 'lib/yaml/converter/markdown_emitter.rb', line 18 def initialize() @options = @max_len = .fetch(:max_line_length) @truncate = .fetch(:truncate) @margin_notes = .fetch(:margin_notes) @validate = .fetch(:validate) @validation_status = :ok @is_latex = false end |
Instance Method Details
#emit(lines) ⇒ Array<String>
Convert input lines to markdown using parser + state machine, then append a footer.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/yaml/converter/markdown_emitter.rb', line 38 def emit(lines) parser = Parser.new(@options) tokens = parser.tokenize(lines) sm = StateMachine.new(validation_status: @validation_status, max_line_length: @max_len, truncate: @truncate, margin_notes: @margin_notes, current_date: @options[:current_date]) body = sm.apply(tokens) if @options[:emit_footer] body << "---- \n\nProduced by [yaml-converter](https://github.com/kettle-rb/yaml-converter)" end body end |
#set_validation_status(status) ⇒ void
This method returns an undefined value.
Set the validation status used when injecting the validation status line.
31 32 33 |
# File 'lib/yaml/converter/markdown_emitter.rb', line 31 def set_validation_status(status) @validation_status = status end |