Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/md-render.jax
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,10 @@ Markdown をレンダリングしてバッファに表示する完全な例で

*Bold* 太字(フォールバック; `bold = true` )
*Italic* 斜体(フォールバック; `italic = true` )
*MdRenderInlineCode* インラインコード( `` `code` `` および `<code>` )。
fg は `String` を継承し、bg は控えめなニュートラル色
(Comment fg と Normal bg のブレンド)でコードと
見出しを視覚的に区別する。
*MdRenderHighlight* Obsidian `==highlight==` マーカー
*MdRenderTag* Obsidian `#tag` ( `Label` にリンク)
*MdRenderMath* 数式( `Special` にリンク)
Expand Down
4 changes: 4 additions & 0 deletions doc/md-render.txt
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@ INLINE FORMATTING ~

*Bold* Bold text (fallback; `bold = true`)
*Italic* Italic text (fallback; `italic = true`)
*MdRenderInlineCode* Inline code spans (`` `code` `` and `<code>`).
fg follows `String`; bg is a subtle neutral tint
(Comment fg blended with Normal bg) so code is
visibly distinct from headings.
*MdRenderHighlight* Obsidian `==highlight==` markers
*MdRenderTag* Obsidian `#tag` syntax (links to `Label`)
*MdRenderMath* Inline/block math (links to `Special`)
Expand Down
22 changes: 22 additions & 0 deletions lua/md-render/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function M.setup_highlights()
M.setup_alert_highlights()
M.setup_details_highlights()
M.setup_image_placeholder_highlight()
M.setup_inline_code_highlight()
end

--- Set up image placeholder highlight group (MdRenderImagePlaceholder)
Expand All @@ -112,6 +113,27 @@ function M.setup_image_placeholder_highlight()
vim.api.nvim_set_hl(0, "MdRenderImagePlaceholder", { fg = fg, bg = bg, default = true })
end

--- Set up inline code highlight group (MdRenderInlineCode).
--- fg follows String so the existing color cue is preserved; bg is a subtle
--- neutral tint (Comment fg blended with Normal bg) so backtick spans stay
--- visually distinct from headings even when the colorscheme paints both green.
function M.setup_inline_code_highlight()
local normal_hl = vim.api.nvim_get_hl(0, { name = "NormalFloat", link = false })
if not normal_hl.bg then
normal_hl = vim.api.nvim_get_hl(0, { name = "Normal", link = false })
end
local normal_bg = normal_hl.bg or 0x1e1e2e
local comment_hl = vim.api.nvim_get_hl(0, { name = "Comment", link = false })
local tint = comment_hl.fg or 0x888888
local bg = blend_color(tint, normal_bg, 0.18)
local string_hl = vim.api.nvim_get_hl(0, { name = "String", link = false })
if string_hl.fg then
vim.api.nvim_set_hl(0, "MdRenderInlineCode", { fg = string_hl.fg, bg = bg, default = true })
else
vim.api.nvim_set_hl(0, "MdRenderInlineCode", { bg = bg, default = true })
end
end

-- Re-export submodules (preview is lazy-loaded to avoid circular dependency)
M.ContentBuilder = require("md-render.content_builder").ContentBuilder
M.Markdown = require "md-render.markdown"
Expand Down
6 changes: 3 additions & 3 deletions lua/md-render/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ local HTML_TAG_HIGHLIGHTS = {
strong = "Bold",
i = "Italic",
em = "Italic",
code = "String",
code = "MdRenderInlineCode",
s = "DiagnosticDeprecated",
del = "DiagnosticDeprecated",
strike = "DiagnosticDeprecated",
Expand Down Expand Up @@ -1562,8 +1562,8 @@ Markdown.render = function(text, repo_base_url, autolinks, ref_links, footnote_m
rendered_text = process_paired_markers(rendered_text, "==([^=]+)==", "MdRenderHighlight", 2, highlights, links)
rendered_text = process_inline_math(rendered_text, "MdRenderMath", highlights, links)

-- Restore code spans (adds String highlight for each span)
rendered_text = restore_code_spans(rendered_text, code_spans, "String", highlights, links)
-- Restore code spans (adds MdRenderInlineCode highlight for each span)
rendered_text = restore_code_spans(rendered_text, code_spans, "MdRenderInlineCode", highlights, links)

-- Restore backslash-escaped characters (adjusts highlight/link positions)
rendered_text = restore_backslashes(rendered_text, backslash_escapes, highlights, links)
Expand Down
4 changes: 2 additions & 2 deletions tests/markdown_checkbox_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ test("html: <em> renders as Italic", function()
assert_eq(highlights[1].hl, "Italic", "html em: should be Italic")
end)

test("html: <code> renders as String", function()
test("html: <code> renders as MdRenderInlineCode", function()
local text, highlights = render("<code>code</code>")
assert_eq(text, "code", "html code: tags should be stripped")
assert_eq(highlights[1].hl, "String", "html code: should be String")
assert_eq(highlights[1].hl, "MdRenderInlineCode", "html code: should be MdRenderInlineCode")
end)

test("html: <s> renders as strikethrough", function()
Expand Down
Loading