From 329559b74b483576a74d5f87eebf951bd12b9200 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 7 Jul 2020 20:14:11 -0400 Subject: lexlua: Added `lexer.colors` and `lexer.styles` tables for themes and lexers. This allows for a more Lua table-oriented approach to defining and using colors and styles, instead of manually manipulating Scintilla property strings. Themes and lexers are still backwards compatible, as the underlying mechanisms are still in place. --- lexlua/markdown.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lexlua/markdown.lua') diff --git a/lexlua/markdown.lua b/lexlua/markdown.lua index fbedb2418..733c39fec 100644 --- a/lexlua/markdown.lua +++ b/lexlua/markdown.lua @@ -12,10 +12,11 @@ local function h(n) return token('h' .. 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)) +local font_size = + tonumber(lexer.property_expanded['style.default']:match('size:(%d+)')) or 10 local function add_header_style(n) - local font_size = lexer.property_int['fontsize'] > 0 and - lexer.property_int['fontsize'] or 10 - lex:add_style('h' .. n, 'fore:$(color.red),size:' .. (font_size + (6 - n))) + lex:add_style( + 'h' .. n, {fore = lexer.colors.red, size = (font_size + (6 - n))}) end for i = 1, 6 do add_header_style(i) end @@ -42,7 +43,7 @@ local code_inline = lpeg.Cmt(lpeg.C(P('`')^1), function(input, index, bt) return (e or #input) + 1 end) lex:add_rule('block_code', token('code', code_line + code_block + code_inline)) -lex:add_style('code', lexer.STYLE_EMBEDDED .. ',eolfilled') +lex:add_style('code', lexer.STYLE_EMBEDDED .. {eolfilled = true}) lex:add_rule('hr', token('hr', lpeg.Cmt( lexer.starts_line(S(' \t')^0 * lpeg.C(S('*-_'))), function(input, index, c) @@ -50,7 +51,7 @@ lex:add_rule('hr', token('hr', lpeg.Cmt( if line:find('[^' .. c .. ']') or #line < 2 then return nil end return (select(2, input:find('\r?\n', index)) or #input) + 1 end))) -lex:add_style('hr', 'back:$(color.black),eolfilled') +lex:add_style('hr', {back = lexer.colors.black, eolfilled = true}) -- Whitespace. local ws = token(lexer.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1) @@ -66,7 +67,7 @@ local ref_link_title = token(lexer.STRING, lexer.range('"', true, false) + lex:add_rule('link_label', ref_link_label * ws * ref_link_url * (ws * ref_link_title)^-1) lex:add_style('link_label', lexer.STYLE_LABEL) -lex:add_style('link_url', 'underlined') +lex:add_style('link_url', {underlined = true}) local link_label = P('!')^-1 * lexer.range('[', ']', true) local link_target = P('(') * (lexer.any - S(') \t'))^0 * @@ -75,7 +76,7 @@ local link_ref = S(' \t')^0 * lexer.range('[', ']', true) local link_url = 'http' * P('s')^-1 * '://' * (lexer.any - lexer.space)^1 lex:add_rule('link', token('link', link_label * (link_target + link_ref) + link_url)) -lex:add_style('link', 'underlined') +lex:add_style('link', {underlined = true}) local punct_space = lexer.punct + lexer.space @@ -95,12 +96,12 @@ end lex:add_rule('strong', token('strong', flanked_range('**') + (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('__', true) * #(punct_space + -1))) -lex:add_style('strong', 'bold') +lex:add_style('strong', {bold = true}) lex:add_rule('em', token('em', flanked_range('*') + (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('_', true) * #(punct_space + -1))) -lex:add_style('em', 'italics') +lex:add_style('em', {italics = true}) -- Embedded HTML. local html = lexer.load('html') -- cgit v1.2.3