render-markdown.nvim

render-markdown.nvim

优化Neovim中Markdown文件的渲染效果

render-markdown.nvim插件通过增强Markdown文件的渲染效果,改善了Neovim中的文档浏览体验。该插件完全集成于Neovim环境,无需额外窗口,可在不同模式间切换渲染视图。它支持渲染多种Markdown元素,如标题、代码块、列表和表格,并能处理LaTeX公式。插件还提供自定义处理程序和反隐藏功能,满足个性化需求。render-markdown.nvim致力于为Neovim用户提供更直观、美观的Markdown文件呈现方式。

NeovimMarkdown渲染插件开发Lua配置Github开源项目

render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim

[!NOTE]

Repo has been renamed from markdown.nvim to make things more consistent.

Github will redirect all requests so nothing should break for most users.

For lazy.nvim & tokyonight.nvim users changing the plugin name will remove custom highlights until the following is merged #620.

In the meantime you can fix this by adding the following to your config:

require('tokyonight').setup({ plugins = { markdown = true }, })

For rocks.nvim users migrate to the new LuaRock.

:Rocks prune markdown.nvim :Rocks install render-markdown.nvim
<!-- panvimdoc-ignore-start -->
HeadingTable
QuoteLaTeX
Callout
<!-- panvimdoc-ignore-end -->

Features

  • Functions entirely inside of Neovim with no external windows
  • Changes between rendered view in normal mode and raw view in all other modes
  • Supports anti-conceal behavior, removing any virtual text added by this plugin on the line the cursor is on, this does have a performance penalty and can be disabled
  • Changes window options between rendered and raw view based on configuration
    • Effects conceallevel & concealcursor by default
  • Supports rendering markdown injected into other file types
  • Renders the following markdown components:
    • Headings: highlight depending on level and replaces # with icon
    • Horizontal breaks: replace with full-width lines
    • Code blocks: highlight to better stand out
      • Adds language icon 1, requires icon provider (mini.icons or nvim-web-devicons)
      • Left pad lines within block 1
    • Inline code: highlight to better stand out
    • List bullet points: replace with provided icon based on level
    • Checkboxes: replace with provided icon based on whether they are checked
    • Block quotes: replace leading > with provided icon
    • Tables: replace border characters, handles misaligned tables but does NOT align according to delimiter indicator
    • Callouts
      • Github & Obsidian out of the box, supports user defined as well
    • Custom checkbox states 1, function similar to callouts
    • Adds icon before images / links 1
    • LaTeX blocks: renders formulas if latex parser and pylatexenc are installed
  • Disable rendering when file is larger than provided value
  • Support custom handlers which are ran identically to builtin handlers

Requirements

  • neovim >= 0.9.0 (minimum) >= 0.10.0 (recommended)
  • treesitter parsers:
  • Icon provider plugin (Optional): Used for icon above code blocks
  • System dependencies:
    • pylatexenc (Optional): Used to transform LaTeX strings to appropriate unicode using latex2text

Install

lazy.nvim

{ 'MeanderingProgrammer/render-markdown.nvim', opts = {}, dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.nvim' }, -- if you use the mini.nvim suite -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.icons' }, -- if you use standalone mini plugins -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons }

rocks.nvim

This plugin is available on LuaRocks

:Rocks install render-markdown.nvim

packer.nvim

use({ 'MeanderingProgrammer/render-markdown.nvim', after = { 'nvim-treesitter' }, requires = { 'echasnovski/mini.nvim', opt = true }, -- if you use the mini.nvim suite -- requires = { 'echasnovski/mini.icons', opt = true }, -- if you use standalone mini plugins -- requires = { 'nvim-tree/nvim-web-devicons', opt = true }, -- if you prefer nvim-web-devicons config = function() require('render-markdown').setup({}) end, })

Commands

  • :RenderMarkdown | :RenderMarkdown enable - Enable this plugin
    • Can also be accessed directly through require('render-markdown').enable()
  • :RenderMarkdown disable - Disable this plugin
    • Can also be accessed directly through require('render-markdown').disable()
  • :RenderMarkdown toggle - Switch between enabling & disabling this plugin
    • Can also be accessed directly through require('render-markdown').toggle()
  • :RenderMarkdown expand - Increase anti-conceal margin above and below by 1
    • Can also be accessed directly through require('render-markdown').expand()
  • :RenderMarkdown contract - Decrease anti-conceal margin above and below by 1
    • Can also be accessed directly through require('render-markdown').contract()

Setup

Checkout the Wiki for examples and images associated with different configuration options.

The full default configuration is provided below for reference.

Any part of it can be modified however for many fields this does not make much sense.

Some of the more useful fields are discussed further down.

<details> <summary>Full Default Configuration</summary>
require('render-markdown').setup({ -- Whether Markdown should be rendered by default or not enabled = true, -- Maximum file size (in MB) that this plugin will attempt to render -- Any file larger than this will effectively be ignored max_file_size = 10.0, -- Milliseconds that must pass before updating marks, updates occur -- within the context of the visible window, not the entire buffer debounce = 100, -- Pre configured settings that will attempt to mimic various target -- user experiences. Any user provided settings will take precedence. -- obsidian: mimic Obsidian UI -- lazy: will attempt to stay up to date with LazyVim configuration -- none: does nothing preset = 'none', -- Capture groups that get pulled from markdown markdown_query = [[ (atx_heading [ (atx_h1_marker) (atx_h2_marker) (atx_h3_marker) (atx_h4_marker) (atx_h5_marker) (atx_h6_marker) ] @heading) (thematic_break) @dash (fenced_code_block) @code [ (list_marker_plus) (list_marker_minus) (list_marker_star) ] @list_marker (task_list_marker_unchecked) @checkbox_unchecked (task_list_marker_checked) @checkbox_checked (block_quote) @quote (pipe_table) @table ]], -- Capture groups that get pulled from quote nodes markdown_quote_query = [[ [ (block_quote_marker) (block_continuation) ] @quote_marker ]], -- Capture groups that get pulled from inline markdown inline_query = [[ (code_span) @code (shortcut_link) @shortcut [(inline_link) (full_reference_link) (image)] @link ]], -- The level of logs to write to file: vim.fn.stdpath('state') .. '/render-markdown.log' -- Only intended to be used for plugin development / debugging log_level = 'error', -- Filetypes this plugin will run on file_types = { 'markdown' }, -- Vim modes that will show a rendered view of the markdown file -- All other modes will be uneffected by this plugin render_modes = { 'n', 'c' }, -- Set to avoid seeing warnings for conflicts in health check acknowledge_conflicts = false, anti_conceal = { -- This enables hiding any added text on the line the cursor is on enabled = true, -- Number of lines above cursor to show above = 0, -- Number of lines below cursor to show below = 0, }, latex = { -- Whether LaTeX should be rendered, mainly used for health check enabled = true, -- Executable used to convert latex formula to rendered unicode converter = 'latex2text', -- Highlight for LaTeX blocks highlight = 'RenderMarkdownMath', -- Amount of empty lines above LaTeX blocks top_pad = 0, -- Amount of empty lines below LaTeX blocks bottom_pad = 0, }, heading = { -- Turn on / off heading icon & background rendering enabled = true, -- Turn on / off any sign column related rendering sign = true, -- Determines how the icon fills the available space: -- inline: underlying '#'s are concealed resulting in a left aligned icon -- overlay: result is left padded with spaces to hide any additional '#' position = 'overlay', -- Replaces '#+' of 'atx_h._marker' -- The number of '#' in the heading determines the 'level' -- The 'level' is used to index into the array using a cycle icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' }, -- Added to the sign column if enabled -- The 'level' is used to index into the array using a cycle signs = { '󰫎 ' }, -- Width of the heading background: -- block: width of the heading text -- full: full width of the window -- Can also be an array of the above values in which case the 'level' is used -- to index into the array using a clamp width = 'full', -- Amount of padding to add to the left of headings left_pad = 0, -- Amount of padding to add to the right of headings when width is 'block' right_pad = 0, -- Minimum width to use for headings when width is 'block' min_width = 0, -- Determins if a border is added above and below headings border = false, -- Highlight the start of the border using the foreground highlight border_prefix = false, -- Used above heading for border above = '▄', -- Used below heading for border below = '▀', -- The 'level' is used to index into the array using a clamp -- Highlight for the heading icon and extends through the entire line backgrounds = { 'RenderMarkdownH1Bg', 'RenderMarkdownH2Bg', 'RenderMarkdownH3Bg', 'RenderMarkdownH4Bg', 'RenderMarkdownH5Bg', 'RenderMarkdownH6Bg', }, -- The 'level' is used to index into the array using a clamp -- Highlight for the heading and sign icons foregrounds = { 'RenderMarkdownH1', 'RenderMarkdownH2', 'RenderMarkdownH3', 'RenderMarkdownH4', 'RenderMarkdownH5', 'RenderMarkdownH6', }, }, code = { -- Turn on / off code block & inline code rendering enabled = true, -- Turn on / off any sign column related rendering sign = true, -- Determines how code blocks & inline code are rendered: -- none: disables all rendering -- normal: adds highlight group to code blocks & inline code, adds padding to code blocks -- language: adds language icon to sign column if enabled and icon + name above code blocks -- full: normal + language style = 'full', -- Determines where language icon is rendered: -- right: right side of code block -- left: left side of code block position = 'left', -- An array of language names for which background highlighting will be disabled -- Likely because that language has background highlights itself disable_background = { 'diff' }, -- Width of the code block background: -- block: width of the code block -- full: full width of the window width = 'full', -- Amount of padding to add to the left of code blocks left_pad = 0, -- Amount of padding to add to the right of code blocks when width is 'block' right_pad = 0, -- Minimum width to use for code blocks when width is 'block' min_width = 0, -- Determins how the top / bottom of code block are rendered: -- thick: use the same highlight as the code body -- thin: when lines are empty overlay the above & below icons border = 'thin', -- Used above code blocks for thin border above = '▄', -- Used below code blocks for thin border below = '▀', -- Highlight for code blocks highlight = 'RenderMarkdownCode', -- Highlight for inline code highlight_inline = 'RenderMarkdownCodeInline', }, dash = { -- Turn on / off thematic break rendering enabled = true, -- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break' -- The icon gets repeated across the window's width icon = '─', -- Width of the generated line: -- <integer>: a hard coded width value -- full: full width of the window width = 'full', -- Highlight for the whole line generated from the icon highlight = 'RenderMarkdownDash', }, bullet = { -- Turn on / off list bullet rendering enabled = true, -- Replaces '-'|'+'|'*' of 'list_item' -- How deeply nested the list is determines the 'level' -- The 'level' is used to index into the array using a cycle -- If the item is a 'checkbox' a conceal is used to hide the bullet instead icons = { '●', '○', '◆', '◇' }, -- Padding to add to the left of bullet point left_pad = 0, -- Padding to add to the right of bullet point right_pad = 0, -- Highlight for the bullet icon highlight = 'RenderMarkdownBullet', }, -- Checkboxes are a special instance of a 'list_item' that start with a 'shortcut_link' -- There are two special states for unchecked & checked defined in the markdown grammar checkbox = { -- Turn on / off checkbox state rendering enabled = true, unchecked = { -- Replaces '[ ]' of 'task_list_marker_unchecked' icon = '󰄱 ', -- Highlight for the unchecked icon highlight = 'RenderMarkdownUnchecked', }, checked = { -- Replaces '[x]' of 'task_list_marker_checked' icon = '󰱒 ', -- Highligh for the checked icon highlight = 'RenderMarkdownChecked', }, -- Define custom checkbox states, more involved as they are not part of the markdown grammar -- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks -- Can specify as many additional states as you like following the 'todo' pattern below -- The key in this case 'todo' is for healthcheck and to allow users to change its values -- 'raw': Matched against the raw text of a 'shortcut_link' -- 'rendered': Replaces the 'raw' value when rendering -- 'highlight': Highlight for the 'rendered' icon custom = { todo = { raw = '[-]', rendered = '󰥔 ', highlight = 'RenderMarkdownTodo' }, }, }, quote = { -- Turn on / off block quote & callout rendering

Footnotes

  1. Requires neovim >= 0.10.0 2 3 4

编辑推荐精选

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

Hunyuan3D-2

Hunyuan3D-2

高分辨率纹理 3D 资产生成

Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。

3FS

3FS

一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。

3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。

下拉加载更多