aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-12-03 07:09:14 +0100
committerMarc André Tanner <mat@brain-dump.org>2020-12-08 10:17:22 +0100
commit468f9ee1b027a7ce98b1a249fa1af5888feeb989 (patch)
treec1486b85065cef5e1be0381c5558146e105ffc62 /lua/lexers
parent6b0da60dc63db7839f14fd78c48055bc706645d6 (diff)
downloadvis-468f9ee1b027a7ce98b1a249fa1af5888feeb989.tar.gz
vis-468f9ee1b027a7ce98b1a249fa1af5888feeb989.tar.xz
Add gemini lexer
Diffstat (limited to 'lua/lexers')
-rw-r--r--lua/lexers/gemini.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/lua/lexers/gemini.lua b/lua/lexers/gemini.lua
new file mode 100644
index 0000000..6755de9
--- /dev/null
+++ b/lua/lexers/gemini.lua
@@ -0,0 +1,48 @@
+-- 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 P, R, S = lpeg.P, lpeg.R, lpeg.S
+
+local M = {_NAME = 'gemini'}
+
+local ws = token(l.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1)
+
+local link = token('link', l.starts_line('=>') * l.nonnewline^0)
+
+-- 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