diff options
| author | orbitalquark <70453897+orbitalquark@users.noreply.github.com> | 2024-09-18 14:30:49 -0400 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2025-01-04 12:29:07 -0700 |
| commit | c1f4d3f68787fa2ae964c468d28a84df37319b28 (patch) | |
| tree | dcd62bd74f8f9fd786cba6a0c248fb388d5244a8 /lua/lexers/markdown.lua | |
| parent | cc18cea14d1f836abcebb84a96f5029431474255 (diff) | |
| download | vis-c1f4d3f68787fa2ae964c468d28a84df37319b28.tar.gz vis-c1f4d3f68787fa2ae964c468d28a84df37319b28.tar.xz | |
lexers: switch to tabs for indentation
Diffstat (limited to 'lua/lexers/markdown.lua')
| -rw-r--r-- | lua/lexers/markdown.lua | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/lua/lexers/markdown.lua b/lua/lexers/markdown.lua index 3819d3f..e8202bd 100644 --- a/lua/lexers/markdown.lua +++ b/lua/lexers/markdown.lua @@ -11,49 +11,49 @@ lex:modify_rule('whitespace', lex:tag(lexer.WHITESPACE, S(' \t')^1 + S('\r\n')^1 -- Block elements. local function h(n) - return lex:tag(string.format('%s.h%s', lexer.HEADING, n), - lexer.to_eol(lexer.starts_line(string.rep('#', n)))) + return lex:tag(string.format('%s.h%s', lexer.HEADING, n), + lexer.to_eol(lexer.starts_line(string.rep('#', n)))) end lex:add_rule('header', h(6) + h(5) + h(4) + h(3) + h(2) + h(1)) lex:add_rule('hr', - lex:tag('hr', lpeg.Cmt(lexer.starts_line(lpeg.C(S('*-_')), true), function(input, index, c) - local line = input:match('[^\r\n]*', index):gsub('[ \t]', '') - if line:find('[^' .. c .. ']') or #line < 2 then return nil end - return (select(2, input:find('\r?\n', index)) or #input) + 1 -- include \n for eolfilled styles - end))) + lex:tag('hr', lpeg.Cmt(lexer.starts_line(lpeg.C(S('*-_')), true), function(input, index, c) + local line = input:match('[^\r\n]*', index):gsub('[ \t]', '') + if line:find('[^' .. c .. ']') or #line < 2 then return nil end + return (select(2, input:find('\r?\n', index)) or #input) + 1 -- include \n for eolfilled styles + end))) lex:add_rule('list', lex:tag(lexer.LIST, - lexer.starts_line(lexer.digit^1 * '.' + S('*+-'), true) * S(' \t'))) + lexer.starts_line(lexer.digit^1 * '.' + S('*+-'), true) * S(' \t'))) local hspace = lexer.space - '\n' local blank_line = '\n' * hspace^0 * ('\n' + P(-1)) local code_line = lexer.starts_line((B(' ') + B('\t')) * lexer.to_eol(), true) local code_block = - lexer.range(lexer.starts_line('```', true), '\n```' * hspace^0 * ('\n' + P(-1))) + - lexer.range(lexer.starts_line('~~~', true), '\n~~~' * hspace^0 * ('\n' + P(-1))) + lexer.range(lexer.starts_line('```', true), '\n```' * hspace^0 * ('\n' + P(-1))) + + lexer.range(lexer.starts_line('~~~', true), '\n~~~' * hspace^0 * ('\n' + P(-1))) local code_inline = lpeg.Cmt(lpeg.C(P('`')^1), function(input, index, bt) - -- `foo`, ``foo``, ``foo`bar``, `foo``bar` are all allowed. - local _, e = input:find('[^`]' .. bt .. '%f[^`]', index) - return (e or #input) + 1 + -- `foo`, ``foo``, ``foo`bar``, `foo``bar` are all allowed. + local _, e = input:find('[^`]' .. bt .. '%f[^`]', index) + return (e or #input) + 1 end) lex:add_rule('block_code', lex:tag(lexer.CODE, code_line + code_block + code_inline)) lex:add_rule('blockquote', - lex:tag(lexer.STRING, lpeg.Cmt(lexer.starts_line('>', true), function(input, index) - local _, e = input:find('\n[ \t]*\r?\n', index) -- the next blank line (possibly with indentation) - return (e or #input) + 1 - end))) + lex:tag(lexer.STRING, lpeg.Cmt(lexer.starts_line('>', true), function(input, index) + local _, e = input:find('\n[ \t]*\r?\n', index) -- the next blank line (possibly with indentation) + return (e or #input) + 1 + end))) -- Span elements. lex:add_rule('escape', lex:tag(lexer.DEFAULT, P('\\') * 1)) local link_text = lexer.range('[', ']', true) local link_target = - '(' * (lexer.any - S(') \t'))^0 * (S(' \t')^1 * lexer.range('"', false, false))^-1 * ')' + '(' * (lexer.any - S(') \t'))^0 * (S(' \t')^1 * lexer.range('"', false, false))^-1 * ')' local link_url = 'http' * P('s')^-1 * '://' * (lexer.any - lexer.space)^1 + - ('<' * lexer.alpha^2 * ':' * (lexer.any - lexer.space - '>')^1 * '>') + ('<' * lexer.alpha^2 * ':' * (lexer.any - lexer.space - '>')^1 * '>') lex:add_rule('link', lex:tag(lexer.LINK, P('!')^-1 * link_text * link_target + link_url)) local link_ref = lex:tag(lexer.REFERENCE, link_text * S(' \t')^0 * lexer.range('[', ']', true)) @@ -61,7 +61,7 @@ local ref_link_label = lex:tag(lexer.REFERENCE, lexer.range('[', ']', true) * ': local ws = lex:get_rule('whitespace') local ref_link_url = lex:tag(lexer.LINK, (lexer.any - lexer.space)^1) local ref_link_title = lex:tag(lexer.STRING, lexer.range('"', true, false) + - lexer.range("'", true, false) + lexer.range('(', ')', true)) + lexer.range("'", true, false) + lexer.range('(', ')', true)) lex:add_rule('link_ref', link_ref + ref_link_label * ws * ref_link_url * (ws * ref_link_title)^-1) local punct_space = lexer.punct + lexer.space @@ -70,20 +70,20 @@ local punct_space = lexer.punct + lexer.space -- https://github.github.com/gfm/#emphasis-and-strong-emphasis in the cases where simple -- delimited ranges are not sufficient. local function flanked_range(s, not_inword) - local fl_char = lexer.any - s - lexer.space - local left_fl = B(punct_space - s) * s * #fl_char + s * #(fl_char - lexer.punct) - local right_fl = B(lexer.punct) * s * #(punct_space - s) + B(fl_char) * s - return left_fl * (lexer.any - blank_line - (not_inword and s * #punct_space or s))^0 * right_fl + local fl_char = lexer.any - s - lexer.space + local left_fl = B(punct_space - s) * s * #fl_char + s * #(fl_char - lexer.punct) + local right_fl = B(lexer.punct) * s * #(punct_space - s) + B(fl_char) * s + return left_fl * (lexer.any - blank_line - (not_inword and s * #punct_space or s))^0 * right_fl end local asterisk_strong = flanked_range('**') local underscore_strong = (B(punct_space) + #lexer.starts_line('_')) * flanked_range('__', true) * - #(punct_space + -1) + #(punct_space + -1) lex:add_rule('strong', lex:tag(lexer.BOLD, asterisk_strong + underscore_strong)) local asterisk_em = flanked_range('*') local underscore_em = (B(punct_space) + #lexer.starts_line('_')) * flanked_range('_', true) * - #(punct_space + -1) + #(punct_space + -1) lex:add_rule('em', lex:tag(lexer.ITALIC, asterisk_em + underscore_em)) -- Embedded HTML. |
