From e78346e326f28697cd9ff5f075adb50fe3b43b31 Mon Sep 17 00:00:00 2001 From: urosm Date: Wed, 14 Feb 2024 15:13:12 +0100 Subject: [PATCH] update `nvim` config markdown syntax checkpoint --- .config/nvim/syntax/markdown.vim | 374 ++++++++++++++++--------------- 1 file changed, 195 insertions(+), 179 deletions(-) diff --git a/.config/nvim/syntax/markdown.vim b/.config/nvim/syntax/markdown.vim index 760f7fc..2a9f944 100644 --- a/.config/nvim/syntax/markdown.vim +++ b/.config/nvim/syntax/markdown.vim @@ -7,225 +7,241 @@ if exists("b:current_syntax") finish endif +syntax spell toplevel + +" html runtime! syntax/html.vim unlet! b:current_syntax -syntax spell toplevel - -" block formatting """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " setext heading -syn match markdownSetexHeading /\%(\%^\|\_^\n\).\+\n[=-]\+\n$/ contains=@markdownInline,markdownSetextHeadingDelimiter,markdownHeadingAttribute -hi def link markdownSetexHeading markdownTitle +syn match markdownSetexHeading /\%(\%^\|^\n\)\@2<=.\+\n[=-]\+\%(\n$\|\%$\)\@=/ contains=@markdownInline,markdownSetextHeadingDelimiter,markdownHeadingAttribute syn match markdownSetextHeadingDelimiter /^[=-]\+$/ contained hi def link markdownSetextHeadingDelimiter markdownDelimiter " atx heading -syn match markdownAtxHeading /\%(\%^\|\_^\n\)#\{1,6} .*\n$/ contains=@markdownInline,markdownAtxHeadingDelimiter,markdownHeadingAttribute -hi def link markdownAtxHeading markdownTitle +syn match markdownAtxHeading /\%(\%^\|^\n\)\@2<=#\{1,6} .*\%(\n$\|\%$\)\@=/ contains=@markdownInline,markdownAtxHeadingDelimiter,markdownHeadingAttribute syn match markdownAtxHeadingDelimiter /^#\{1,6}/ contained hi def link markdownAtxHeadingDelimiter markdownDelimiter + +" heading identifier syn match markdownHeadingAttribute /.*\zs{.\{-}}$/ contained hi def link markdownHeadingAttribute markdownDelimiter -" titleblock -syn region markdownTitleBlock start=/\%^%/ end=/\n$/ contains=@markdownInline,markdownTitleBlockDelimiter -hi def link markdownTitleBlock markdownTitle -syn match markdownTitleBlockDelimiter /%\ / contained -hi def link markdownTitleBlockDelimiter markdownDelimiter +" block quotation +syn region markdownBlockquote start=/\%(\%^\|^\n\)\@2<= \{,3}>/ end=/\%(\n$\|\%$\)\@=/ contains=markdownBlockquoteDelimiter +syn match markdownBlockquoteDelimiter /^\%(\s*>\)\+/ contained +hi def link markdownBlockquoteDelimiter markdownDelimiter -" horizontal rule -syn match markdownHRule /^\n\s*\*\s*\(\*\s*\)\{2,}\n$/ display -syn match markdownHRule /^\n\s*\-\s*\(\-\s*\)\{2,}\n$/ display -syn match markdownHRule /^\n\s*_\s*\(_\s*\)\{2,}\n$/ display -hi def link markdownHRule markdownDelimiter +" indented code block +"syn match markdownIndentedCodeBlock /\%(\%^\|^\n\)\@2<=\%(^\%( \{4,}\|\t\).*\n\)\+\%($\|\%$\)\@=/ +"hi def link markdownIndentedCodeBlock markdownSpecial -" inline formatting """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" emphasis -syn region markdownItalic matchgroup=markdownDelimiter start=/\\\@1/ contains=NONE -hi def link markdownAutomaticLink markdownUnderlined - -" wikilink -syn match markdownWikilink /\[\[.*\]\]/ contains=markdownWikilinkLabel -hi def link markdownWikilink markdownUnderlined - -syn region markdownWikilink start=/\[\[/ end=/\]\]/ contains=markdownWikilinkLabel,markdownWikilinkURL keepend display -syn match markdownWikilinkLabel /\(\[\[\)\@2<=[^\|\[\]]\+/ contained -hi def link markdownWikilinkLabel markdownLabel -syn match markdownWikilinkURL /|\@1<=[^\]]\+/ contained -hi def link markdownWikilinkURL markdownUnderlined - -" definition -syn region markdownReferenceDefinition start=/\[.\{-}\]:/ end=/\(\n\s*".*"$\|$\)/ keepend -hi def link markdownReferenceDefinition markdownDelimiter -syn match markdownReferenceDefinitionLabel /\[\zs.\{-}\ze\]:/ contained containedin=markdownReferenceDefinition display -hi def link markdownReferenceDefinitionLabel markdownLabel -syn match markdownReferenceDefinitionURL /:\s*\zs.*/ contained containedin=markdownReferenceDefinition -hi def link markdownReferenceDefinitionURL markdownUnderlined -syn match markdownReferenceDefinitionTitle /\s*".\{-}"/ contained containedin=markdownReferenceDefinition,markdownReferenceDefinitionURL contains=@Spell,markdownAmpersandEscape -hi def link markdownReferenceDefinitionTitle markdownTitle - -" citation -syn match markdownPCite "\^\@~/]*.\{-}\]" contains=markdownItalic,markdownBold,markdownLatex,markdownCiteKey,@Spell,markdownAmpersandEscape -syn match markdownICite "@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\s\[.\{-1,}\]" contains=markdownCiteKey,@Spell display -syn match markdownCiteKey /\(-\=@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\)/ containedin=markdownPCite,markdownICite contains=@NoSpell display -hi def link markdownCiteKey markdownLabel -syn match markdownCiteLocator /[\[\]]/ contained containedin=markdownPCite,markdownICite -hi def link markdownCiteLocator markdownDelimiter - - -" strikeout -syn region markdownStrike start=/\~\~/ end=/\~\~/ contains=markdownStrikeout,@Spell keepend -hi def link markdownStrike htmlStrike -syn match markdownStrikeDelimiter /\~\~/ contained -hi def link markdownStrikeDelimiter markdownDelimiter - -" subscript -syn region markdownSubscript start=/\~\(\([[:graph:]]\(\\ \)\=\)\{-}\~\)\@=/ end=/\~/ contains=markdownSubscriptDelimiter keepend -syn match markdownSubscriptDelimiter /\~/ contained -hi def link markdownSubscriptDelimiter markdownDelimiter - -" superscript -syn region markdownSuperscript start=/\^\(\([[:graph:]]\(\\ \)\=\)\{-}\^\)\@=/ skip=/\\ / end=/\^/ contains=markdownSuperscriptDelimiter keepend -syn match markdownSuperscriptDelimiter /\^/ contained -hi def link markdownSuperscriptDelimiter markdownDelimiter +" fenced code block +"syn region markdownFencedCodeBlock start=/^\z(\~\{3,}\~*\)/ end=/^\z1\~*$/ keepend contains=markdownFencedCodeBlockDelimiter +"syn region markdownFencedCodeBlock start=/^\z(\`\{3,}\`*\)/ end=/^\z1\`*$/ keepend contains=markdownFencedCodeBlockDelimiter +"hi def link markdownFencedCodeBlock markdownSpecial " line block -syn region markdownLineBlock start=/^|/ end=/\(^|\(.*\n|\@!\)\@=.*\)\@<=\n/ transparent -syn match markdownLineBlockDelimiter /^|/ contained containedin=markdownLineBlock -hi def link markdownLineBlockDelimiter markdownDelimiter +"syn match markdownLineBlock /\%(\%^\|^\n\)\@2<=|.*\n\%(^\%(|\| \).*\n\)*\%($\|\%$\)\@=/ contains=markdownLineBlockDelimiter +"syn match markdownLineBlockDelimiter /^|/ contained +"hi def link markdownLineBlockDelimiter markdownDelimiter + +" bullet list +"syn region markdownBulletList start=/\%(\%^\|^\n\)\@2<= \{,3}[*+-] / end=/\%(\n\n\S\)\@=/ contains=markdownBulletListDelimiter,markdownOrderedList,markdownOrderedListDelimiter,markdownBlockquote,markdownBlockquoteDelimiter +"syn match markdownBulletListDelimiter /^\s*\zs[*+-]/ contained +"hi def link markdownBulletListDelimiter markdownDelimiter + +" ordered list +"syn region markdownOrderedList start=/\%(\%^\|^\n\)\@2<= \{,3}\%(\%(\d\+\|\l\|\#\|@\)\. \|(\=\%(\d\+\|\l\|\#\|@\)) \)/ end=/\%(\n\n\S\)\@=/ contains=markdownOrderedListDelimiter,markdownTaskListDelimiter,markdownBulletList,markdownBulletListDelimiter,markdownBlockquote,markdownBlockquoteDelimiter +"syn match markdownOrderedlistDelimiter /^\s*\%(\%(\d\+\|\l\|\#\|@\)\. \|(\=\%(\d\+\|\l\|\#\|@\)) \)/ contained +"hi def link markdownOrderedListDelimiter markdownDelimiter + +" task list delimiter +"syn match markdownTaskListDelimiter /\%(\%(\%(\d\+\|\l\|\#\|@\)\.\|(\=\%(\d\+\|\l\|\#\|@\))\) \s*\)\@<=\[[ x]\] / contained +"hi def link markdownTaskListDelimiter markdownSpecial + +" definition list +" TODO + +" example list +"syn region markdownExampleList start=/\%(\%^\|^\n\)\@2<= \{,3}(@[[:lower:][:upper:]_-]*)/ end=/\%(\n\n \{,3}\S\)\@=/ contains=markdownExampleListDelimiter +"syn match markdownExampleListDelimiter /^ \{,3}(@.\{-}) / contained +"hi def link markdownExampleListDelimiter markdownDelimiter +"syn match markdownExampleListLabel /@.\{-}\ze)/ containedin=markdownExampleListDelimiter contains=ALLBUT,markdownExampleListReference +"hi def link markdownExampleListLabel markdownSpecial +"syn match markdownExampleListReference /(@[[:lower:][:upper:]_-]*)/ !contained +"hi def link markdownExampleListReference Error + +" horizontal rule +"syn match markdownHRule /^\n\s*\*\s*\(\*\s*\)\{2,}\n$/ display +"syn match markdownHRule /^\n\s*\-\s*\(\-\s*\)\{2,}\n$/ display +"syn match markdownHRule /^\n\s*_\s*\(_\s*\)\{2,}\n$/ display +"hi def link markdownHRule markdownDelimiter + +" table +" TODO + +" titleblock +"syn region markdownTitleBlock start=/\%^%/ end=/\n$/ contains=@markdownInline,markdownTitleBlockDelimiter +"hi def link markdownTitleBlock markdownTitle +"syn match markdownTitleBlockDelimiter /%\ / contained +"hi def link markdownTitleBlockDelimiter markdownDelimiter + +" definition +"syn region markdownReferenceDefinition start=/\[.\{-}\]:/ end=/\(\n\s*".*"$\|$\)/ keepend +"hi def link markdownReferenceDefinition markdownDelimiter +"syn match markdownReferenceDefinitionLabel /\[\zs.\{-}\ze\]:/ contained containedin=markdownReferenceDefinition display +"hi def link markdownReferenceDefinitionLabel markdownLabel +"syn match markdownReferenceDefinitionURL /:\s*\zs.*/ contained containedin=markdownReferenceDefinition +"hi def link markdownReferenceDefinitionURL markdownUnderlined +"syn match markdownReferenceDefinitionTitle /\s*".\{-}"/ contained containedin=markdownReferenceDefinition,markdownReferenceDefinitionURL contains=@Spell,markdownAmpersandEscape +"hi def link markdownReferenceDefinitionTitle markdownTitle + +" strikeout +"syn region markdownStrike start=/\~\~/ end=/\~\~/ contains=markdownStrikeout,@Spell keepend +"hi def link markdownStrike htmlStrike +"syn match markdownStrikeDelimiter /\~\~/ contained +"hi def link markdownStrikeDelimiter markdownDelimiter + +" subscript +"syn region markdownSubscript start=/\~\(\([[:graph:]]\(\\ \)\=\)\{-}\~\)\@=/ end=/\~/ contains=markdownSubscriptDelimiter keepend +"syn match markdownSubscriptDelimiter /\~/ contained +"hi def link markdownSubscriptDelimiter markdownDelimiter + +" superscript +"syn region markdownSuperscript start=/\^\(\([[:graph:]]\(\\ \)\=\)\{-}\^\)\@=/ skip=/\\ / end=/\^/ contains=markdownSuperscriptDelimiter keepend +"syn match markdownSuperscriptDelimiter /\^/ contained +"hi def link markdownSuperscriptDelimiter markdownDelimiter + " simple table -syn region markdownSimpleTable start=/\%#=2\(^.*[[:graph:]].*\n\)\@/ contained containedin=markdownGridTableHeader,markdownPipeTableHeader contains=@Spell -hi def link markdownTableHeaderWord markdownBold +"syn match markdownTableHeaderWord /\<.\{-}\>/ contained containedin=markdownGridTableHeader,markdownPipeTableHeader contains=@Spell +"hi def link markdownTableHeaderWord markdownBold " delimited code blocks -syn region markdownDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=markdownDelimitedCodeBlockStart,markdownDelimitedCodeBlockEnd keepend -syn region markdownDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=markdownDelimitedCodeBlockStart,markdownDelimitedCodeBlockEnd keepend -syn match markdownDelimitedCodeBlockStart /\(\(\_^\n\_^\|\%^\)\(>\s\)\?\( \+\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=markdownDelimitedCodeBlock nextgroup=markdownDelimitedCodeBlockLanguage -syn match markdownDelimitedCodeBlockLanguage /\(\s\?\)\@<=.\+\(\_$\)\@=/ contained -syn match markdownDelimitedCodeBlockEnd /\(`\{3,}`*\|\~\{3,}\~*\)\(\_$\n\(>\s\)\?\_$\)\@=/ contained containedin=markdownDelimitedCodeBlock -syn match markdownBlockquoteinDelimitedCodeBlock '^>' contained containedin=markdownDelimitedCodeBlock -syn match markdownCodePre /
.\{-}<\/pre>/ skipnl
-syn match markdownCodePre /.\{-}<\/code>/ skipnl
-hi def link markdownDelimitedCodeBlock markdownSpecial
-hi def link markdownDelimitedCodeBlockStart markdownDelimiter
-hi def link markdownDelimitedCodeBlockEnd markdownDelimiter
-hi def link markdownDelimitedCodeBlockLanguage markdownComment
-hi def link markdownBlockquoteinDelimitedCodeBlock markdownBlockquote
-hi def link markdownCodePre markdownString
+"syn region markdownDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=markdownDelimitedCodeBlockStart,markdownDelimitedCodeBlockEnd keepend
+"syn region markdownDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=markdownDelimitedCodeBlockStart,markdownDelimitedCodeBlockEnd keepend
+"syn match markdownDelimitedCodeBlockStart /\(\(\_^\n\_^\|\%^\)\(>\s\)\?\( \+\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=markdownDelimitedCodeBlock nextgroup=markdownDelimitedCodeBlockLanguage
+"syn match markdownDelimitedCodeBlockLanguage /\(\s\?\)\@<=.\+\(\_$\)\@=/ contained
+"syn match markdownDelimitedCodeBlockEnd /\(`\{3,}`*\|\~\{3,}\~*\)\(\_$\n\(>\s\)\?\_$\)\@=/ contained containedin=markdownDelimitedCodeBlock
+"syn match markdownBlockquoteinDelimitedCodeBlock '^>' contained containedin=markdownDelimitedCodeBlock
+"syn match markdownCodePre /
.\{-}<\/pre>/ skipnl
+"syn match markdownCodePre /.\{-}<\/code>/ skipnl
+"hi def link markdownDelimitedCodeBlock markdownSpecial
+"hi def link markdownDelimitedCodeBlockStart markdownDelimiter
+"hi def link markdownDelimitedCodeBlockEnd markdownDelimiter
+"hi def link markdownDelimitedCodeBlockLanguage markdownComment
+"hi def link markdownBlockquoteinDelimitedCodeBlock markdownBlockquote
+"hi def link markdownCodePre markdownString
 
 " footnote
-syn match markdownFootnoteID /\[\^[^\]]\+\]/ nextgroup=markdownFootnoteDef
-hi def link markdownFootnoteID markdownLabel
+"syn match markdownFootnoteID /\[\^[^\]]\+\]/ nextgroup=markdownFootnoteDef
+"hi def link markdownFootnoteID markdownLabel
 
 " inline footnote
-syn region markdownFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=markdownLink,markdownLatex,markdownPCite,markdownCiteKey,markdownBold,markdownItalic,markdownBoldItalic,markdownNoFormatted,markdownSuperscript,markdownSubscript,markdownStrike,markdownEnDash,markdownEmDash,markdownEllipses,markdownBeginQuote,markdownEndQuote,@Spell,markdownAmpersandEscape skipnl keepend
-hi def link markdownFootnoteDef markdownComment
-syn match markdownFootnoteDefHead /\^\[/ contained containedin=markdownFootnoteDef
-hi def link markdownFootnoteDefHead markdownDelimiter
-syn match markdownFootnoteDefTail /\]/ contained containedin=markdownFootnoteDef
-hi def link markdownFootnoteDefTail markdownDelimiter
+"syn region markdownFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=markdownLink,markdownLatex,markdownPCite,markdownCiteKey,markdownBold,markdownItalic,markdownBoldItalic,markdownNoFormatted,markdownSuperscript,markdownSubscript,markdownStrike,markdownEnDash,markdownEmDash,markdownEllipses,markdownBeginQuote,markdownEndQuote,@Spell,markdownAmpersandEscape skipnl keepend
+"hi def link markdownFootnoteDef markdownComment
+"syn match markdownFootnoteDefHead /\^\[/ contained containedin=markdownFootnoteDef
+"hi def link markdownFootnoteDefHead markdownDelimiter
+"syn match markdownFootnoteDefTail /\]/ contained containedin=markdownFootnoteDef
+"hi def link markdownFootnoteDefTail markdownDelimiter
 
 " regular footnotes
-syn region markdownFootnoteBlock start=/\[\^.\{-}\]:\s*\n*/ end=/^\n^\s\@!/ contains=markdownLink,markdownLatex,markdownPCite,markdownCiteKey,markdownBold,markdownItalic,markdownNoFormatted,markdownSuperscript,markdownSubscript,markdownStrike,markdownEnDash,markdownEmDash,markdownNewLine,markdownBoldItalic,markdownEllipses,markdownBeginQuote,markdownEndQuote,markdownLaTeXInlineMath,markdownEscapedDollar,markdownLaTeXCommand,markdownLaTeXMathBlock,markdownLaTeXRegion,markdownAmpersandEscape,@Spell skipnl
-syn match markdownFootnoteBlockSeparator /:/ contained containedin=markdownFootnoteBlock
-hi def link markdownFootnoteBlockSeparator markdownDelimiter
-syn match markdownFootnoteID /\[\^.\{-}\]/ contained containedin=markdownFootnoteBlock
-syn match markdownFootnoteIDHead /\[\^/ contained containedin=markdownFootnoteID
-hi def link markdownFootnoteIDHead markdownDelimiter
-syn match markdownFootnoteIDTail /\]/ contained containedin=markdownFootnoteID
-hi def link markdownFootnoteIDTail markdownDelimiter
-
-" unordered list
-syn match markdownUListItem /^>\=\s*[*+-]\s\+-\@!.*$/ nextgroup=markdownUListItem,markdownLaTeXMathBlock,markdownLaTeXInlineMath,markdownEscapedDollar,markdownDelimitedCodeBlock,markdownListItemContinuation contains=@Spell,markdownItalic,markdownBold,markdownNoFormatted,markdownStrike,markdownSubscript,markdownSuperscript,markdownBoldItalic,markdownBoldItalic,markdownPCite,markdownICite,markdownCiteKey,markdownLinkText,markdownLaTeXCommand,markdownLaTeXMathBlock,markdownLaTeXInlineMath,markdownEscapedDollar,markdownLinkURL,markdownAutomaticLink,markdownFootnoteDef,markdownFootnoteBlock,markdownFootnoteID,markdownAmpersandEscape skipempty display
-syn match markdownUListItemBullet /^>\=\s*\zs[*+-]/ contained containedin=markdownUListItem
-hi def link markdownUListItemBullet markdownOperator
-
-" ordered list
-syn match markdownListItem /^\s*(\?\(\d\+\|\l\|\#\|@\)[.)].*$/ nextgroup=markdownListItem,markdownLaTeXMathBlock,markdownLaTeXInlineMath,markdownEscapedDollar,markdownDelimitedCodeBlock,markdownListItemContinuation contains=@Spell,markdownItalic,markdownBold,markdownNoFormatted,markdownStrike,markdownSubscript,markdownSuperscript,markdownBoldItalic,markdownBoldItalic,markdownPCite,markdownICite,markdownCiteKey,markdownLinkText,markdownLaTeXCommand,markdownLaTeXMathBlock,markdownLaTeXInlineMath,markdownEscapedDollar,markdownAutomaticLink,markdownFootnoteDef,markdownFootnoteBlock,markdownFootnoteID,markdownAmpersandEscape skipempty display
-syn match markdownListItem /^\s*(\?x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}[.)].*$/ nextgroup=markdownListItem,markdownMathBlock,markdownLaTeXInlineMath,markdownEscapedDollar,markdownDelimitedCodeBlock,markdownListItemContinuation,markdownAutomaticLink skipempty display
-syn match markdownListItemBullet /^(\?.\{-}[.)]/ contained containedin=markdownListItem
-syn match markdownListItemBulletId /\(\d\+\|\l\|\#\|@.\{-}\|x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}\)/ contained containedin=markdownListItemBullet
-hi def link markdownListItemBullet markdownOperator
-hi def link markdownListItemBulletId markdownIdentifier
-
-syn match markdownListItemContinuation /^\s\+\([-+*]\s\+\|(\?.\+[).]\)\@/
+hi def link markdownAutomaticLink markdownUnderlined
+
+" wikilink
+" NOTE: update to support newlines in titles
+syn match markdownWikilink /\[\[.*\]\]/ contains=markdownWikilinkLabel,markdownWikilinkURL
+syn match markdownWikilinkLabel /\[\[\zs.\{-}\ze|.*\]\]/ contained
+hi def link markdownWikilinkLabel markdownLabel
+syn match markdownWikilinkURL /\%(\[\[\||\)\zs[^|]*\ze\]\]/ contained
+hi def link markdownWikilinkURL markdownUnderlined
+
+" footnote reference
+syn match markdownFootnoteReference /\[\zs\^.\{-}\ze\]/
+hi def link markdownFootnoteReference markdownLabel
+
+" reference key
+syn match markdownReferenceKey /@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&-+?<>~\/]*/
+hi def link markdownReferenceKey markdownLabel
+
+" styling
 hi def link markdownComment Comment
 hi def link markdownConstant Constant
 hi def link markdownString String