diff options
Diffstat (limited to 'lua/lexers/gemini.lua')
| -rw-r--r-- | lua/lexers/gemini.lua | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/lua/lexers/gemini.lua b/lua/lexers/gemini.lua index 6755de9..dc529d4 100644 --- a/lua/lexers/gemini.lua +++ b/lua/lexers/gemini.lua @@ -1,48 +1,42 @@ + -- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE. -- Markdown LPeg lexer. -- Copyright 2020 Haelwenn (lanodan) Monnier <contact+gemini.lua@hacktivis.me> -- Gemini / Gemtext LPeg lexer. -- See https://gemini.circumlunar.space/docs/specification.html -local l = require('lexer') -local token, word_match = l.token, l.word_match +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match local P, R, S = lpeg.P, lpeg.R, lpeg.S -local M = {_NAME = 'gemini'} +local lex = lexer.new('gemini') + +local header = token('h3', lexer.starts_line('###') * lexer.nonnewline^0) + + token('h2', lexer.starts_line('##') * lexer.nonnewline^0) + + token('h1', lexer.starts_line('#') * lexer.nonnewline^0) +lex:add_rule('header', header) +lex:add_style('h1', {fore = lexer.colors.red, size = 15}) +lex:add_style('h2', {fore = lexer.colors.red, size = 14}) +lex:add_style('h3', {fore = lexer.colors.red, size = 13}) -local ws = token(l.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1) +local list = token('list', lexer.starts_line('*') * lexer.nonnewline^0) +lex:add_rule('list', list) +lex:add_style('list', lexer.styles.constant) -local link = token('link', l.starts_line('=>') * l.nonnewline^0) +local blockquote = token(lexer.STRING, lexer.starts_line('>') * lexer.nonnewline^0) +lex:add_rule('blockquote', blockquote) -- Should only match ``` at start of line -local pre = token('pre', l.delimited_range('```', false, true)) - -local header = token('h3', l.starts_line('###') * l.nonnewline^0) + - token('h2', l.starts_line('##') * l.nonnewline^0) + - token('h1', l.starts_line('#') * l.nonnewline^0) - -local list = token('list', l.starts_line('*') * l.nonnewline^0) - -local blockquote = token(l.STRING, l.starts_line('>') * l.nonnewline^0) - -M._rules = { - {'header', header}, - {'list', list}, - {'blockquote', blockquote}, - {'pre', pre}, - {'whitespace', ws}, - {'link', link} -} - -local font_size = 10 -local hstyle = 'fore:red' -M._tokenstyles = { - h3 = hstyle..',size:'..(font_size + 3), - h2 = hstyle..',size:'..(font_size + 4), - h1 = hstyle..',size:'..(font_size + 5), - pre = l.STYLE_EMBEDDED..',eolfilled', - link = 'underlined', - list = l.STYLE_CONSTANT -} - -return M +local pre = token('pre', lexer.range('```', false, true)) +lex:add_rule('pre', pre) +lex:add_style('pre', lexer.styles.embedded .. {eolfilled = true}) + +-- Whitespace. +local ws = token(lexer.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1) +lex:add_rule('whitespace', ws) + +local link = token('link', lexer.starts_line('=>') * lexer.nonnewline^0) +lex:add_rule('link', link) +lex:add_style('link', {underlined=true}) + +return lex |
