Skip to content

Commit

Permalink
feat(highlights): revamp markup headings, links and raw text (#17)
Browse files Browse the repository at this point in the history
* fix(highlighter): only preprocess the attributes before applying highlights

This change will allow getting the styles of specific highlight group.

* feat(highlights): revamp markup headings, links and raw text

* docs(README): yellow is no longer optional in color sets

* chore(ci): auto generate docs

* docs(README): add default config for markup headings

* chore(ci): auto generate docs
  • Loading branch information
ramojus authored Feb 20, 2024
1 parent a72e8ea commit 34a59fc
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 21 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ require 'mellifluous'.setup({
properties = {},
types = {},
operators = {},
markup = {
headings = { bold = true },
},
},
transparent_background = {
enabled = false,
Expand Down Expand Up @@ -189,7 +192,7 @@ require 'mellifluous'.setup({
For further instructions, refer to [overriding highlights](#overriding-highlights) section

##### Extra colors
In addition to the colors listed in [available colors](#available-colors) section, some color sets may have more colors available (`cyan` and/or `yellow`). To check your color set, refer to [the source code for color sets](lua/mellifluous/colors/sets/) and see if `get_colors_*` functions return any extra (optional) colors.
In addition to the colors listed in [available colors](#available-colors) section, some color sets may have more colors available (`cyan`). To check your color set, refer to [the source code for color sets](lua/mellifluous/colors/sets/) and see if `get_colors_*` functions return any extra (optional) colors.

### Overriding highlights
The following snippet shows how global (for any color set) highlight overrides can be defined:
Expand Down Expand Up @@ -250,12 +253,14 @@ Available colors:
- `green`
- `blue`
- `purple`
- `yellow`
- UI colors. Same as named colors, but all are of the same brightness (lightness).
- `ui_red`: used to indicate errors, deletes, bad spellings.
- `ui_orange`: used to indicate warnings, changes, other (strange) spellings.
- `ui_green`: used to indicate staged, additions.
- `ui_blue`: used to indicate information, new files.
- `ui_purple`: used to indicate hints, merge.
- `ui_yellow`

NOTE: some color sets may have more colors available. See [extra colors](#extra-colors) section.

Expand Down
12 changes: 8 additions & 4 deletions doc/mellifluous.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ parts of the config can be included.
properties = {},
types = {},
operators = {},
markup = {
headings = { bold = true },
},
},
transparent_background = {
enabled = false,
Expand Down Expand Up @@ -216,10 +219,9 @@ For further instructions, refer to |mellifluous-overriding-highlights| section
EXTRA COLORS

In addition to the colors listed in |mellifluous-available-colors| section,
some color sets may have more colors available (`cyan` and/or `yellow`). To
check your color set, refer to the source code for color sets
<lua/mellifluous/colors/sets/> and see if `get_colors_*` functions return any
extra (optional) colors.
some color sets may have more colors available (`cyan`). To check your color
set, refer to the source code for color sets <lua/mellifluous/colors/sets/> and
see if `get_colors_*` functions return any extra (optional) colors.


OVERRIDING HIGHLIGHTS *mellifluous-configuration-overriding-highlights*
Expand Down Expand Up @@ -293,12 +295,14 @@ Available colors:
- `green`
- `blue`
- `purple`
- `yellow`
- UI colors. Same as named colors, but all are of the same brightness (lightness).
- `ui_red`: used to indicate errors, deletes, bad spellings.
- `ui_orange`: used to indicate warnings, changes, other (strange) spellings.
- `ui_green`: used to indicate staged, additions.
- `ui_blue`: used to indicate information, new files.
- `ui_purple`: used to indicate hints, merge.
- `ui_yellow`

NOTE: some color sets may have more colors available. See
|mellifluous-extra-colors| section.
Expand Down
1 change: 1 addition & 0 deletions lua/mellifluous/colors/sets/alduin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function M.get_colors_dark(bg)
green = green, -- staged, additions
blue = grey, -- information, new files
purple = cyan, -- hints, merge
yellow = strings,

-- optional (for better terminal highlights)
cyan = cyan,
Expand Down
2 changes: 2 additions & 0 deletions lua/mellifluous/colors/sets/mellifluous.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function M.get_colors_dark(bg)
green = green, -- staged, additions
blue = blue, -- information, new files
purple = purple, -- hints, merge
yellow = yellow,
}
end

Expand Down Expand Up @@ -111,6 +112,7 @@ function M.get_colors_light(bg)
green = green, -- staged, additions
blue = blue, -- information, new files
purple = purple, -- hints, merge
yellow = yellow,
}
end

Expand Down
2 changes: 1 addition & 1 deletion lua/mellifluous/colors/sets/mountain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function M.get_colors_dark(bg)
green = green, -- staged, additions
blue = blue, -- information, new files
purple = magenta, -- hints, merge
yellow = yellow,

-- optional (for better terminal highlights)
cyan = cyan,
yellow = yellow,
}
end

Expand Down
4 changes: 1 addition & 3 deletions lua/mellifluous/colors/sets/tender.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ function M.get_colors_dark(bg)
green = green1, -- staged, additions
blue = blue1, -- information, new files
purple = blue2, -- hints, merge

-- optional (for better terminal highlights)
yellow = yellow2,
yellow = yellow1,
}
end

Expand Down
1 change: 1 addition & 0 deletions lua/mellifluous/colors/shades.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function M.get_recipes()
ui_green = { target = 'green', action = 'with_li', val = 'ui' },
ui_blue = { target = 'blue', action = 'with_li', val = 'ui' },
ui_purple = { target = 'purple', action = 'with_li', val = 'ui' },
ui_yellow = { target = 'yellow', action = 'with_li', val = 'ui' },
}
local recipes = {}

Expand Down
3 changes: 3 additions & 0 deletions lua/mellifluous/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ local config = {
properties = {},
types = {},
operators = {},
markup = {
headings = { bold = true }
}
},
transparent_background = {
enabled = false,
Expand Down
3 changes: 2 additions & 1 deletion lua/mellifluous/highlights/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ local M = {}
function M.set(hl, colors)
local config = require('mellifluous.config').config

require('mellifluous.highlights.plugins.treesitter').set(hl, colors)

for plugin in pairs(config.plugins) do
if (type(config.plugins[plugin]) == 'table' and config.plugins[plugin].enabled == true)
or (type(config.plugins[plugin]) == 'boolean' and config.plugins[plugin] == true) then
require('mellifluous.highlights.plugins.' .. plugin).set(hl, colors)
end
end

require('mellifluous.highlights.plugins.treesitter').set(hl, colors)
require('mellifluous.highlights.plugins.semantic_tokens').set(hl, colors)
end

Expand Down
53 changes: 49 additions & 4 deletions lua/mellifluous/highlights/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ function M.set(hl, colors)
hl.set('@markup.math', { fg = colors.other_keywords }) -- Math environments like LaTeX's `$ ... $`
hl.set('@markup.environment', { fg = colors.other_keywords }) -- Text environments of markup languages.
hl.set('@markup.environment.name', { link = '@markup.environment' }) -- Text/string indicating the type of text environment. Like the name of a `\begin` block in LaTeX.
hl.set('@markup.link', { fg = hl.get('@string.special.url').fg }) -- Footnotes, text references, citations, etc.
hl.set('@markup.link.label', { fg = colors.constants }) -- Link, reference descriptions
hl.set('@markup.link', { fg = colors.constants, style = { underline = true } }) -- Footnotes, text references, citations, etc.
hl.set('@markup.link.markdown_inline', { fg = hl.get('@markup.link').fg }) -- Everything in a markdown link that's not a label or url (`[]()`)
hl.set('@markup.link.label', { link = '@markup.link' }) -- Link, reference descriptions
hl.set('@markup.link.url', { link = '@string.special.url' }) -- URIs like hyperlinks or email addresses.
hl.set('@markup.raw', { link = 'Character' }) -- Literal or verbatim text (e.g., inline code)
hl.set('@markup.raw.block', { link = 'Character' }) -- Literal or verbatim text as a stand-alone block
hl.set('@markup.raw', { fg = colors.fg2 }) -- Literal or verbatim text (e.g., inline code)
hl.set('@markup.raw.block', { link = '@markup.raw' }) -- Literal or verbatim text as a stand-alone block
hl.set('@markup.list', { link = 'Operator' }) -- List markers
hl.set('@markup.list.unchecked', { link = 'Todo' }) -- Unchecked todo-style list markers
hl.set('@markup.list.checked', { fg = hl.get('@markup.list.unchecked').fg, bg = 'NONE' }) -- Checked todo-style list markers
Expand All @@ -108,6 +109,50 @@ function M.set(hl, colors)
hl.set('@tag', { link = 'Keyword' }) -- Tags like HTML tag names.
hl.set('@tag.attribute', { link = 'Function', style = {} }) -- HTML tag attributes.
hl.set('@tag.delimiter', { link = 'Operator', style = {} }) -- Tag delimiters like `<` `>` `/`.
hl.set('@markup.heading.1.marker', { fg = colors.ui_red, style = {} })
hl.set('@markup.heading.2.marker', { fg = colors.ui_orange, style = {} })
hl.set('@markup.heading.3.marker', { fg = colors.ui_yellow, style = {} })
hl.set('@markup.heading.4.marker', { fg = colors.ui_green, style = {} })
hl.set('@markup.heading.5.marker', { fg = colors.ui_blue, style = {} })
hl.set('@markup.heading.6.marker', { fg = colors.ui_purple, style = {} })
hl.set('@markup.heading.1',
{
fg = shader.get_higher_contrast(colors.ui_red, 10),
bg = colors.bg:with_overlay(colors.ui_red, 16),
style = config.styles.markup.headings
})
hl.set('@markup.heading.2',
{
fg = shader.get_higher_contrast(colors.ui_orange, 10),
bg = colors.bg:with_overlay(colors.ui_orange, 16),
style = config.styles.markup.headings
})
hl.set('@markup.heading.3',
{
fg = shader.get_higher_contrast(colors.ui_yellow, 10),
bg = colors.bg:with_overlay(colors.ui_yellow, 16),
style = config.styles.markup.headings
})
hl.set('@markup.heading.4',
{
fg = shader.get_higher_contrast(colors.ui_green, 10),
bg = colors.bg:with_overlay(colors.ui_green, 16),
style = config.styles.markup.headings
})
hl.set('@markup.heading.5',
{
fg = shader.get_higher_contrast(colors.ui_blue, 10),
bg = colors.bg:with_overlay(colors.ui_blue, 16),
style = config.styles.markup.headings
})
hl.set('@markup.heading.6',
{
fg = shader.get_higher_contrast(colors.ui_purple, 10),
bg = colors.bg:with_overlay(colors.ui_purple, 16),
style = config.styles.markup.headings
})
hl.set('@markup.heading', { link = '@markup.heading.1' })
hl.set('@markup.heading.gitcommit', { fg = hl.get('@markup.heading').fg })


-- For compatitibilty with older neovim versions (TODO: remove after a few months)
Expand Down
16 changes: 9 additions & 7 deletions lua/mellifluous/utils/highlighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ local function get_hex(color)
end

function M.set(name, attributes)
if attributes.style then
for style_name, val in pairs(attributes.style) do
attributes[style_name] = val
end
if not attributes.style then
attributes.style = {}
end
attributes.style = nil
attributes.fg = get_hex(attributes.fg)
attributes.bg = get_hex(attributes.bg)

highlights[name] = attributes
end
Expand All @@ -33,6 +28,13 @@ end

function M.apply_all()
for name, attributes in pairs(highlights) do
for style_name, val in pairs(attributes.style) do
attributes[style_name] = val
end
attributes.style = nil
attributes.fg = get_hex(attributes.fg)
attributes.bg = get_hex(attributes.bg)

vim.api.nvim_set_hl(0, name, attributes)
end
end
Expand Down

0 comments on commit 34a59fc

Please sign in to comment.