Skip to content

A Neovim plugin for rendering markdown files in terminal

License

Notifications You must be signed in to change notification settings

yelog/marklive.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages