Skip to content

Latest commit

 

History

114 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 marklive.nvim

A Neovim plugin for rendering markdown files in terminal marklive nvim

✨ Features

  • 💡 Any element (treesitter, regex_group) can be replaced with icons
  • 💪 Built-in markdown elements config, markdown files work out of the box
  • 💞 Built-in commands MarkliveEnable, MarkliveDisable, MarkliveToggle to enable/disable/toggle the marklive feature
  • ✅ Built-in command MarkliveTaskToggle to toggle markdown task state (supports cascading according to action.task.hierarchy config)
  • 🛴 Supports automatically disabling the marklive feature on the current line for easy editing
  • 🔎 Highly configurable, allowing custom icons for each markdown element, and even custom displays for html files

⚡️ Requirements

📦 Installation

Using lazy.nvim

{
    "yelog/marklive.nvim",
    dependencies = { 'nvim-treesitter/nvim-treesitter' },
    lazy = true,
    ft = "markdown",
    opts = {}
}

Using packer.nvim

use {
  'yelog/marklive.nvim',
  requires = { 'nvim-treesitter/nvim-treesitter' },
}

Using dein

call dein#add('nvim-treesitter/nvim-treesitter')
call dein#add('yelog/marklive.nvim')

Usingn vim-plug

Plug 'nvim-treesitter/nvim-treesitter'
Plug 'yelog/marklive.nvim'

⚙️ Configuration

The default configuration for marklive.nvim is shown in the link config.lua

Code Block Language Badge

Fenced code blocks render the language badge on the left side of the first line. The badge uses language-aware Nerd Font icons and high-contrast colors by default.

You can override or add languages through render.code_block.language_styles:

require('marklive').setup({
  render = {
    code_block = {
      language_styles = {
        default = { icon = '', fg = '#89B4FA' },
        lua = { icon = '', fg = '#7AA2F7' },
        python = { icon = '', fg = '#FFD43B' },
      },
    },
  },
})

Heading Styling

ATX headings are indented by level when rendered: H1 has no extra indent, H2 adds 2 spaces, H3 adds 4 spaces, and so on through H6.

Headings also render a full-line background by default. Each level uses a low-saturation background from the same hue as its heading color, making heading rows easier to distinguish from nested lists and task items without overpowering the document body.

You can override the default indentation through each heading marker config:

require('marklive').setup({
  render = {
    atx_h2_marker = { indent = 2 },
    atx_h3_marker = { indent = 4 },
  },
})

You can customize the heading foreground/background through the matching heading highlight groups, or disable the full-line background for a level:

require('marklive').setup({
  highlight_config = {
    markdownH2 = { highlight = { fg = '#f7c59f', bg = '#3a3028', bold = true } },
    markdownH2Delimiter = { highlight = { fg = '#f7c59f', bg = '#3a3028', bold = true } },
  },
  render = {
    atx_h2_marker = { line_background = false },
  },
})

Task Toggle (MarkliveTaskToggle)

You can use the command :MarkliveTaskToggle to toggle the state of markdown tasks (checkboxes) under the cursor.

  • Cascading (hierarchy) is enabled by default: toggling a parent task will also cascade the change to all its subtasks, and parent tasks will update their state based on their children.
  • If you want to disable cascading, set action.task.hierarchy = false in your config. When disabled, only the current line's task state will be toggled.

Example config to disable cascading:

require('marklive').setup({
  action = {
    task = {
      hierarchy = false
    }
  }
})

Keymap Example

You can bind a shortcut to toggle the task state, for example, using <CR> (Enter) in normal mode:

vim.keymap.set("n", "<CR>", "<cmd>MarkliveTaskToggle<cr>", { desc = "Toggle markdown task" })

If you don't want to use a Nerd Font, you can replace the icons with Unicode symbols.

Table Format

marklive 提供 table_align() 用于格式化光标所在的管道表格,按照分隔行推断对齐方式:

  • 每列宽度取所有行去除左右空格后的最大显示宽度,内容与边框符号至少留 1 个空格。
  • 分隔行 ----/:--- 视为左对齐,:---: 居中,---: 右对齐;需要补齐时在冒号间添加 -,其他行用空格补齐。
  • 默认开启,可通过 action.table.enable = false 关闭。

配置示例:

require('marklive').setup({
  action = {
    table = { enable = true },
  }
})

插件在全局表 Marklive 上暴露了方法,便于通过 keys 配置绑定快捷键(风格示例如下):

-- 例如在 Lazy.nvim opts 中
keys = {
  { "<leader>ta",  function() Marklive.table_align() end,             desc = "Align markdown table" },
  { "<leader>tir", function() Marklive.table_insert_row_below() end,  desc = "Insert row below (table body)" },
  { "<leader>tiR", function() Marklive.table_insert_row_above() end,  desc = "Insert row above (table body)" },
  { "<leader>tic", function() Marklive.table_insert_col_right() end,  desc = "Insert column right (table body)" },
  { "<leader>tiC", function() Marklive.table_insert_col_left() end,   desc = "Insert column left (table body)" },
  { "<leader>tmh", function() Marklive.table_move_col_left() end,     desc = "Swap column with left" },
  { "<leader>tml", function() Marklive.table_move_col_right() end,    desc = "Swap column with right" },
  { "<leader>tmj", function() Marklive.table_move_row_down() end,     desc = "Swap row with below (table body)" },
  { "<leader>tmk", function() Marklive.table_move_row_up() end,       desc = "Swap row with above (table body)" },
  { "<leader>tdr", function() Marklive.table_delete_row() end,        desc = "Delete current row (table body)" },
  { "<leader>tdc", function() Marklive.table_delete_col() end,        desc = "Delete current column" },
  { "<A-h>",       function() Marklive.table_nav_left() end,          desc = "Jump left cell (wrap)",  mode = { "n", "i" } },
  { "<A-l>",       function() Marklive.table_nav_right() end,         desc = "Jump right cell (wrap)", mode = { "n", "i" } },
  { "<A-j>",       function() Marklive.table_nav_down() end,          desc = "Jump down cell (wrap)",  mode = { "n", "i" } },
  { "<A-k>",       function() Marklive.table_nav_up() end,            desc = "Jump up cell (wrap)",    mode = { "n", "i" } },
}

需要其他自定义函数时,也可以将它们放在同一个全局表中统一管理,避免散落的全局函数。

📝 Plan

  • Implement background style rendering for Markdown’sBlock Quote
  • Implement style rendering for Markdown’sCode Block

🔑 License

marklive.nvim is licensed under the Apache 2.0 license

About

A Neovim plugin for rendering markdown files in terminal

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages