%YAML 1.2 --- # This definition aims to meet CommonMark specifications # http://spec.commonmark.org/ # with GitHub Formatted Markdown extensions # https://github.github.com/gfm/ # and has a few extras like Markdown Extra's footnotes # https://michelf.ca/projects/php-markdown/extra/#footnotes # # The scope suffix should indicate which flavor of Markdown the feature came from, # to help make this syntax definition easier to maintain. name: Markdown scope: text.html.markdown version: 2 file_extensions: - md - mdown - mdwn - markdown - markdn variables: # Headings # ======== atx_heading: (?:\#{1,6}[ \t\n]) # 1 to 6 hashes, followed by at least one space or tab or by end of the line atx_heading_space: (?:(?=[ \t]+#+[ \t]*$)|[ \t]+|$) # consume spaces only if heading is not empty to ensure `atx_heading_end` can fully match closing hashes atx_heading_end: (?:[ \t]+(#+))?[ \t]*($\n?) # \n is optional so ## is matched as end punctuation in new document (at eof) setext_heading_or_paragraph: ^(?:[ ]{,3}=+[ \t]*$|(?=[ ]{,3}\S)) # between 0 and 3 spaces, followed by non-whitespace (consume equal signs as paragraphs may start with them) setext_heading_escape: ^(?=[ ]{,3}(?:=+|-+)[ \t]*$) # between 0 and 3 spaces, followed by at least one hyphen or equal sign (setext underline can be of any length) setext_heading1_escape: ^(?=[ ]{,3}=+[ \t]*$) # between 0 and 3 spaces, followed by at least one equal sign (setext underline can be of any length) setext_heading1_end: ^[ ]{,3}(=+)[ \t]*($\n?) # between 0 and 3 spaces, followed by at least one equal sign (setext underline can be of any length) setext_heading2_end: ^[ ]{,3}(-+)[ \t]*($\n?) # between 0 and 3 spaces, followed by at least one hyphen (setext underline can be of any length) list_setext_heading_or_paragraph: (?:[ \t]*=+[ \t]*$|(?=[ \t]*\S)) # any number of spaces, followed by non-whitespace (consume equal signs as paragraphs may start with them) list_setext_heading_escape: ^(?=[ \t]{2,}(?:==+|--+)[ \t]*$) # two or more spaces, followed by at least one hyphen or equal sign (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items) list_setext_heading1_escape: ^(?=[ \t]{2,}==+[ \t]*$) # two or more spaces, followed by at least one equal sign (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items) list_setext_heading1_end: ^[ \t]{2,}(==+)[ \t]*($\n?) # two or more spaces, followed by at least one equal sign (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items) list_setext_heading2_end: ^[ \t]{2,}(--+)[ \t]*($\n?) # two or more spaces, followed by at least one hyphen (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items) # Common Block Indicators # ======================= block_quote: '>' # a greater than sign, (followed by any character or the end of the line) indented_code_block: (?:[ ]{4}|[ ]{0,3}\t) # a visual tab of width 4 consisting of 4 spaces or 0 to 3 spaces followed by 1 tab first_list_item: (?:(?:1[.)]|[*+-])[ \t\n]) # at least one integer and a full stop or a parenthesis, or (a star, plus or dash), followed by whitespace list_item: (?:(?:\d{1,9}[.)]|[*+-])[ \t\n]) # at least one integer and a full stop or a parenthesis, or (a star, plus or dash), followed by whitespace thematic_break: |- (?x: (?: # followed by one of the following: [-](?:[ \t]*[-]){2,} # - a dash, followed by the following at least twice: any number of spaces or tabs followed by a dash | [*](?:[ \t]*[*]){2,} # - a star, followed by the following at least twice: any number of spaces or tabs followed by a star | [_](?:[ \t]*[_]){2,} # - an underscore, followed by the following at least twice: any number of spaces or tabs followed by an underscore ) [ \t]*$ # followed by any number of tabs or spaces, followed by the end of the line ) # Fenced code blocks # ================== fenced_code_block: |- (?x: (`){3,} # 3 or more backticks (?![^`]*`) # not followed by any more backticks on the same line | # or (~){3,} # 3 or more tildas ) fenced_code_block_start: |- (?x: ([ \t]*) ({{fenced_code_block}}) ) fenced_code_block_language: |- (?x: # first word of an infostring is used as language specifier \s* # allow for whitespace between code block start and info string ( [[:alpha:]] # starts with a letter to make sure not to hit any attribute annotation [^\s:;`]* # optionally followed by any nonwhitespace character (except backticks) ) ) fenced_code_block_trailing_infostring_characters: |- (?x: (?: (?: \s+ | (?=[:;]) ) # separated by colon, semicolon or whitespace ... ([^`]+?) # any characters (except backticks) )? (\s*$\n?) # ... until EOL (fold begin marker) ) fenced_code_block_end: |- (?x: [ \t]* ( \2 # the backtick/tilde combination that opened the code fence (?:\3|\4)* # plus optional additional closing characters ) (\s*$\n?) # any amount of whitespace until EOL (fold end marker) ) fenced_code_block_escape: ^{{fenced_code_block_end}} # https://pandoc.org/MANUAL.html#divs-and-spans fenced_div_block: ':{3,}' # HTML blocks # =========== # https://spec.commonmark.org/0.30/#html-blocks html_block: |- (?x: {{html_tag_block_end_at_close_tag}} # html block type 1 | {{html_tag_block_end_at_blank_line}} # html block type 6 | {{html_block_open_tag}} # html block type 7 | {{html_block_close_tag}} # html block type 7 | {{html_block_comment}} # html block type 2 | {{html_block_decl}} # html block type 4 | {{html_block_cdata}} # html block type 5 | {{html_block_preprocessor}} # html block type 3 ) html_block_comment: