Skip to content

Commit 73321b6

Browse files
committed
Add option to disable italics
With italics option (true by default), you can disable italic used by default in style for some groups (Function, Keyword, Comment...). - README.md : add documentation for italics option - lua/monokai.lua : use italics option to disable/enable italic in style Adapted from #18 to fix conflicts.
1 parent bff619d commit 73321b6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ monokai.setup {
110110
}
111111
```
112112

113+
With `italics` option (`true` by default), you can disable italic used by default in style for some groups (`Function`, `Keyword`, `Comment`...).
114+
115+
```
116+
require('monokai').setup { italics = false }
117+
```
118+
113119
## Extras
114120

115121
Extra color configs for **Kitty**, **Alacritty**, **Windows Terminal**, can be found in [extras](extras/). To use them, refer to their respective documentation.

lua/monokai.lua

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,24 @@ M.ristretto = {
118118
diff_text = '#23324d',
119119
}
120120

121-
M.highlight = function(group, color)
122-
local style = color.style and 'gui=' .. color.style or 'gui=NONE'
123-
local fg = color.fg and 'guifg = ' .. color.fg or 'guifg = NONE'
124-
local bg = color.bg and 'guibg = ' .. color.bg or 'guibg = NONE'
125-
local sp = color.sp and 'guisp = ' .. color.sp or ''
121+
local function remove_italics(config, colors)
122+
if not config.italics and colors.style == 'italic' then
123+
colors.style = nil
124+
end
125+
return colors
126+
end
127+
128+
local function highlighter(config)
129+
return function(group, color)
130+
color = remove_italics(config, color)
131+
local style = color.style and 'gui=' .. color.style or 'gui=NONE'
132+
local fg = color.fg and 'guifg = ' .. color.fg or 'guifg = NONE'
133+
local bg = color.bg and 'guibg = ' .. color.bg or 'guibg = NONE'
134+
local sp = color.sp and 'guisp = ' .. color.sp or ''
126135
vim.cmd(
127136
'highlight ' .. group .. ' ' .. style .. ' ' .. fg .. ' ' .. bg .. ' ' .. sp
128137
)
138+
end
129139
end
130140

131141
M.load_syntax = function(palette)
@@ -689,6 +699,7 @@ end
689699
local default_config = {
690700
palette = M.classic,
691701
custom_hlgroups = {},
702+
italics = true,
692703
}
693704

694705
M.setup = function(config)
@@ -704,8 +715,9 @@ M.setup = function(config)
704715
vim.g.colors_name = used_palette.name
705716
local syntax = M.load_syntax(used_palette)
706717
syntax = vim.tbl_deep_extend('keep', config.custom_hlgroups, syntax)
718+
local highlight = highlighter(config)
707719
for group, colors in pairs(syntax) do
708-
M.highlight(group, colors)
720+
highlight(group, colors)
709721
end
710722
local plugin_syntax = M.load_plugin_syntax(used_palette)
711723
plugin_syntax = vim.tbl_deep_extend(
@@ -714,7 +726,7 @@ M.setup = function(config)
714726
plugin_syntax
715727
)
716728
for group, colors in pairs(plugin_syntax) do
717-
M.highlight(group, colors)
729+
highlight(group, colors)
718730
end
719731
end
720732

0 commit comments

Comments
 (0)