Class: Kramdown::Parser::GFM
- Defined in:
- lib/kramdown/parser/gfm.rb
Constant Summary collapse
- ATX_HEADER_START =
/^\#{1,6}\s/- FENCED_CODEBLOCK_MATCH =
/^(([~`]){3,})\s*?(\w+)?\s*?\n(.*?)^\1\2*\s*?\n/m
Constants inherited from Kramdown
Kramdown::ABBREV_DEFINITION_START, Kramdown::ACHARS, Kramdown::ALD_ANY_CHARS, Kramdown::ALD_ID_CHARS, Kramdown::ALD_ID_NAME, Kramdown::ALD_START, Kramdown::ALD_TYPE_ANY, Kramdown::ALD_TYPE_CLASS_NAME, Kramdown::ALD_TYPE_ID_NAME, Kramdown::ALD_TYPE_ID_OR_CLASS, Kramdown::ALD_TYPE_ID_OR_CLASS_MULTI, Kramdown::ALD_TYPE_KEY_VALUE_PAIR, Kramdown::ALD_TYPE_REF, Kramdown::ATX_HEADER_MATCH, Kramdown::AUTOLINK_START, Kramdown::AUTOLINK_START_STR, Kramdown::BLANK_LINE, Kramdown::BLOCKQUOTE_START, Kramdown::BLOCK_BOUNDARY, Kramdown::BLOCK_EXTENSIONS_START, Kramdown::BLOCK_MATH_START, Kramdown::CODEBLOCK_MATCH, Kramdown::CODEBLOCK_START, Kramdown::CODESPAN_DELIMITER, Kramdown::DEFINITION_LIST_START, Kramdown::EMPHASIS_START, Kramdown::EOB_MARKER, Kramdown::ESCAPED_CHARS, Kramdown::EXT_BLOCK_START, Kramdown::EXT_BLOCK_STOP_STR, Kramdown::EXT_SPAN_START, Kramdown::EXT_START_STR, Kramdown::EXT_STOP_STR, Kramdown::FENCED_CODEBLOCK_START, Kramdown::FOOTNOTE_DEFINITION_START, Kramdown::FOOTNOTE_MARKER_START, Kramdown::HEADER_ID, Kramdown::HR_START, Kramdown::HTML_BLOCK_START, Kramdown::HTML_MARKDOWN_ATTR_MAP, Kramdown::HTML_SPAN_START, Kramdown::IAL_BLOCK, Kramdown::IAL_BLOCK_START, Kramdown::IAL_CLASS_ATTR, Kramdown::IAL_SPAN_START, Kramdown::INLINE_MATH_START, Kramdown::LAZY_END, Kramdown::LAZY_END_HTML_SPAN_ELEMENTS, Kramdown::LAZY_END_HTML_START, Kramdown::LAZY_END_HTML_STOP, Kramdown::LINE_BREAK, Kramdown::LINK_BRACKET_STOP_RE, Kramdown::LINK_DEFINITION_START, Kramdown::LINK_INLINE_ID_RE, Kramdown::LINK_INLINE_TITLE_RE, Kramdown::LINK_PAREN_STOP_RE, Kramdown::LINK_START, Kramdown::LIST_ITEM_IAL, Kramdown::LIST_ITEM_IAL_CHECK, Kramdown::LIST_START, Kramdown::LIST_START_OL, Kramdown::LIST_START_UL, Kramdown::PARAGRAPH_END, Kramdown::PARAGRAPH_MATCH, Kramdown::PARAGRAPH_START, Kramdown::SETEXT_HEADER_START, Kramdown::SMART_QUOTES_RE, Kramdown::SPAN_EXTENSIONS_START, Kramdown::SQ_CLOSE, Kramdown::SQ_PUNCT, Kramdown::SQ_RULES, Kramdown::SQ_SUBSTS, Kramdown::TABLE_FSEP_LINE, Kramdown::TABLE_HSEP_ALIGN, Kramdown::TABLE_LINE, Kramdown::TABLE_PIPE_CHECK, Kramdown::TABLE_ROW_LINE, Kramdown::TABLE_SEP_LINE, Kramdown::TABLE_START, Kramdown::TRAILING_WHITESPACE, Kramdown::TYPOGRAPHIC_SYMS, Kramdown::TYPOGRAPHIC_SYMS_RE, Kramdown::TYPOGRAPHIC_SYMS_SUBST
Constants included from Html::Parser
Constants included from Html::Constants
Html::Constants::HTML_ATTRIBUTE_RE, Html::Constants::HTML_BLOCK_ELEMENTS, Html::Constants::HTML_COMMENT_RE, Html::Constants::HTML_CONTENT_MODEL, Html::Constants::HTML_CONTENT_MODEL_BLOCK, Html::Constants::HTML_CONTENT_MODEL_RAW, Html::Constants::HTML_CONTENT_MODEL_SPAN, Html::Constants::HTML_DOCTYPE_RE, Html::Constants::HTML_ELEMENTS_WITHOUT_BODY, Html::Constants::HTML_ENTITY_RE, Html::Constants::HTML_INSTRUCTION_RE, Html::Constants::HTML_SPAN_ELEMENTS, Html::Constants::HTML_TAG_CLOSE_RE, Html::Constants::HTML_TAG_RE
Constants included from Kramdown
Instance Attribute Summary
Attributes inherited from Base
#options, #root, #source, #warnings
Instance Method Summary collapse
- #add_hard_line_breaks(element) ⇒ Object
-
#initialize(source, options) ⇒ GFM
constructor
A new instance of GFM.
- #parse ⇒ Object
Methods inherited from Kramdown
#add_link, #after_block_boundary?, #before_block_boundary?, #handle_extension, #handle_kramdown_html_tag, #normalize_link_id, #parse_abbrev_definition, #parse_attribute_list, #parse_atx_header, #parse_autolink, #parse_blank_line, #parse_block_extensions, #parse_block_html, #parse_block_math, #parse_blockquote, #parse_codeblock, #parse_codeblock_fenced, #parse_codespan, #parse_definition_list, #parse_emphasis, #parse_eob_marker, #parse_escaped_chars, #parse_extension_start_tag, #parse_first_list_line, #parse_footnote_definition, #parse_footnote_marker, #parse_horizontal_rule, #parse_html_entity, #parse_inline_math, #parse_line_break, #parse_link, #parse_link_definition, #parse_list, #parse_paragraph, #parse_setext_header, #parse_smart_quotes, #parse_span_extensions, #parse_span_html, #parse_table, #parse_typographic_syms, #replace_abbreviations, #update_ial_with_ial
Methods included from Html::Parser
#handle_html_start_tag, #handle_raw_html_tag, #parse_raw_html
Methods included from Kramdown
Methods inherited from Base
#adapt_source, #add_text, #extract_string, parse, #warning
Constructor Details
#initialize(source, options) ⇒ GFM
Returns a new instance of GFM.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kramdown/parser/gfm.rb', line 9 def initialize(source, ) super @span_parsers.delete(:line_break) if @options[:hard_wrap] {:codeblock_fenced => :codeblock_fenced_gfm, :atx_header => :atx_header_gfm}.each do |current, replacement| i = @block_parsers.index(current) @block_parsers.delete(current) @block_parsers.insert(i, replacement) end end |
Instance Method Details
#add_hard_line_breaks(element) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kramdown/parser/gfm.rb', line 25 def add_hard_line_breaks(element) element.children.map! do |child| if child.type == :text && child.value =~ /\n/ children = [] lines = child.value.split(/\n/, -1) omit_trailing_br = (Kramdown::Element.category(element) == :block && element.children[-1] == child && lines[-1].empty?) lines.each_with_index do |line, index| children << Element.new(:text, (index > 0 ? "\n#{line}" : line)) children << Element.new(:br) if index < lines.size - 2 || (index == lines.size - 2 && !omit_trailing_br) end children elsif child.type == :html_element child else add_hard_line_breaks(child) child end end.flatten! end |
#parse ⇒ Object
20 21 22 23 |
# File 'lib/kramdown/parser/gfm.rb', line 20 def parse super add_hard_line_breaks(@root) if @options[:hard_wrap] end |