Giter Club home page Giter Club logo

mdpreview.nvim's Introduction

mdpreview.nvim

mdpreview.nvim is a Neovim plugin to preview Markdown files using CLI Markdown renderers. By default, uses charmbracelet/glow. It can use any CLI that can render Markdown from STDIN.

Demo gif of live updating Markdown preview

Plugin Status

This plugin should be considered alpha software at this time. Breaking changes may land on master at any time. Once the plugin is stable I will move to semantic versioning.

Installation

First ensure you have glow (or another Markdown renderer CLI) installed on your system. If it is not in $PATH, you can configure an explicit path in the plugin settings.

With lazy.nvim

{
  'mrjones2014/mdpreview.nvim',
  ft = 'markdown', -- you can lazy load on markdown files only
  -- requires the `terminal` filetype to render ASCII color and format codes
  dependencies = { 'norcalli/nvim-terminal.lua', config = true },
}

Usage

From a Markdown file, run the :Mdpreview command to start a live-updating preview in a vertical split, and :Mdpreview! to close it. You can also run :MdpreviewCurrent to run the preview in a new buffer in the current window, and :MdpreviewCurrent! to close it. Both previews can also be closed with q, or by closing the source buffer.

Configuration

Default configuration shown below:

require('mdpreview').setup({
  -- specify manually if `glow` is not on `$PATH` or you want to use another CLI, or use different args
  cli_args = {
    'glow',
    -- glow assumes you want no colors if not run in a TTY
    '-s',
    'dark',
    -- let nvim handle word wrapping, disable glow word wrap
    '-w',
    '1',
    -- don't unexpectedly make network connections
    '--local',
  },
  -- enabled on these filetypes
  filetypes = { 'markdown', 'markdown.pandoc', 'markdown.gfm' },
  renderer = {
    -- use the nvim buffer renderer, currently `buffer` is the only available backend
    backend = 'buffer',
    -- options for the renderer backend
    opts = {
      -- if you don't want to use a vertical split, create your own window
      -- and return the window ID. May be a function or a number if you already
      -- have the window ID
      winnr = function()
        vim.cmd('vsp')
        return vim.api.nvim_get_current_win()
      end,
      -- options that will be set on the preview window
      win_opts = {
        signcolumn = 'no',
        number = false,
        concealcursor = 'niv',
        wrap = true,
        linebreak = true,
      },
    },
  },
})

API

You can override Config.renderer by passing it as a table into preview() like so:

require('mdpreview').preview({
  backend = 'buffer',
  opts = {
    winnr = function()
      return some_window_id
    end,
  },
})

mdpreview.nvim's People

Contributors

mrjones2014 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mdpreview.nvim's Issues

FR: Using tmux as an alternative to nvim-terminal

Right now I don't have the time to check how this could be implemented, but it would be nice that the plugin detects if nvim is running in a tmux session and uses a tmux window command to open the glow previewer.

Or maybe a simpler version would be a config parameter that when activated uses tmux instead of nvim-terminal.

What do you think?

Render options not being applied

When setting custom options in the .setup() function, they are not used when using the commands :Mdpreview.

Example config:

      require('mdpreview').setup {
        renderer = {
          opts = {
            win_opts = {
              wrap = false,
            },
          },
        },
      }

When using the command :Mdpreview, I was expecting the new window to have the win_opts I'm overriding. Instead, the default config with wrap = true is being used.

The issue should be in this line where the default opts are being used and not the ones coming from the .setup().

Thanks for the plugin :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.