Class: Kramdown::Parser::Kramdown
- Inherits:
-
Base
- Object
- Base
- Kramdown::Parser::Kramdown
- Includes:
- Kramdown
- Defined in:
- lib/kramdown-respec.rb
Overview
class KramdownRespec < Kramdown::Parser::Kramdown
Constant Summary collapse
- RESPECTESTS_ANNOTATIONS =
List of possible annotations If annotation is not in the list, then it should be a reference to a test
["untestable", "informative", "note", "no-test-needed", "needs-test"]
- RESPECTESTS =
/\{:&(.*)\}/
- RESPECTESTS_START =
/^#{OPT_SPACE}#{RESPECTESTS}/
Instance Method Summary collapse
-
#initialize(source, options) ⇒ Kramdown
constructor
Create a new Kramdown parser object with the given
options
. -
#parse_block_extensions ⇒ Object
Parse one of the block extensions (ALD, block IAL or generic extension) at the current location.
-
#parse_respec_tests_list(str, opts) ⇒ Object
Parse the string
str
and extract the annotation or the list of tests. - #parse_respectests ⇒ Object
-
#parse_span_extensions ⇒ Object
Parse the extension span at the current location.
Constructor Details
#initialize(source, options) ⇒ Kramdown
Create a new Kramdown parser object with the given options
.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kramdown-respec.rb', line 77 def initialize(source, ) super reset_env @alds = {} @footnotes = {} @link_defs = {} update_link_definitions(@options[:link_defs]) @block_parsers = [:blank_line, :codeblock, :codeblock_fenced, :blockquote, :atx_header, :horizontal_rule, :list, :definition_list, :block_html, :setext_header, :block_math, :table, :footnote_definition, :link_definition, :abbrev_definition, :block_extensions, :eob_marker, :paragraph, :respectests] @span_parsers = [:emphasis, :codespan, :autolink, :span_html, :footnote_marker, :link, :smart_quotes, :inline_math, :span_extensions, :html_entity, :typographic_syms, :line_break, :escaped_chars, :respectests] end |
Instance Method Details
#parse_block_extensions ⇒ Object
Parse one of the block extensions (ALD, block IAL or generic extension) at the current location.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/kramdown-respec.rb', line 111 def parse_block_extensions # Parse the string +str+ and extract the annotation or the list of tests if @src.scan(RESPECTESTS_START) last_child = @tree.children.last if last_child.type == :header parse_respec_tests_list(@src[1], last_child.[:respec_section] ||= {}) @tree.children << new_block_el(:eob, :respec_section) else parse_respec_tests_list(@src[1], last_child.[:ial] ||= {}) @tree.children << new_block_el(:eob, :ial) end # Original parser of block extensions elsif @src.scan(ALD_START) parse_attribute_list(@src[2], @alds[@src[1]] ||= Utils::OrderedHash.new) @tree.children << new_block_el(:eob, :ald) true elsif @src.check(EXT_BLOCK_START) parse_extension_start_tag(:block) elsif @src.scan(IAL_BLOCK_START) if @tree.children.last && @tree.children.last.type != :blank && (@tree.children.last.type != :eob || [:link_def, :abbrev_def, :footnote_def].include?(@tree.children.last.value)) parse_attribute_list(@src[1], @tree.children.last.[:ial] ||= Utils::OrderedHash.new) @tree.children << new_block_el(:eob, :ial) unless @src.check(IAL_BLOCK_START) else parse_attribute_list(@src[1], @block_ial ||= Utils::OrderedHash.new) end true else false end end |
#parse_respec_tests_list(str, opts) ⇒ Object
Parse the string str
and extract the annotation or the list of tests
159 160 161 162 163 164 165 166 |
# File 'lib/kramdown-respec.rb', line 159 def parse_respec_tests_list(str, opts) str = str.strip if RESPECTESTS_ANNOTATIONS.include?(str) opts['class'] = "#{str}" else opts['data-tests'] = "#{str}" end end |
#parse_respectests ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/kramdown-respec.rb', line 168 def parse_respectests last_child = @tree.children.last if last_child.type == :header parse_respec_tests_list(@src[1], last_child.[:respec_section] ||= {}) @tree.children << new_block_el(:eob, :respec_section) else parse_respec_tests_list(@src[1], last_child.[:ial] ||= {}) @tree.children << new_block_el(:eob, :ial) end end |
#parse_span_extensions ⇒ Object
Parse the extension span at the current location.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/kramdown-respec.rb', line 180 def parse_span_extensions if @src.check(RESPECTESTS_START) if (last_child = @tree.children.last) && last_child.type != :text @src.pos += @src.matched_size attr = {} parse_respec_tests_list(@src[1], attr) update_ial_with_ial(last_child.[:ial] ||= {}, attr) update_attr_with_ial(last_child.attr, attr) else warning("Found span respec-test after text - ignoring it") add_text(@src.getch) end # Original parser of span extension elsif @src.check(EXT_SPAN_START) parse_extension_start_tag(:span) elsif @src.check(IAL_SPAN_START) if @tree.children.last && @tree.children.last.type != :text @src.pos += @src.matched_size attr = Utils::OrderedHash.new parse_attribute_list(@src[1], attr) update_ial_with_ial(@tree.children.last.[:ial] ||= Utils::OrderedHash.new, attr) update_attr_with_ial(@tree.children.last.attr, attr) else warning("Found span IAL after text - ignoring it") add_text(@src.getch) end else add_text(@src.getch) end end |