markview.nvim

repository·main·Indexed 25 days ago

https://github.com/oxy2dev/markview.nvim

A hackable Neovim plugin providing enhanced previews for Markdown, HTML, LaTeX, Typst, Asciidoc, and YAML. It features a Hybrid Editing Mode for simultaneous editing and previewing, Splitview with scroll synchronization, and Tree-sitter integration for math and code rendering. Supports GitHub-flavored Markdown, Obsidian/PKM extended syntax, and customizable highlight groups.

Tokens
3.4K
Snippets
8
Records
18
Agent score
36%

What's inside markview.nvim

  1. Overview of Markview.nvim features

    main

    markview.nvim is a hackable previewer for Neovim that supports Markdown, HTML, LaTeX, Typst, Asciidoc, and YAML.

    Key capabilities include:

    • Hybrid Editing Mode: Allows simultaneous editing and previewing using either node-based (Tree-sitter) or range-based edit ranges.
    • Splitview: Enables side-by-side editing and previewing with scroll synchronization.
    • Wrap Support: Markdown-specific text wrapping support.
    • Customization: Highly configurable with dynamic highlight groups that adapt to your colorscheme.
    • Completions: Supports Callout and checkbox completions for blink.cmp and nvim-cmp.
    • Tree-sitter Integration: Works with tree-sitter injections.
  2. Preview Markdown, HTML, LaTeX, Typst, and Asciidoc

    main

    markview.nvim provides syntax highlighting and rendering for several formats:

    Markdown

    • GitHub-flavored syntax (tables, checkboxes, block quotes, etc.).
    • Obsidian/PKM extended syntax (block references, embed links, tags, internal links).
    • GitHub emoji shorthands (1920 supported).
    • HTML entity support (786 named entities).
    • Org-mode like indentation for headings.

    HTML

    • Customizable previews for container elements (e.g., <a>, <b>, <code>, <pre>) and void elements (e.g., <hr>, <br>).

    LaTeX

    • Math blocks ($$...$$) and inline math ($...$).
    • Support for math fonts (e.g., \mathbb{}) and 2056 different math symbol definitions.

    Typst

    • Support for headings, labels, list items, math blocks/spans, and symbols.

    Asciidoc

    • Support for admonitions, checkboxes, horizontal rules, and automated TOC.

    YAML

    • Custom property icons and scope decorations based on property type and value.
  3. Toggle Markview previews

    main

    You can disable automatic previews in your configuration and toggle them manually using a keymap. This is useful for performance or when you only want to see the rendered view on demand.

    -- Disable automatic previews.
    require("markview").setup({
        preview = { enable = false }
    });
    
    -- Keymap to toggle previews globally
    vim.api.nvim_set_keymap("n", "<leader>m", "<CMD>Markview<CR>", { desc = "Toggles `markview` previews globally." });
  4. Configure Header Folding with Treesitter

    main

    To modify folding behavior so that only headings are folded (preventing Treesitter from folding other elements), follow these steps:

    1. Create a folds.scm file in ~/.config/nvim/queries/markdown/.
    2. Add the following query to the file:
    ; NOTE: `(#trim!)` is used to prevent empty lines at the end of the section from being folded.
    ((section
        (atx_heading)) @fold
        (#trim! @fold))
    1. Set foldmethod to v:lua.vim.treesitter.foldexpr().
    2. Set foldtext to "".
  5. Use Hybrid Editing Mode

    main

    Hybrid mode allows you to edit and preview at the same time. It supports two types of edit ranges:

    1. Node-based edit range (Default): Clears a range of lines covered by the named TSNode under the cursor. This is ideal for editing structured elements like lists, block quotes, code blocks, or tables.
    2. Range-based edit range: Clears a selected number of lines above and below the cursor.
  6. Configure markview.nvim requirements

    main

    Before using markview.nvim, ensure your environment meets these requirements:

    System

    • Neovim: >= 0.10.3
    • Recommended Settings: Use nowrap and expandtab.

    Parsers (Tree-sitter)

    Install the following parsers via :TSInstall to enable full functionality:

    :TSInstall markdown markdown_inline html latex typst yaml

    Note: On Windows, you may need the tree-sitter CLI for the LaTeX parser.

    Icon Providers

    If using mini.icons or nvim-web-devicons, you must configure the icon_provider in your setup:

    {
        preview = {
            icon_provider = "internal", -- Change to "mini" or "devicons"
        }
    }

    Fonts

    • A modern Unicode font is required for math symbols.
    • Nerd Fonts are recommended.

    Verification

    Run :checkhealth markview after installation to verify your setup.

  7. Install markview.nvim

    main

    Choose the installation method that matches your Neovim plugin manager:

    vim.pack

    Add to your init.lua:

    vim.pack.add({
        "https://github.com/OXY2DEV/markview.nvim",
    })

    Vim-plug

    Add to your plugin list:

    Plug 'OXY2DEV/markview.nvim'

    Lazy.nvim

    Warning: Do not lazy load this plugin (lazy = false). Lazy loading can increase preview load times. Ensure it is loaded after your colorscheme.

    return {
        "OXY2DEV/markview.nvim",
        lazy = false,
    };

    Mini.deps

    local MiniDeps = require("mini.deps");
    
    MiniDeps.add({
        source = "OXY2DEV/markview.nvim",
    });

    Rocks.nvim

    :Rocks install markview.nvim
    -- Example for Lazy.nvim
    return {
        "OXY2DEV/markview.nvim",
        lazy = false,
    };
  8. Apply a single highlight group to all links

    main

    You can use a helper function to apply a single highlight group to various link types (hyperlinks, uri_autolinks, etc.) in the markview configuration.

    local spec = require("markview.spec");
    local config = spec.get({ "markdown_inline", "hyperlinks" }, { fallback = {} });
    
    local function generic_hl (group)
        local output = {};
        for k, v in pairs(config) do
            output[k] = vim.tbl_extend("force", v, { hl = group });
        end
        return output;
    end
    
    require("markview").setup({
        markdown = {
           reference_definitions = generic_hl("MarkviewPalette4Fg")
        },
        markdown_inline = {
            hyperlinks = generic_hl("MarkviewHyperlink"),
            uri_autolinks = generic_hl("MarkviewEmail"),
        },
        typst = {
            url_links = generic_hl("MarkviewEmail")
        }
    });