Merge pull request #864 from jgmdev/markdown-adjustments

language_md: removed scale adjustment code
This commit is contained in:
Jefferson González 2022-03-15 22:14:34 -04:00 committed by GitHub
commit 20763ed7ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 42 deletions

View File

@ -3,7 +3,6 @@ local syntax = require "core.syntax"
local style = require "core.style" local style = require "core.style"
local core = require "core" local core = require "core"
local initial_scale = SCALE
local initial_color = style.syntax["keyword2"] local initial_color = style.syntax["keyword2"]
-- Add 3 type of font styles for use on markdown files -- Add 3 type of font styles for use on markdown files
@ -121,46 +120,45 @@ syntax.add {
{ pattern = { "```liquid", "```" }, type = "string", syntax = ".liquid" }, { pattern = { "```liquid", "```" }, type = "string", syntax = ".liquid" },
{ pattern = { "```", "```" }, type = "string" }, { pattern = { "```", "```" }, type = "string" },
{ pattern = { "``", "``" }, type = "string" }, { pattern = { "``", "``" }, type = "string" },
{ pattern = { "`", "`" }, type = "string" }, { pattern = { "%f[\\`]%`[%S]", "`" }, type = "string" },
-- strike -- strike
{ pattern = { "~~", "~~" }, type = "keyword2" }, { pattern = { "~~", "~~" }, type = "keyword2" },
-- highlight -- highlight
{ pattern = { "==", "==" }, type = "literal" }, { pattern = { "==", "==" }, type = "literal" },
-- lines -- lines
{ regex = "^\\-{2,}\\-$", type = "comment" }, { pattern = "^%-%-%-+\n", type = "comment" },
{ regex = "^\\*{2,}\\*$", type = "comment" }, { pattern = "^%*%*%*+\n", type = "comment" },
{ regex = "^\\_{2,}_$", type = "comment" }, { pattern = "^___+\n", type = "comment" },
-- bullets -- bullets
{ regex = "^\\s*\\*\\s", type = "number" }, { pattern = "^%s*%*%s", type = "number" },
{ regex = "^\\s*-\\s", type = "number" }, { pattern = "^%s*%-%s", type = "number" },
{ regex = "^\\s*\\+\\s", type = "number" }, { pattern = "^%s*%+%s", type = "number" },
-- numbered bullet -- numbered bullet
{ regex = "^\\s*[0-9]+\\.\\s", type = "number" }, { pattern = "^%s*[0-9]+%.%s", type = "number" },
-- blockquote -- blockquote
{ regex = "^\\s*>{1,}\\s", type = "string" }, { pattern = "^%s*>+%s", type = "string" },
-- bold and italic -- bold and italic
{ pattern = { "%*%*%*", "%*%*%*" }, type = "markdown_bold_italic" }, { pattern = { "%*%*%*%S", "%*%*%*" }, type = "markdown_bold_italic" },
{ pattern = { "%*%*", "%*%*" }, type = "markdown_bold" }, { pattern = { "%*%*%S", "%*%*" }, type = "markdown_bold" },
-- handle edge case where asterisk can be at end of line and not close -- handle edge case where asterisk can be at end of line and not close
{ pattern = { "%*[%S]", "%*" }, type = "markdown_italic" },
-- alternative bold italic formats
{ {
regex = "^_{3}[\\s[:punct:]A-Za-z0-9]+_{3}\\s" , pattern = { "%f[\\%*]%*[%S]", "%*%f[^%*]" },
type = "markdown_bold_italic"
},
{
regex = "^_{2}[\\s[:punct:]A-Za-z0-9]+_{2}\\s" ,
type = "markdown_bold"
},
{
regex = "^_{1}[\\s[:punct:]A-Za-z0-9]+_{1}\\s" ,
type = "markdown_italic" type = "markdown_italic"
}, },
-- alternative bold italic formats
{ pattern = "^___[%s%p%w]+___%s" , type = "markdown_bold_italic" },
{ pattern = "^__[%s%p%w]+__%s" , type = "markdown_bold" },
{ pattern = "^_[%s%p%w]+_%s" , type = "markdown_italic" },
{ pattern = { "%s___", "___%f[%s]" }, type = "markdown_bold_italic" }, { pattern = { "%s___", "___%f[%s]" }, type = "markdown_bold_italic" },
{ pattern = { "%s__", "__%f[%s]" }, type = "markdown_bold" }, { pattern = { "%s__", "__%f[%s]" }, type = "markdown_bold" },
{ pattern = { "%s_[%S]", "_%f[%s]" }, type = "markdown_italic" }, { pattern = { "%s_[%S]", "_%f[%s]" }, type = "markdown_italic" },
-- heading with custom id
{
pattern = "^#+%s[%w%s%p]+(){()#[%w%-]+()}",
type = { "keyword", "function", "string", "function" }
},
-- headings -- headings
{ regex = "^#{1,6}.+", type = "keyword" }, { pattern = "^#+%s.+\n", type = "keyword" },
-- superscript and subscript -- superscript and subscript
{ {
pattern = "%^()%d+()%^", pattern = "%^()%d+()%^",
@ -171,13 +169,17 @@ syntax.add {
type = { "function", "number", "function" } type = { "function", "number", "function" }
}, },
-- definitions -- definitions
{ regex = "^:\\s.+", type = "function" }, { pattern = "^:%s.+", type = "function" },
-- emoji -- emoji
{ pattern = ":[a-zA-Z0-9_%-]+:", type = "literal" }, { pattern = ":[a-zA-Z0-9_%-]+:", type = "literal" },
-- images and links -- images and link
{ {
pattern = "!?%[()["..in_squares_match.."]+()%]()%(()["..in_parenthesis_match.."]+()%)", pattern = "!?%[!?%[()["..in_squares_match.."]+()%]%(()["..in_parenthesis_match.."]+()%)%]%(()["..in_parenthesis_match.."]+()%)",
type = { "function", "string", "function", "function", "number", "function" } type = { "function", "string", "function", "number", "function", "number", "function" }
},
{
pattern = "!?%[!?%[?()["..in_squares_match.."]+()%]?%]%(()["..in_parenthesis_match.."]+()%)",
type = { "function", "string", "function", "number", "function" }
}, },
-- reference links -- reference links
{ {
@ -185,11 +187,15 @@ syntax.add {
type = { "function", "string", "function", "function", "number", "function" } type = { "function", "string", "function", "function", "number", "function" }
}, },
{ {
pattern = "%[%^?()["..in_squares_match.."]+()%]: ", pattern = "^%s*%[%^()["..in_squares_match.."]+()%]: ",
type = { "function", "number", "function" } type = { "function", "number", "function" }
}, },
{ {
pattern = "%[%^?()["..in_squares_match.."]+()%]", pattern = "^%s*%[%^?()["..in_squares_match.."]+()%]:%s+.+\n",
type = { "function", "number", "function" }
},
{
pattern = "!?%[%^?()["..in_squares_match.."]+()%]",
type = { "function", "number", "function" } type = { "function", "number", "function" }
}, },
-- url's and email -- url's and email
@ -203,20 +209,9 @@ syntax.add {
symbols = { }, symbols = { },
} }
-- Adjust markdown fonts on scale changes. -- Adjust the color on theme changes
-- Note: this should be performed by lite-xl it self to all style.syntax_fonts
core.add_thread(function() core.add_thread(function()
while true do while true do
if initial_scale ~= SCALE then
for _, attr in pairs({"bold", "italic", "bold_italic"}) do
style.syntax_fonts["markdown_"..attr] =
style.syntax_fonts["markdown_"..attr]:copy(
style.code_font:get_size()
)
end
initial_scale = SCALE
end
-- we also adjust the color on theme changes
if initial_color ~= style.syntax["keyword2"] then if initial_color ~= style.syntax["keyword2"] then
for _, attr in pairs({"bold", "italic", "bold_italic"}) do for _, attr in pairs({"bold", "italic", "bold_italic"}) do
style.syntax["markdown_"..attr] = style.syntax["keyword2"] style.syntax["markdown_"..attr] = style.syntax["keyword2"]