Home

Awesome

nvim-asciidoc-preview

A simple AsciiDoc preview while editing AsciiDoc documents in Neovim.

[!WARNING] The plugin is in an early stage not fully tested. Use at your own risk.

Works on: ✅ Linux, ✅ macOS and ✅ Windows with WSL2

<img width="1000" alt="Screenshot 2024-10-30" src="https://github.com/user-attachments/assets/ac63f6df-292b-4d6d-8680-829083d0dc16">

The plugin started as a playground for learning Neovim plugin programming with Lua and a server component with Node.js. Therefore, many things are not solved optimally and partly implemented twice (plugin and server). Helpful tips are welcome.

Features

Requirements

The plugin allows optionally using the local installed Asciidoctor tools.

Installation

lazy.nvim

{
  'tigion/nvim-asciidoc-preview',
  ft = { 'asciidoc' },
  build = 'cd server && npm install',
  opts = {
    -- Add user configuration here
  },
}

packer.nvim

<details> <summary>Show instruction</summary>
use({
  'tigion/nvim-asciidoc-preview',
  run = 'cd server && npm install',
  config = function()
    require('asciidoc-preview').setup({
      -- Add user configuration here
    })
  end,
})
</details>

Configuration

For lazy.nvim use the opts or config property.

opts = {
  server = {
    converter = 'js'
  },
  preview = {
    position = 'current',
  },
}
<details> <summary>Variant with config</summary>
config = function()
  require('asciidoc-preview').setup({
    server = {
      converter = 'js'
    },
    preview = {
      position = 'current',
    },
  })
end,
</details>

For other plugin manager, call the setup function require('asciidoc-preview').setup({ ... }) directly.

Default Options

Currently available settings for the user:

{
  server = {
    -- Determines how the AsciiDoc file is converted to HTML for the preview.
    -- `js`  - asciidoctor.js (no local installation needed)
    -- `cmd` - asciidoctor command (local installation needed)
    converter = 'js',

    -- Determines the local port of the preview website.
    -- Must be between 10000 and 65535.
    port = 11235,
  },
  preview = {
    -- Determines the scroll position of the preview website.
    -- `current` - Keep current scroll position
    -- `start`   - Start of the website
    -- `sync`    - (experimental) Same (similar) position as in Neovim
    --             => inaccurate, because very content dependent
    position = 'current',
  },
}

Usage

CommandDescription
:AsciiDocPreviewStarts the AsciiDoc preview server in background and opens the current AsciiDoc file in the standard web browser.
:AsciiDocPreviewStop(if needed) Stops the AsciiDoc preview server.
:AsciiDocPreviewOpen(if needed) (Re)Opens the current AsciiDoc file in the standard web browser.
:AsciiDocPreviewNotify(if needed) Notifies the server to display the current AsciiDoc file in the preview.

A keymap suggestion:

vim.keymap.set('n', '<Leader>cp', ':AsciiDocPreview<CR>', { desc = 'Preview AsciiDoc document' })

FAQ

How do I report an issue?

  1. Open an AsciiDoc document in Neovim.
  2. Run the :checkhealth asciidoc-preview command.
  3. Open a new Issue.
  4. Describe your problem and include:
    • the checkhealth output
    • the Installation/Configuration with the used package manager
    • the content of the ~/.local/state/nvim/nvim-asciidoc-preview-server.log file

[!WARNING] The nvim-asciidoc-preview-server.log file contains private information from the current/last session. These are, for example, the name of your home directory and the names of the AsciiDoc files used.

Do not share this information with others. So please remove or anonymize this information before.