Skip to content

boborbt/marp-dev-preview.nvim

Repository files navigation

Marp Dev Preview - NeoVim Plugin

Seamlessly integrate Marp Dev Preview into NeoVim with slide syncing and quick navigation.

Warning

Currently the plugin has been mainly tested on MacOS and Linux. Please open an issue if you encounter any problems on other operating systems, but keep in mind that I don't have access to windows machines (but I'm happy to review and merge PRs fixing issues on windows).

Features

  • Starts/stops the preview server (experimental)
  • Live Sync Slides
    • Updates the preview as you edit your Markdown slides (rendering incrementally at each buffer change).
    • Keep your Markdown slide position synced with the preview. (One-way sync: browser → NeoVim not supported.)
  • Goto Slide – Jump to a specific slide. Temporarily disables auto-sync.
  • Next/Prev Slides - provides commands to navigate to the next/previous slide in your markdown file.

mdp-live-demo


Quick Start

Install with the plugin manager of your choice, here is a lazy.nvim example (at the end of this README you can find a complete lazy.nvim example with key mappings):

use {
  'boborbt/marp-dev-preview.nvim',
  requires = { 'nvim-lua/plenary.nvim' },
  config = function()
    require('marp-dev-preview').setup({ })
  end
}

The plugin provides support to start the Marp Dev Preview server for you. If you prefer to start it yourself, you can follow the instructions in the Marp Dev Preview server repository to set the server up. And use MarpDevPreviewStartAttach command to connect your marp buffer with the server.

To start the server and the live sync, run the following command in NeoVim:

:MarpDevPreviewStartAll

Other commands you might find useful:

:MarpDevPreviewStartServer
:MarpDevPreviewStopServer
:MarpDevPreviewStartLiveSync
:MarpDevPreviewStopLiveSync
:MarpDevPreviewToggleLiveSync
:MarpDevPreviewGoto
:MarpDevPreviewNextSlide
:MarpDevPreviewPrevSlide
:MarpDevPreviewStartAttach
  • MarpDevPreviewStartAll starts the Marp Dev Preview server (if not already running), opens a browser on the preview page, and enables live sync.
  • MarpDevPreviewStartServer starts the Marp Dev Preview server from within NeoVim (experimental) and opens a browser on the preview page.
  • MarpDevPreviewStopServer stops the Marp Dev Preview server started from within NeoVim.
  • MarpDevPreviewStartLiveSync enables live sync between your markdown file and the preview, it will not work if the server is not running. You can provide as an argument the port number on which the server is running (not necessary if you started the server from within NeoVim).
  • MarpDevPreviewStopLiveSync disables live sync.
  • MarpDevPreviewToggleLiveSync toggles live sync on or off.
  • MarpDevPreviewGoto allows you to jump to a specific slide within your markdown file (if live sync is enabled, the preview will update accordingly).
  • MarpDevPreviewNextSlide jumps to the next slide in your markdown file (if live sync is enabled, the preview will update accordingly).
  • MarpDevPreviewPrevSlide jumps to the previous slide in your markdown file (if live sync is enabled, the preview will update accordingly).
  • MarpDevPreviewStartAttach connects your marp buffer with a running Marp Dev Preview server. You can provide as an argument the port number on which the server is running.

Configuration

You can customize the plugin by passing options to the setup function. Here are the available options and their default values:

Option Type Default Description
live_sync boolean false If true, live sync will be started automatically when starting the server.
browser_start_timeout number 3000 Timeout in milliseconds for trying to establish a connection with marp-dev-preview server before giving up opening the browser.
browser_start_waiting_interval number 100 Interval in milliseconds between two attempts to check if the server is reachable when opening the browser.
server_cmds_timeout number 1000 Timeout in milliseconds for server operations.
live_sync_start_timeout number 3000 Timeout in milliseconds for trying to start live sync. If the server is not running or not reachable within this time, an error will be shown.
live_sync_waiting_interval number 100 Interval in milliseconds between two attempts to check if the server is reachable when starting live sync.
port number 8080 base port number for the connection with marp-dev-preview. The plugin will try to connect to a random port computed as port + n where n is a random number between 0 and 1000. This is to avoid port conflicts if you run multiple instances of NeoVim or if you want to connect to different presentations.
theme_set array {} If set, it will be passed to the Marp Dev Preview server as the --theme-set argument. See Marp Dev Preview server documentation for details. The directory should be relative to the current working directory.

Defaults:

require('marp-dev-preview').setup({
  live_sync = true,
  -- timeout for server operations in milliseconds
  server_cmds_timeout = 1000,

  -- timeout for server startup in milliseconds
  browser_start_timeout = 3000,
  browser_start_waiting_interval = 500,
:
  -- timeout for live sync start in milliseconds
  live_sync_start_timeout = 3000,
  live_sync_waiting_interval = 500,

  -- base port for the marp-dev-preview server
  port = 8080,

  -- directory containing custom themes, relative to current directory
  theme_set = nil
})

Lualine configuration

You can configure lualine to show the live preview sync status by using the statusline function from the main module. For example:

require("lualine").setup({
      options = {
        ...
      },
      sections = {
        ...
        lualine_c = { ..., require('marp-dev-preview').statusline, ... },
        ...
      },
      ...

Contributing

I’m new to Lua and NeoVim plugin development. Feedback, issues, and pull requests are welcome! Help improve the plugin for everyone.

I'm opening issues for enhancements and bugs as I find them. Feel free to peruse them if you're looking for something to work on.


Complete lazy.nvim configuration example with key mappings:**

return {
  "boborbt/marp-dev-preview.nvim",
  branch = "server-start",
  lazy = false,
  config = function()
    mdp = require('marp-dev-preview')
    mdp.setup({
      live_sync = true,
      theme_set = { "theme" }
    })
  end,

  keys = {
    {
      "<leader>ms",
      "<cmd>MarpDevPreviewStartServer<cr>",
      desc = "Marp: start server",
      mode = "n"
    },
    {
      "<leader>mS",
      "<cmd>MarpDevPreviewStopServer<cr>",
      desc = "Marp: stop server",
      mode = "n"
    },
    {
      "<leader>ml",
      "<cmd>MarpDevPreviewStartLiveSync<cr>",
      desc = "Marp: start live sync",
      mode = "n"
    },
    {
      "<leader>mL",
      "<cmd>MarpDevPreviewStopLiveSync<cr>",
      desc = "Marp: stop live sync",
      mode = "n"
    },
    {
      "<leader>mx", function() mdp.start_server_and_live_sync() end,
      desc = "Marp: start live sync and server",
    },
    {
      "<leader>mX",
      "<cmd>MarpDevPreviewStopLiveSync<cr><cmd>MarpDevPreviewStopServer<cr>",
      desc = "Marp: stop live sync and server",
      mode = "n"
    },
    {
      "<leader>mg",
      "<cmd>MarpDevPreviewGoTo<cr>",
      desc = "Marp: go to slide",
    },
    {
      "<C-n>",
      "<cmd>MarpDevPreviewNextSlide<cr>zz",
      desc = "Marp: next slide",
      mode = "n"
    },
    {
      "<C-p>",
      "<cmd>MarpDevPreviewPrevSlide<cr>zz",
      desc = "Marp: previous slide",
      mode = "n"
    },
  }
}

About

NeoVim plugin to integrate marp-dev-preview

Resources

Stars

Watchers

Forks

Packages

No packages published