Class: Kramdown::Parser::GithubMarkdown

Inherits:
Markdown show all
Defined in:
lib/kramdown/parser/github_markdown.rb,
lib/kramdown/parser/github_markdown/github_codeblock.rb

Overview

Used for parsing a document in GithubMarkdown format.

This parser is based on the kramdown parser and removes the parser methods for the additional non-Markdown features. However, since some things are handled differently by the kramdown parser methods (like deciding when a list item contains just text), this parser differs from real Markdown parsers in some respects.

Note, though, that the parser basically fails just one of the Markdown test cases (some others also fail but those failures are negligible).

Constant Summary collapse

GITHUB_CODEBLOCK_START =
/^```/
GITHUB_CODEBLOCK_MATCH =
/^```([^\s]*)?\s*?\n(.*?)^```[\ \t]*\n/m

Constants inherited from Markdown

Markdown::BLOCK_BOUNDARY, Markdown::CODEBLOCK_MATCH, Markdown::EXTENDED, Markdown::IAL_RAND_CHARS, Markdown::IAL_RAND_STRING, Markdown::IAL_SPAN_START, Markdown::LAZY_END, Markdown::LIST_ITEM_IAL, Markdown::PARAGRAPH_END

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_KEY_VALUE_PAIR, Kramdown::ALD_TYPE_REF, Kramdown::ATX_HEADER_MATCH, Kramdown::ATX_HEADER_START, 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_MATCH, 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

Html::Parser::HTML_RAW_START

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

VERSION

Instance Attribute Summary

Attributes inherited from Base

#options, #root, #source, #warnings

Instance Method Summary collapse

Methods inherited from Kramdown

#add_link, #after_block_boundary?, #before_block_boundary?, #handle_extension, #handle_kramdown_html_tag, #normalize_link_id, #parse, #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

data_dir

Methods inherited from Base

#adapt_source, #add_text, #extract_string, #parse, parse, #warning

Constructor Details

#initialize(source, options) ⇒ GithubMarkdown

Returns a new instance of GithubMarkdown.



36
37
38
39
# File 'lib/kramdown/parser/github_markdown.rb', line 36

def initialize(source, options)
  super
  @block_parsers.unshift(:github_codeblock)
end

Instance Method Details

#parse_github_codeblockObject

Parse the indented codeblock at the current location.



35
36
37
38
39
40
# File 'lib/kramdown/parser/github_markdown/github_codeblock.rb', line 35

def parse_github_codeblock
  data = @src.scan(self.class::GITHUB_CODEBLOCK_MATCH)
  matches = data.match GITHUB_CODEBLOCK_MATCH
  @tree.children << new_block_el(:codeblock, matches[2], nil, {"language" => matches[1]})
  true
end