diff options
Diffstat (limited to 'lua/lexers/gemini.lua')
| -rw-r--r-- | lua/lexers/gemini.lua | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/lua/lexers/gemini.lua b/lua/lexers/gemini.lua index dc529d4..a5f78a3 100644 --- a/lua/lexers/gemini.lua +++ b/lua/lexers/gemini.lua @@ -1,42 +1,23 @@ - --- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE. --- Markdown LPeg lexer. --- Copyright 2020 Haelwenn (lanodan) Monnier <contact+gemini.lua@hacktivis.me> +-- Copyright 2020-2024 Haelwenn (lanodan) Monnier <contact+gemini.lua@hacktivis.me>. See LICENSE. -- Gemini / Gemtext LPeg lexer. -- See https://gemini.circumlunar.space/docs/specification.html -local lexer = require('lexer') -local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local lexer = lexer +local P, S = lpeg.P, lpeg.S -local lex = lexer.new('gemini') +local lex = lexer.new(...) -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) +local header = lex:tag(lexer.HEADING .. '.h3', lexer.to_eol(lexer.starts_line('###'))) + + lex:tag(lexer.HEADING .. '.h2', lexer.to_eol(lexer.starts_line('##'))) + + lex:tag(lexer.HEADING .. '.h1', lexer.to_eol(lexer.starts_line('#'))) 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 list = token('list', lexer.starts_line('*') * lexer.nonnewline^0) -lex:add_rule('list', list) -lex:add_style('list', lexer.styles.constant) -local blockquote = token(lexer.STRING, lexer.starts_line('>') * lexer.nonnewline^0) -lex:add_rule('blockquote', blockquote) +lex:add_rule('list', lex:tag(lexer.LIST, lexer.to_eol(lexer.starts_line('*')))) --- Should only match ``` at start of line -local pre = token('pre', lexer.range('```', false, true)) -lex:add_rule('pre', pre) -lex:add_style('pre', lexer.styles.embedded .. {eolfilled = true}) +lex:add_rule('blockquote', lex:tag(lexer.STRING, lexer.to_eol(lexer.starts_line('>')))) --- Whitespace. -local ws = token(lexer.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1) -lex:add_rule('whitespace', ws) +lex:add_rule('pre', lex:tag(lexer.CODE, lexer.to_eol(lexer.range('```', false, true)))) -local link = token('link', lexer.starts_line('=>') * lexer.nonnewline^0) -lex:add_rule('link', link) -lex:add_style('link', {underlined=true}) +lex:add_rule('link', lex:tag(lexer.LINK, lexer.to_eol(lexer.starts_line('=>')))) return lex |
