diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..7c81ce9 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,26 @@ +# vim:nospell: + +on: + push: + branches: + - dev + +permissions: + contents: write + pull-requests: write + +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4 + with: + # this assumes that you have created a personal access token + # (PAT) and configured it as a GitHub action secret named + # `MY_RELEASE_PLEASE_TOKEN` (this secret name is not important). + token: ${{ secrets.RELEASE_PLEASE_TOKEN }} + # this is a built-in strategy in release-please, see "Action Inputs" + # for more options + release-type: simple diff --git a/ftplugin/markdown.lua b/ftplugin/markdown.lua index a11475d..4053695 100644 --- a/ftplugin/markdown.lua +++ b/ftplugin/markdown.lua @@ -135,10 +135,6 @@ vim.api.nvim_create_autocmd({ "ModeChanged", "TextChanged" }, { local partial_contents = markview.parser.parse_range(event.buf, markview.configuration, parse_start, parse_stop); local current_range = markview.renderer.get_content_range(partial_contents); - -- vim.print(current_range) - -- Update the range first or it gets messed up later - markview.renderer.update_range(buffer, current_range); - if markview.configuration.hybrid_modes and vim.list_contains(markview.configuration.hybrid_modes, mode) then markview.renderer.render(buffer, parsed_content, markview.configuration, parse_start, parse_stop); markview.renderer.clear_content_range(event.buf, partial_contents) @@ -146,6 +142,9 @@ vim.api.nvim_create_autocmd({ "ModeChanged", "TextChanged" }, { markview.renderer.render(buffer, parsed_content, markview.configuration); end + -- Or else things won't render on first redraw from the other autocmd + markview.renderer.update_range(buffer, current_range); + for _, window in ipairs(windows) do markview.keymaps.init(buffer, window, parsed_content, markview.configuration); end @@ -206,6 +205,7 @@ vim.api.nvim_create_autocmd(events, { local current_range = markview.renderer.get_content_range(partial_contents); + vim.print(_G.__markview_render_ranges[event.buf]) -- Don't draw new things if _G.__markview_render_ranges[event.buf] and vim.deep_equal(_G.__markview_render_ranges[event.buf], current_range) then markview.renderer.clear_content_range(event.buf, partial_contents) diff --git a/lua/markview.lua b/lua/markview.lua index 3949950..a1831c2 100644 --- a/lua/markview.lua +++ b/lua/markview.lua @@ -1,11 +1,11 @@ local markview = {}; local utils = require("markview.utils"); -markview.parser = require("markview/parser"); -markview.renderer = require("markview/renderer"); -markview.keymaps = require("markview/keymaps"); +markview.parser = require("markview.parser"); +markview.renderer = require("markview.renderer"); +markview.keymaps = require("markview.keymaps"); -markview.colors = require("markview/colors"); +markview.colors = require("markview.colors"); markview.add_hls = function (obj) local use_hl = {}; @@ -63,251 +63,851 @@ markview.configuration = { }, highlight_groups = { + ---+ ##code## { + -- Heading level 1 output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "markdownH1", "fg") or "#f38ba8"; - - return { - { - group_name = "Col1", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col1Fg", - value = { - fg = fg - } - }, - { - group_name = "Col1Inv", - value = { - bg = fg, - fg = bg - } - }, - } + if markview.colors.get_hl_value(0, "DiagnosticVirtualTextOk", "bg") and markview.colors.get_hl_value(0, "DiagnosticVirtualTextOk", "fg") then + local bg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextOk", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextOk", "fg"); + + return { + { + group_name = "Heading1", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading1Sign", + value = { + fg = fg, + + default = true + } + }, + } + elseif markview.colors.get_hl_value(0, "DiagnosticOk", "fg") and markview.colors.get_hl_value(0, "Normal", "bg") then + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticOk", "fg"); + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading1", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading1Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + else + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = vim.o.background == "dark" and "#a6e3a1" or "#40a02b"; + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading1", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading1Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + end end }, - { + -- Heading level 2 output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "markdownH2", "fg") or "#fab387"; - - return { - { - group_name = "Col2", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col2Fg", - value = { - fg = fg - } - }, - { - group_name = "Col2Inv", - value = { - bg = fg, - fg = bg - } - }, - } + if markview.colors.get_hl_value(0, "DiagnosticVirtualTextHint", "bg") and markview.colors.get_hl_value(0, "DiagnosticVirtualTextHint", "fg") then + local bg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextHint", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextHint", "fg"); + + return { + { + group_name = "Heading2", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading2Sign", + value = { + fg = fg, + + default = true + } + }, + } + elseif markview.colors.get_hl_value(0, "DiagnosticHint", "fg") and markview.colors.get_hl_value(0, "Normal", "bg") then + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticHint", "fg"); + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading2", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading2Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + else + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = vim.o.background == "dark" and "#94e2d5" or "#179299"; + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading2", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading2Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + end end }, - { + -- Heading level 3 output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "markdownH3", "fg") or "#f9e2af"; - - return { - { - group_name = "Col3", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col3Fg", - value = { - fg = fg - } - }, - { - group_name = "Col3Inv", - value = { - bg = fg, - fg = bg - } - }, - } + if markview.colors.get_hl_value(0, "DiagnosticVirtualTextInfo", "bg") and markview.colors.get_hl_value(0, "DiagnosticVirtualTextInfo", "fg") then + local bg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextInfo", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextInfo", "fg"); + + return { + { + group_name = "Heading3", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading3Sign", + value = { + fg = fg, + + default = true + } + }, + } + elseif markview.colors.get_hl_value(0, "DiagnosticInfo", "fg") and markview.colors.get_hl_value(0, "Normal", "bg") then + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticInfo", "fg"); + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading3", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading3Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + else + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = vim.o.background == "dark" and "#89dceb" or "#179299"; + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading3", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading3Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + end end }, - { + -- Heading level 4 output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "markdownH4", "fg") or "#a6e3a1"; - - - return { - { - group_name = "Col4", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col4Fg", - value = { - fg = fg - } - }, - { - group_name = "Col4Inv", - value = { - bg = fg, - fg = bg - } - }, - } + if markview.colors.get_hl_value(0, "Special", "bg") and markview.colors.get_hl_value(0, "Special", "fg") then + local bg = markview.colors.get_hl_value(0, "Special", "bg"); + local fg = markview.colors.get_hl_value(0, "Special", "fg"); + + return { + { + group_name = "Heading4", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading4Sign", + value = { + fg = fg, + + default = true + } + }, + } + elseif markview.colors.get_hl_value(0, "Special", "fg") and markview.colors.get_hl_value(0, "Normal", "bg") then + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = markview.colors.get_hl_value(0, "Special", "fg"); + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading4", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading4Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + else + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = vim.o.background == "dark" and "#f5c2e7" or "#ea76cb"; + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading4", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading4Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + end end }, - { + -- Heading level 5 output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "markdownH5", "fg") or "#74c7ec"; - - return { - { - group_name = "Col5", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col5Fg", - value = { - fg = fg - } - }, - { - group_name = "Col5Inv", - value = { - bg = fg, - fg = bg - } - }, - } + if markview.colors.get_hl_value(0, "DiagnosticVirtualTextWarn", "bg") and markview.colors.get_hl_value(0, "DiagnosticVirtualTextWarn", "fg") then + local bg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextWarn", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextWarn", "fg"); + + return { + { + group_name = "Heading5", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading5Sign", + value = { + fg = fg, + + default = true + } + }, + } + elseif markview.colors.get_hl_value(0, "DiagnosticWarn", "fg") and markview.colors.get_hl_value(0, "Normal", "bg") then + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticWarn", "fg"); + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading5", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading5Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + else + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = vim.o.background == "dark" and "#F9E3AF" or "#DF8E1D"; + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading5", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading5Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + end end }, - { + -- Heading level 6 output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "markdownH6", "fg") or "#b4befe"; - - return { - { - group_name = "Col6", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col6Fg", - value = { - fg = fg - } - }, - { - group_name = "Col6Inv", - value = { - bg = fg, - fg = bg - } - }, - } + if markview.colors.get_hl_value(0, "DiagnosticVirtualTextError", "bg") and markview.colors.get_hl_value(0, "DiagnosticVirtualTextError", "fg") then + local bg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextError", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticVirtualTextError", "fg"); + + return { + { + group_name = "Heading6", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading6Sign", + value = { + fg = fg, + + default = true + } + }, + } + elseif markview.colors.get_hl_value(0, "DiagnosticError", "fg") and markview.colors.get_hl_value(0, "Normal", "bg") then + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = markview.colors.get_hl_value(0, "DiagnosticError", "fg"); + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading6", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading6Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + else + local bg = markview.colors.get_hl_value(0, "Normal", "bg"); + local fg = vim.o.background == "dark" and "#F38BA8" or "#D20F39"; + + local nr = markview.colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading6", + value = { + bg = vim.o.background == "dark" + and + markview.colors.mix(bg, fg, 0.5, 0.15) + or + markview.colors.mix(bg, fg, 0.85, 0.20), + fg = fg, + + default = true + } + }, + { + group_name = "Heading6Sign", + value = { + bg = nr, + fg = fg, + + default = true + } + }, + } + end end }, + { - output = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "Comment", "fg"); - - return { - { - group_name = "Col7", - value = { - bg = markview.colors.mix(bg, fg, 0.7, 0.25), - fg = fg - } - }, - { - group_name = "Col7Fg", - value = { - fg = fg - } - }, - { - group_name = "Col7Inv", - value = { - bg = fg, - fg = bg - } - }, - } + group_name = "BlockQuoteDefault", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "Comment", "fg"), + + vim.o.background == "dark" and "#6c7086" or "#9ca0b0"; + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "BlockQuoteError", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticError", "fg"), + + vim.o.background == "dark" and "#F38BA8" or "#D20F39"; + }); + + return { fg = fg, default = true }; end }, + { + group_name = "BlockQuoteWarn", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticWarn", "fg"), + vim.o.background == "dark" and "#F9E3AF" or "#DF8E1D"; + }); + + return { fg = fg, default = true }; + end + }, { - group_name = "Layer", + group_name = "BlockQuoteOk", value = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "Comment", "fg"); + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticOk", "fg"), - local txt = markview.colors.get_hl_value(0, "FloatTitle", "fg") + vim.o.background == "dark" and "#a6e3a1" or "#40a02b"; + }); - return { - bg = markview.colors.mix(bg, fg, 1, 0.20), - fg = txt - } + return { fg = fg, default = true }; end }, { - group_name = "Layer2", + group_name = "BlockQuoteNote", value = function () - local bg = markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"); - local fg = markview.colors.get_hl_value(0, "Comment", "fg"); + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "@comment.note", "bg"), + markview.colors.get_hl_value(0, "@comment.note", "fg"), - return { - bg = markview.colors.mix(bg, fg, 0.85, 0.13), - } + markview.colors.get_hl_value(0, "Title", "fg"), + vim.o.background == "dark" and "#89b4fa" or "#1e66f5" + }); + + return { fg = fg, default = true }; end }, + { + group_name = "BlockQuoteSpecial", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "Conditional", "fg"), + markview.colors.get_hl_value(0, "Keyword", "fg"), + + vim.o.background == "dark" and "#cba6f7" or "#8839ef" + }); + + return { fg = fg, default = true }; + end + }, + + + + { + group_name = "Code", + value = function () + local bg = markview.colors.get({ + markview.colors.get_hl_value(0, "Normal", "bg"), + markview.colors.get_hl_value(0, "Cursor", "fg"), + + vim.o.background == "dark" and "#1e1e2e" or "#cdd6f4" + }); + + local luminosity = markview.colors.get_brightness(bg); + + if luminosity < 0.5 then + return { + bg = markview.colors.mix(bg, bg, 1, math.max(luminosity, 0.25)), + default = true + }; + else + return { + bg = markview.colors.mix(bg, bg, 1, math.min(luminosity, 0.25) * -1), + default = true + }; + end + end + }, + + + { + group_name = "CheckboxChecked", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticOk", "fg"), + + vim.o.background == "dark" and "#a6e3a1" or "#40a02b"; + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "CheckboxUnchecked", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticError", "fg"), + + vim.o.background == "dark" and "#F38BA8" or "#D20F39"; + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "CheckboxPending", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticWarn", "fg"), + + vim.o.background == "dark" and "#F9E3AF" or "#DF8E1D"; + }); + + return { fg = fg, default = true }; + end + }, + + + { + group_name = "TableBorder", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "@comment.note", "bg"), + markview.colors.get_hl_value(0, "@comment.note", "fg"), + + markview.colors.get_hl_value(0, "Title", "fg"), + vim.o.background == "dark" and "#89b4fa" or "#1e66f5" + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "TableAlignLeft", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "@comment.note", "bg"), + markview.colors.get_hl_value(0, "@comment.note", "fg"), + + markview.colors.get_hl_value(0, "Title", "fg"), + vim.o.background == "dark" and "#89b4fa" or "#1e66f5" + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "TableAlignRight", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "@comment.note", "bg"), + markview.colors.get_hl_value(0, "@comment.note", "fg"), + + markview.colors.get_hl_value(0, "Title", "fg"), + vim.o.background == "dark" and "#89b4fa" or "#1e66f5" + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "TableAlignCenter", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "@comment.note", "bg"), + markview.colors.get_hl_value(0, "@comment.note", "fg"), + + markview.colors.get_hl_value(0, "Title", "fg"), + vim.o.background == "dark" and "#89b4fa" or "#1e66f5" + }); + + return { fg = fg, default = true }; + end + }, + + + { + group_name = "ListItemMinus", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticWarn", "fg"), + + vim.o.background == "dark" and "#F9E3AF" or "#DF8E1D"; + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "ListItemPlus", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "DiagnosticOk", "fg"), + + vim.o.background == "dark" and "#a6e3a1" or "#40a02b"; + }); + + return { fg = fg, default = true }; + end + }, + { + group_name = "ListItemStar", + value = function () + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "@comment.note", "bg"), + markview.colors.get_hl_value(0, "@comment.note", "fg"), + + markview.colors.get_hl_value(0, "Title", "fg"), + vim.o.background == "dark" and "#89b4fa" or "#1e66f5" + }); + + return { fg = fg, default = true }; + end + }, + + + { + group_name = "Hyperlink", + value = function () + if markview.colors.get_hl_value(0, "markdownLinkText", "fg") then + return { link = "markdownLinkText", default = true }; + elseif markview.colors.get_hl_value(0, "@markup.link.label.markdown_inline", "fg") then + return { link = "@markup.link.label.markdown_inline", default = true }; + end + + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "Label", "fg"), + + vim.o.background == "dark" and "#74c7ec" or "#209fb5" + }); + + return { fg = fg, underline = true, default = true }; + end + }, + { + group_name = "ImageLink", + value = function () + if markview.colors.get_hl_value(0, "markdownLinkText", "fg") then + return { link = "markdownLinkText", default = true }; + elseif markview.colors.get_hl_value(0, "@markup.link.label.markdown_inline", "fg") then + return { link = "@markup.link.label.markdown_inline", default = true }; + end + + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "Label", "fg"), + + vim.o.background == "dark" and "#74c7ec" or "#209fb5" + }); + + return { fg = fg, underline = true, default = true }; + end + }, + { + group_name = "Email", + value = function () + if markview.colors.get_hl_value(0, "@markup.link.url.markdown_inline", "fg") then + return { link = "@markup.link.url.markdown_inline", default = true }; + elseif markview.colors.get_hl_value(0, "@markup.link.url", "fg") then + return { link = "@markup.link.url", default = true }; + end + + local fg = markview.colors.get({ + markview.colors.get_hl_value(0, "Label", "fg"), + + vim.o.background == "dark" and "#f5e0dc" or "#dc8a78" + }); + + return { fg = fg, underline = true, default = true }; + end + }, + + { output = function () return markview.colors.create_gradient("Gradient", markview.colors.get_hl_value(0, "Normal", "bg") or markview.colors.get_hl_value(0, "Cursor", "fg"), markview.colors.get_hl_value(0, "Title", "fg"), 10, "fg"); end } + ---_ }, buf_ignore = { "nofile" }, modes = { "n", "no" }, + special_modes = nil, headings = { enable = true, @@ -315,48 +915,48 @@ markview.configuration = { heading_1 = { style = "icon", - sign = "󰌕 ", sign_hl = "MarkviewCol1Fg", + sign = "󰌕 ", sign_hl = "MarkviewHeading1Sign", - icon = "󰼏 ", hl = "MarkviewCol1", + icon = "󰼏 ", hl = "MarkviewHeading1", }, heading_2 = { style = "icon", - sign = "󰌖 ", sign_hl = "MarkviewCol2Fg", + sign = "󰌖 ", sign_hl = "MarkviewHeading2Sign", - icon = "󰎨 ", hl = "MarkviewCol2", + icon = "󰎨 ", hl = "MarkviewHeading2", }, heading_3 = { style = "icon", - icon = "󰼑 ", hl = "MarkviewCol3", + icon = "󰼑 ", hl = "MarkviewHeading3", }, heading_4 = { style = "icon", - icon = "󰎲 ", hl = "MarkviewCol4", + icon = "󰎲 ", hl = "MarkviewHeading4", }, heading_5 = { style = "icon", - icon = "󰼓 ", hl = "MarkviewCol5", + icon = "󰼓 ", hl = "MarkviewHeading5", }, heading_6 = { style = "icon", - icon = "󰎴 ", hl = "MarkviewCol6", + icon = "󰎴 ", hl = "MarkviewHeading6", }, setext_1 = { style = "github", - icon = "  ", hl = "MarkviewCol1", + icon = "  ", hl = "MarkviewHeading1", underline = "━" }, setext_2 = { style = "github", - icon = "  ", hl = "MarkviewCol2", + icon = "  ", hl = "MarkviewHeading2", underline = "─" } }, @@ -365,7 +965,7 @@ markview.configuration = { enable = true, style = "language", - hl = "Layer2", + hl = "MarkviewCode", min_width = 60, pad_amount = 3, @@ -383,7 +983,7 @@ markview.configuration = { enable = true, default = { - border = "▋", border_hl = "MarkviewCol7Fg" + border = "▋", border_hl = "MarkviewBlockQuoteDefault" }, callouts = { @@ -391,139 +991,139 @@ markview.configuration = { { match_string = "ABSTRACT", callout_preview = "󱉫 Abstract", - callout_preview_hl = "MarkviewCol5Fg", + callout_preview_hl = "MarkviewBlockQuoteNote", custom_title = true, custom_icon = "󱉫 ", - border = "▋", border_hl = "MarkviewCol5Fg" + border = "▋", border_hl = "MarkviewBlockQuoteNote" }, { match_string = "TODO", callout_preview = " Todo", - callout_preview_hl = "MarkviewCol5Fg", + callout_preview_hl = "MarkviewBlockQuoteNote", custom_title = true, custom_icon = " ", - border = "▋", border_hl = "MarkviewCol5Fg" + border = "▋", border_hl = "MarkviewBlockQuoteNote" }, { match_string = "SUCCESS", callout_preview = "󰗠 Success", - callout_preview_hl = "MarkviewCol4Fg", + callout_preview_hl = "MarkviewBlockQuoteOk", custom_title = true, custom_icon = "󰗠 ", - border = "▋", border_hl = "MarkviewCol4Fg" + border = "▋", border_hl = "MarkviewBlockQuoteOk" }, { match_string = "QUESTION", callout_preview = "󰋗 Question", - callout_preview_hl = "MarkviewCol2Fg", + callout_preview_hl = "MarkviewBlockQuoteWarn", custom_title = true, custom_icon = "󰋗 ", - border = "▋", border_hl = "MarkviewCol2Fg" + border = "▋", border_hl = "MarkviewBlockQuoteWarn" }, { match_string = "FAILURE", callout_preview = "󰅙 Failure", - callout_preview_hl = "MarkviewCol1Fg", + callout_preview_hl = "MarkviewBlockQuoteError", custom_title = true, custom_icon = "󰅙 ", - border = "▋", border_hl = "MarkviewCol1Fg" + border = "▋", border_hl = "MarkviewBlockQuoteError" }, { match_string = "DANGER", callout_preview = " Danger", - callout_preview_hl = "MarkviewCol1Fg", + callout_preview_hl = "MarkviewBlockQuoteError", custom_title = true, custom_icon = "  ", - border = "▋", border_hl = "MarkviewCol1Fg" + border = "▋", border_hl = "MarkviewBlockQuoteError" }, { match_string = "BUG", callout_preview = " Bug", - callout_preview_hl = "MarkviewCol1Fg", + callout_preview_hl = "MarkviewBlockQuoteError", custom_title = true, custom_icon = "  ", - border = "▋", border_hl = "MarkviewCol1Fg" + border = "▋", border_hl = "MarkviewBlockQuoteError" }, { match_string = "EXAMPLE", callout_preview = "󱖫 Example", - callout_preview_hl = "MarkviewCol6Fg", + callout_preview_hl = "MarkviewBlockQuoteSpecial", custom_title = true, custom_icon = " 󱖫 ", - border = "▋", border_hl = "MarkviewCol6Fg" + border = "▋", border_hl = "MarkviewBlockQuoteSpecial" }, { match_string = "QUOTE", callout_preview = " Quote", - callout_preview_hl = "MarkviewCol7Fg", + callout_preview_hl = "MarkviewBlockQuoteDefault", custom_title = true, custom_icon = "  ", - border = "▋", border_hl = "MarkviewCol7Fg" + border = "▋", border_hl = "MarkviewBlockQuoteDefault" }, { match_string = "NOTE", callout_preview = "󰋽 Note", - callout_preview_hl = "MarkviewCol5Fg", + callout_preview_hl = "MarkviewBlockQuoteNote", - border = "▋", border_hl = "MarkviewCol5Fg" + border = "▋", border_hl = "MarkviewBlockQuoteNote" }, { match_string = "TIP", callout_preview = " Tip", - callout_preview_hl = "MarkviewCol4Fg", + callout_preview_hl = "MarkviewBlockQuoteOk", - border = "▋", border_hl = "MarkviewCol4Fg" + border = "▋", border_hl = "MarkviewBlockQuoteOk" }, { match_string = "IMPORTANT", callout_preview = " Important", - callout_preview_hl = "MarkviewCol3Fg", + callout_preview_hl = "MarkviewBlockQuoteSpecial", - border = "▋", border_hl = "MarkviewCol3Fg" + border = "▋", border_hl = "MarkviewBlockQuoteSpecial" }, { match_string = "WARNING", callout_preview = " Warning", - callout_preview_hl = "MarkviewCol2Fg", + callout_preview_hl = "MarkviewBlockQuoteWarn", - border = "▋", border_hl = "MarkviewCol2Fg" + border = "▋", border_hl = "MarkviewBlockQuoteWarn" }, { match_string = "CAUTION", callout_preview = "󰳦 Caution", - callout_preview_hl = "MarkviewCol1Fg", + callout_preview_hl = "MarkviewBlockQuoteError", - border = "▋", border_hl = "MarkviewCol1Fg" + border = "▋", border_hl = "MarkviewBlockQuoteError" }, { match_string = "CUSTOM", callout_preview = "󰠳 Custom", - callout_preview_hl = "MarkviewCol3Fg", + callout_preview_hl = "MarkviewBlockQuoteWarn", custom_title = true, custom_icon = " 󰠳 ", - border = "▋", border_hl = "MarkviewCol3Fg" + border = "▋", border_hl = "MarkviewBlockQuoteWarn" } } }, @@ -569,16 +1169,16 @@ markview.configuration = { enable = true, inline_links = { - icon = "󰌷 ", icon_hl = "markdownLinkText", - hl = "markdownLinkText", + icon = "󰌷 ", + hl = "MarkviewHyperlink", }, images = { - icon = "󰥶 ", icon_hl = "markdownLinkText", - hl = "markdownLinkText", + icon = "󰥶 ", + hl = "MarkviewImageLink", }, emails = { - icon = " ", icon_hl = "@markup.link.url", - hl = "@markup.link.url", + icon = " ", + hl = "MarkviewEmail", } }, @@ -587,7 +1187,7 @@ markview.configuration = { corner_left = " ", corner_right = " ", - hl = "Layer" + hl = "MarkviewCode" }, list_items = { @@ -595,19 +1195,19 @@ markview.configuration = { add_padding = true, text = "", - hl = "markviewCol2Fg" + hl = "MarkviewListItemMinus" }, marker_plus = { add_padding = true, text = "", - hl = "markviewCol4Fg" + hl = "MarkviewListItemPlus" }, marker_star = { add_padding = true, text = "", - text_hl = "markviewCol6Fg" + text_hl = "MarkviewListItemStar" }, marker_dot = { add_padding = true @@ -618,13 +1218,13 @@ markview.configuration = { enable = true, checked = { - text = "✔", hl = "markviewCol4Fg" + text = "✔", hl = "MarkviewCheckboxChecked" }, pending = { - text = "◯", hl = "MarkviewCol2Fg" + text = "◯", hl = "MarkviewCheckboxPending" }, unchecked = { - text = "✘", hl = "MarkviewCol1Fg" + text = "✘", hl = "MarkviewCheckboxUnchecked" } }, @@ -638,11 +1238,11 @@ markview.configuration = { "╼", "╾", "╴", "╶" }, hl = { - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg" + "MarkviewTableAlignLeft", "MarkviewTableAlignRight", "MarkviewTableAlignCenter", "MarkviewTableAlignCenter" }, use_virt_lines = true @@ -675,6 +1275,8 @@ markview.commands = { end end + markview.state.buf_states[buf] = true; + markview.renderer.clear(buf); markview.renderer.render(buf, parsed_content, markview.configuration) end @@ -689,6 +1291,8 @@ markview.commands = { end end + markview.state.buf_states[buf] = false; + markview.renderer.clear(buf); end diff --git a/lua/markview/colors.lua b/lua/markview/colors.lua index fd77497..26552a8 100644 --- a/lua/markview/colors.lua +++ b/lua/markview/colors.lua @@ -8,7 +8,55 @@ colors.lerp = function (x, y, t) return x + ((y - x) * t); end +colors.name_to_hex = function (name) + local lookup = { + ["red"] = "#FF0000", ["lightred"] = "#FFBBBB", ["darkred"] = "#8B0000", + ["green"] = "#00FF00", ["lightgreen"] = "#90EE90", ["darkgreen"] = "#006400", ["seagreen"] = "#2E8B57", + ["blue"] = "#0000FF", ["lightblue"] = "#ADD8E6", ["darkblue"] = "#00008B", ["slateblue"] = "#6A5ACD", + ["cyan"] = "#00FFFF", ["lightcyan"] = "#E0FFFF", ["darkcyan"] = "#008B8B", + ["magenta"] = "#FF00FF", ["lightmagenta"] = "#FFBBFF", ["darkmagenta"] = "#8B008B", + ["yellow"] = "#FFFF00", ["lightyellow"] = "#FFFFE0", ["darkyellow"] = "#BBBB00", ["brown"] = "#A52A2A", + ["grey"] = "#808080", ["lightgrey"] = "#D3D3D3", ["darkgrey"] = "#A9A9A9", + ["gray"] = "#808080", ["lightgray"] = "#D3D3D3", ["darkgray"] = "#A9A9A9", + ["black"] = "#000000", ["white"] = "#FFFFFF", + ["orange"] = "#FFA500", ["purple"] = "#800080", ["violet"] = "#EE82EE" + }; + + local lookup_nvim = { + ["nvimdarkblue"] = "#004C73", ["nvimlightblue"] = "#A6DBFF", + ["nvimdarkcyan"] = "#007373", ["nvimlightcyan"] = "#8CF8F7", + ["nvimdarkgray1"] = "#07080D", ["nvimlightgray1"] = "#EEF1F8", + ["nvimdarkgray2"] = "#14161B", ["nvimlightgray2"] = "#E0E2EA", + ["nvimdarkgray3"] = "#2C2E33", ["nvimlightgray3"] = "#C4C6CD", + ["nvimdarkgray4"] = "#4F5258", ["nvimlightgray4"] = "#9B9EA4", + ["nvimdarkgrey1"] = "#07080D", ["nvimlightgrey1"] = "#EEF1F8", + ["nvimdarkgrey2"] = "#14161B", ["nvimlightgrey2"] = "#E0E2EA", + ["nvimdarkgrey3"] = "#2C2E33", ["nvimlightgrey3"] = "#C4C6CD", + ["nvimdarkgrey4"] = "#4F5258", ["nvimlightgrey4"] = "#9B9EA4", + ["nvimdarkgreen"] = "#005523", ["nvimlightgreen"] = "#B3F6C0", + ["nvimdarkmagenta"] = "#470045", ["nvimlightmagenta"] = "#FFCAFF", + ["nvimdarkred"] = "#590008", ["nvimlightred"] = "#FFC0B9", + ["nvimdarkyellow"] = "#6B5300", ["nvimlightyellow"] = "#FCE094", + }; + + return lookup[string.lower(name)] or lookup_nvim[string.lower(name)]; +end + +colors.name_to_rgb = function (name) + local hex = colors.name_to_hex(name); + + if not hex then + return; + end + + return colors.hex_to_rgb(hex); +end + colors.num_to_hex = function (num) + if not num then + return; + end + if num == 0 then return "#000000"; elseif num ~= nil then @@ -17,6 +65,10 @@ colors.num_to_hex = function (num) end colors.num_to_rgb = function (num) + if not num then + return; + end + local hex = string.format("%x", num); return { @@ -49,14 +101,30 @@ colors.rgb_to_hex = function (tbl) end colors.get_hl_value = function (ns_id, hl_group, value) - local hl = vim.api.nvim_get_hl(ns_id, { name = hl_group, link = false }); + if vim.fn.hlexists(hl_group) == 0 then + return; + end + + local hl = vim.api.nvim_get_hl(ns_id, { name = hl_group, link = false, create = false }); if value == "fg" then - return colors.num_to_hex(hl.fg) + if type(hl.fg) == "string" and hl.fg:match("^[#]?(%x+)$") then + return colors.name_to_hex(hl.fg) + else + return colors.num_to_hex(hl.fg) + end elseif value == "bg" then - return colors.num_to_hex(hl.bg) + if type(hl.bg) == "string" and hl.bg:match("^[#]?(%x+)$") then + return colors.name_to_hex(hl.bg) + else + return colors.num_to_hex(hl.bg) + end elseif value == "sp" then - return colors.num_to_hex(hl.sp) + if type(hl.sp) == "string" and hl.sp:match("^[#]?(%x+)$") then + return colors.name_to_hex(hl.sp) + else + return colors.num_to_hex(hl.sp) + end else return hl[value]; end @@ -109,14 +177,18 @@ colors.mix = function (color_1, color_2, per_1, per_2) if type(color_1) == "table" then c_1 = color_1; - elseif type(color_1) == "string" then + elseif type(color_1) == "string" and color_1:match("^[#]?(%x+)$") then c_1 = colors.hex_to_rgb(color_1); + elseif type(color_1) == "string" then + c_1 = colors.name_to_rgb(color_1); end if type(color_2) == "table" then c_2 = color_2; - elseif type(color_2) == "string" then + elseif type(color_2) == "string" and color_2:match("^[#]?(%x+)$") then c_2 = colors.hex_to_rgb(color_2); + elseif type(color_2) == "string" then + c_1 = colors.name_to_rgb(color_2); end if not c_1 or not c_2 then @@ -130,4 +202,85 @@ colors.mix = function (color_1, color_2, per_1, per_2) return colors.rgb_to_hex({ r = _r, g = _g, b = _b }); end +colors.get_brightness = function (color) + if type(color) == "string" and color:match("^[#]?(%x+)$") then + color = colors.hex_to_rgb(color); + elseif type(color_1) == "string" then + color = colors.name_to_rgb(color); + elseif type(color) == "number" then + color = colors.num_to_rgb(color); + end + + for key, value in pairs(color) do + if value > 1 then + color[key] = value / 255; + end + end + + return (color.r * 0.2126) + (color.g * 0.7152) + (color.b * 0.0722); +end + +colors.brightest = function (col_list, debug) + if not col_list then + return; + elseif not vim.islist(col_list) then + local tmp = {}; + + for _, item in pairs(col_list) do + table.insert(tmp,item); + end + + col_list = tmp; + end + + local _c = {}; + + for _, col in ipairs(col_list) do + if type(col) == "string" and col:match("^[#]?(%x+)$") then + table.insert(_c, colors.hex_to_rgb(col)); + elseif type(col) == "string" then + table.insert(_c, colors.name_to_rgb(col)); + elseif type(col) == "number" then + table.insert(_c, colors.num_to_rgb(col)); + elseif type(col) == "table" then + table.insert(_c, col); + end + end + + + local _b = 0; + local brightest; + + for _, c in ipairs(_c) do + local brightness = colors.get_brightness(c) or 0; + + if brightness >= _b then + _b = brightness; + brightest = c; + end + end + + -- if debug then + -- vim.print(colors.rgb_to_hex(brightest) == nil); + -- end + + return colors.rgb_to_hex(brightest); +end + +colors.get = function (col_list) + if not col_list then + return; + elseif not vim.islist(col_list) then + local tmp = {}; + + for _, item in pairs(col_list) do + table.insert(tmp,item); + end + + col_list = tmp; + end + + return col_list[1]; +end + return colors; diff --git a/lua/markview/parser.lua b/lua/markview/parser.lua index 4b22177..89fc910 100644 --- a/lua/markview/parser.lua +++ b/lua/markview/parser.lua @@ -158,6 +158,8 @@ parser.md = function (buffer, TStree, from, to) local lines = {}; local highest_len = 0; + local block_start = vim.api.nvim_buf_get_lines(buffer, row_start, row_start + 1, false)[1]; + for i = 1,(row_end - row_start) - 2 do local this_code = vim.api.nvim_buf_get_lines(buffer, row_start + i, row_start + i + 1, false)[1]; local len = vim.fn.strchars(this_code) or 0; @@ -173,7 +175,7 @@ parser.md = function (buffer, TStree, from, to) table.insert(parser.parsed_content, { node = capture_node, type = "code_block", - language = not capture_node:named_child(1) and "" or vim.treesitter.get_node_text(capture_node:named_child(1), buffer), + language = block_start:match("%s*```(%S*)$") or "", line_lengths = line_lens, largest_line = highest_len, diff --git a/lua/markview/presets.lua b/lua/markview/presets.lua index 1c0f2a2..b8774bd 100644 --- a/lua/markview/presets.lua +++ b/lua/markview/presets.lua @@ -1,4 +1,360 @@ local presets = {}; +local colors = require("markview.colors"); + +presets.highlight_groups = { + colorful_heading_bg = { + ---+ ##code## + { + -- Heading level 1 + output = function () + if colors.get_hl_value(0, "DiagnosticOk", "fg") and colors.get_hl_value(0, "Normal", "bg") then + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = colors.get_hl_value(0, "DiagnosticOk", "fg"); + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading1", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading1Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + else + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = vim.o.background == "dark" and "#a6e3a1" or "#40a02b"; + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading1", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading1Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + end + end + }, + { + -- Heading level 2 + output = function () + if colors.get_hl_value(0, "DiagnosticHint", "fg") and colors.get_hl_value(0, "Normal", "bg") then + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = colors.get_hl_value(0, "DiagnosticHint", "fg"); + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading2", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading2Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + else + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = vim.o.background == "dark" and "#94e2d5" or "#179299"; + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading2", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading2Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + end + end + }, + { + -- Heading level 3 + output = function () + if colors.get_hl_value(0, "DiagnosticInfo", "fg") and colors.get_hl_value(0, "Normal", "bg") then + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = colors.get_hl_value(0, "DiagnosticInfo", "fg"); + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading3", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading3Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + else + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = vim.o.background == "dark" and "#89dceb" or "#179299"; + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading3", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading3Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + end + end + }, + { + -- Heading level 4 + output = function () + if colors.get_hl_value(0, "Special", "fg") and colors.get_hl_value(0, "Normal", "bg") then + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = colors.get_hl_value(0, "Special", "fg"); + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading4", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading4Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + else + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = vim.o.background == "dark" and "#f5c2e7" or "#ea76cb"; + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading4", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading4Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + end + end + }, + { + -- Heading level 5 + output = function () + if colors.get_hl_value(0, "DiagnosticWarn", "fg") and colors.get_hl_value(0, "Normal", "bg") then + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = colors.get_hl_value(0, "DiagnosticWarn", "fg"); + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading5", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading5Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + else + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = vim.o.background == "dark" and "#F9E3AF" or "#DF8E1D"; + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading5", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading5Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + end + end + }, + { + -- Heading level 6 + output = function () + if colors.get_hl_value(0, "DiagnosticError", "fg") and colors.get_hl_value(0, "Normal", "bg") then + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = colors.get_hl_value(0, "DiagnosticError", "fg"); + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading6", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading6Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + else + local fg = colors.get_hl_value(0, "Normal", "bg"); + local bg = vim.o.background == "dark" and "#F38BA8" or "#D20F39"; + + local nr = colors.get_hl_value(0, "LineNr", "bg"); + + return { + { + group_name = "Heading6", + value = { + bg = bg, + fg = fg, + + default = true + } + }, + { + group_name = "Heading6Sign", + value = { + bg = nr, + fg = bg, + + default = true + } + }, + } + end + end + }, + ---_ + } +}; presets.headings = { glow = { @@ -10,7 +366,7 @@ presets.headings = { heading_1 = { style = "label", - hl = "MarkviewCol1Inv", + hl = "MarkviewHeading1", padding_left = " ", padding_right = " " @@ -21,13 +377,26 @@ presets.headings = { enable = true, shift_width = 0, + setext_1 = { + style = "github", + + icon = "  ", hl = "MarkviewHeading1", + underline = "━" + }, + setext_2 = { + style = "github", + + icon = "  ", hl = "MarkviewHeading2", + underline = "─" + }, + heading_1 = { style = "label", padding_left = " ", padding_right = " ", - hl = "MarkviewCol1Inv" + hl = "MarkviewHeading1" }, heading_2 = { style = "label", @@ -35,7 +404,7 @@ presets.headings = { padding_left = " ", padding_right = " ", - hl = "MarkviewCol2Inv" + hl = "MarkviewHeading2" }, heading_3 = { style = "label", @@ -43,7 +412,7 @@ presets.headings = { padding_left = " ", padding_right = " ", - hl = "MarkviewCol3Inv" + hl = "MarkviewHeading3" }, heading_4 = { style = "label", @@ -51,7 +420,7 @@ presets.headings = { padding_left = " ", padding_right = " ", - hl = "MarkviewCol4Inv" + hl = "MarkviewHeading4" }, heading_5 = { style = "label", @@ -59,7 +428,7 @@ presets.headings = { padding_left = " ", padding_right = " ", - hl = "MarkviewCol5Inv" + hl = "MarkviewHeading5" }, heading_6 = { style = "label", @@ -67,7 +436,7 @@ presets.headings = { padding_left = " ", padding_right = " ", - hl = "MarkviewCol6Inv" + hl = "MarkviewHeading6" }, }, decorated_labels = { @@ -82,9 +451,9 @@ presets.headings = { padding_right = " ", corner_right = "", - corner_right_hl = "MarkviewCol1Fg", + corner_right_hl = "MarkviewHeading1Sign", - hl = "MarkviewCol1Inv" + hl = "MarkviewHeading1" }, heading_2 = { style = "label", @@ -93,9 +462,9 @@ presets.headings = { padding_right = " ", corner_right = "", - corner_right_hl = "MarkviewCol2Fg", + corner_right_hl = "MarkviewHeading2", - hl = "MarkviewCol2Inv" + hl = "MarkviewHeading2Sign" }, heading_3 = { style = "label", @@ -104,9 +473,9 @@ presets.headings = { padding_right = " ", corner_right = "", - corner_right_hl = "MarkviewCol3Fg", + corner_right_hl = "MarkviewHeading3", - hl = "MarkviewCol3Inv" + hl = "MarkviewHeading3Sign" }, heading_4 = { style = "label", @@ -115,9 +484,9 @@ presets.headings = { padding_right = " ", corner_right = "", - corner_right_hl = "MarkviewCol4Fg", + corner_right_hl = "MarkviewHeading4", - hl = "MarkviewCol4Inv" + hl = "MarkviewHeading4Sign" }, heading_5 = { style = "label", @@ -126,9 +495,9 @@ presets.headings = { padding_right = " ", corner_right = "", - corner_right_hl = "MarkviewCol5Fg", + corner_right_hl = "MarkviewHeading5", - hl = "MarkviewCol5Inv" + hl = "MarkviewHeading5Sign" }, heading_6 = { style = "label", @@ -137,9 +506,9 @@ presets.headings = { padding_right = " ", corner_right = "", - corner_right_hl = "MarkviewCol6Fg", + corner_right_hl = "MarkviewHeading6", - hl = "MarkviewCol6Inv" + hl = "MarkviewHeading6Sign" }, }, @@ -151,32 +520,32 @@ presets.headings = { heading_1 = { style = "simple", - hl = "MarkviewCol1" + hl = "MarkviewHeading1" }, heading_2 = { style = "simple", - hl = "MarkviewCol2" + hl = "MarkviewHeading2" }, heading_3 = { style = "simple", - hl = "MarkviewCol3" + hl = "MarkviewHeading3" }, heading_4 = { style = "simple", - hl = "MarkviewCol4" + hl = "MarkviewHeading4" }, heading_5 = { style = "simple", - hl = "MarkviewCol5" + hl = "MarkviewHeading5" }, heading_6 = { style = "simple", - hl = "MarkviewCol6" + hl = "MarkviewHeading6" }, }, simple_no_marker = { @@ -191,37 +560,37 @@ presets.headings = { style = "icon", icon = " ", - hl = "MarkviewCol1" + hl = "MarkviewHeading1" }, heading_2 = { style = "icon", icon = " ", - hl = "MarkviewCol2" + hl = "MarkviewHeading2" }, heading_3 = { style = "icon", icon = " ", - hl = "MarkviewCol3" + hl = "MarkviewHeading3" }, heading_4 = { style = "icon", icon = " ", - hl = "MarkviewCol4" + hl = "MarkviewHeading4" }, heading_5 = { style = "icon", icon = " ", - hl = "MarkviewCol5" + hl = "MarkviewHeading5" }, heading_6 = { style = "icon", icon = " ", - hl = "MarkviewCol6" + hl = "MarkviewHeading6" }, }, }; @@ -260,11 +629,11 @@ presets.tables = { }, -- This is a required property hl = { - nil, "MarkviewCol1Fg", nil, nil, + nil, "MarkviewTableBorder", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", }, use_virt_lines = false @@ -282,11 +651,11 @@ presets.tables = { "╼", "╾", "╴", "╶" }, hl = { - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg" + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder" }, use_virt_lines = false @@ -304,11 +673,11 @@ presets.tables = { "╼", "╾", "╴", "╶" }, hl = { - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg" + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder" }, use_virt_lines = false @@ -327,11 +696,11 @@ presets.tables = { "━", "━", "━", "━" }, hl = { - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", - "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", "MarkviewCol1Fg", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", + "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", "MarkviewTableBorder", - "MarkviewCol3Fg", "MarkviewCol4Fg", "MarkviewCol6Fg", "MarkviewCol6Fg" + "MarkviewTableAlignLeft", "MarkviewTableAlignRight", "MarkviewTableAlignCenter", "MarkviewTableAlignCenter" }, use_virt_lines = false diff --git a/lua/markview/renderer.lua b/lua/markview/renderer.lua index 18317be..1e67030 100644 --- a/lua/markview/renderer.lua +++ b/lua/markview/renderer.lua @@ -587,6 +587,10 @@ renderer.render_headings = function (buffer, content, config) local conf = config["heading_" .. content.level] or {}; local shift = config.shift_width or vim.bo[buffer].shiftwidth; + if not conf then + return; + end + if conf.style == "simple" then -- Adds a simple background vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start, content.col_start, { @@ -667,7 +671,7 @@ renderer.render_headings = function (buffer, content, config) end renderer.render_headings_s = function (buffer, content, config) - if config.enable == false then + if not config or config.enable == false then return; end @@ -675,6 +679,10 @@ renderer.render_headings_s = function (buffer, content, config) local conf = content.marker:match("=") and config["setext_1"] or config["setext_2"]; local shift = config.shift_width or vim.bo[buffer].shiftwidth; + if not conf then + return; + end + if conf.style == "simple" then -- Adds a simple background @@ -809,14 +817,14 @@ renderer.render_code_blocks = function (buffer, content, config_table) block_length = config_table.min_width end - local lang_width = vim.fn.strchars(icon .. " " .. language .. " "); + local lang_width = vim.fn.strchars(" " .. icon .. " " .. (language == "" and "Unknown" or language) .. " "); if config_table.language_direction == nil or config_table.language_direction == "left" then vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start, content.col_start + 3 + vim.fn.strlen(content.language), { virt_text_pos = config_table.position or "inline", virt_text = { - { icon .. " ", set_hl(hl) }, - { language .. " ", set_hl(config_table.name_hl) or set_hl(hl) }, + { " " .. icon .. " ", set_hl(hl) }, + { (language == "" and "Unknown" or language) .. " ", set_hl(config_table.name_hl) or set_hl(hl) }, { string.rep(config_table.pad_char or " ", block_length - lang_width + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) }, }, @@ -830,8 +838,8 @@ renderer.render_code_blocks = function (buffer, content, config_table) virt_text_pos = config_table.position or "inline", virt_text = { { string.rep(config_table.pad_char or " ", block_length - lang_width + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) }, - { icon .. " ", set_hl(hl) }, - { language .. " ", set_hl(config_table.name_hl) or set_hl(hl) }, + { " " .. icon .. " ", set_hl(hl) }, + { (language == "" and "Unknown" or language) .. " ", set_hl(config_table.name_hl) or set_hl(hl) }, }, sign_text = config_table.sign == true and icon or nil, @@ -1341,27 +1349,27 @@ renderer.render = function (buffer, parsed_content, config_table, conceal_start, end if type == "heading_s" then - renderer.render_headings_s(buffer, content, config_table.headings); + pcall(renderer.render_headings_s, buffer, content, config_table.headings); elseif type == "heading" then - renderer.render_headings(buffer, content, config_table.headings) + pcall(renderer.render_headings, buffer, content, config_table.headings) elseif type == "code_block" then - renderer.render_code_blocks(buffer, content, config_table.code_blocks) + pcall(renderer.render_code_blocks, buffer, content, config_table.code_blocks) elseif type == "block_quote" then - renderer.render_block_quotes(buffer, content, config_table.block_quotes); + pcall(renderer.render_block_quotes, buffer, content, config_table.block_quotes); elseif type == "horizontal_rule" then - renderer.render_horizontal_rules(buffer, content, config_table.horizontal_rules); + pcall(renderer.render_horizontal_rules, buffer, content, config_table.horizontal_rules); elseif type == "link" then - renderer.render_links(buffer, content, config_table.links); + pcall(renderer.render_links, buffer, content, config_table.links); elseif type == "image" then - renderer.render_links(buffer, content, config_table.images); + pcall(renderer.render_links, buffer, content, config_table.images); elseif type == "inline_code" then - renderer.render_inline_codes(buffer, content, config_table.inline_codes) + pcall(renderer.render_inline_codes, buffer, content, config_table.inline_codes) elseif type == "list_item" then - renderer.render_lists(buffer, content, config_table.list_items) + pcall(renderer.render_lists, buffer, content, config_table.list_items) elseif type == "checkbox" then - renderer.render_checkboxes(buffer, content, config_table.checkboxes) + pcall(renderer.render_checkboxes, buffer, content, config_table.checkboxes) elseif type == "table" then - renderer.render_tables(buffer, content, config_table) + pcall(renderer.render_tables, buffer, content, config_table) end ::extmark_skipped::