aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/gemini.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-11 01:27:32 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-03-27 06:04:21 -0600
commit4c4392d29df777ff702dfe99b4f3c23142976e05 (patch)
tree5355324abe18952f7d19d6cfc5dbeb5d6cb72b84 /lua/lexers/gemini.lua
parent95bf9f59f8a9a37148bdc0787db378d62c7cd032 (diff)
downloadvis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.gz
vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.xz
update lexers to orbitalquark/scintillua@b789dde
Rather than cherry pick patches from after 6.2 we will just grab everything as is.
Diffstat (limited to 'lua/lexers/gemini.lua')
-rw-r--r--lua/lexers/gemini.lua41
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