Giter Club home page Giter Club logo

nvim-asciidoc-preview's Introduction

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, but not yet on ❌ Windows (WSL❓)

screenshot 2024-03-22

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

  • Once started with :AsciiDocPreview, a preview of the current AsciiDoc file is shown in the web browser.
  • The preview is updated every time the AsciiDoc file is saved.
  • When exiting Neovim or using the :AsciiDocPreviewStop command, the preview server is terminated in the background.
  • The generation of the HTML preview is done either with:
    • Asciidoctor.js (default, no local installed Asciidoctor needed)
    • Or the locally installed Asciidoctor tools (asciidoctor and asciidoctor-diagram).

Requirements

  • Neovim >= 0.8
  • Node.js with node and npm command
  • curl command

The plugin allows optionally using the local installed Asciidoctor tools.

Installation

{
  'tigion/nvim-asciidoc-preview',
  cmd = { 'AsciiDocPreview' },
  ft = { 'asciidoc' },
  build = 'cd server && npm install',
  opts = {
    -- Add user configuration here
  },
}
Show instruction
use({
  'tigion/nvim-asciidoc-preview',
  run = 'cd server && npm install',
  config = function()
    require('asciidoc-preview').setup({
      -- Add user configuration here
    })
  end,
})

Configuration

For lazy.nvim use the opts or config property.

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

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

Command Description
:AsciiDocPreview Starts the AsciiDoc preview server in background and opens the current AsciiDoc file in the standard web browser.
:AsciiDocPreviewStop Stops the AsciiDoc preview server.
:AsciiDocPreviewOpen (if needed) (Re)Opens the current AsciiDoc file in the standard web browser.
:AsciiDocPreviewNotify (if needed) Notifies server about an update on the last saved AsciiDoc file.

A keymap suggestion:

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

To use the same keymap for different file types and plugins (e.g. markdown-preview.nvim), place it in after/ftplugin/asciidoc.lua. This way the keymap is only set for AsciiDoc files.

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

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.

nvim-asciidoc-preview's People

Contributors

edeneast avatar tigion avatar

Stargazers

 avatar  avatar  avatar  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

nvim-asciidoc-preview's Issues

No AsciiDoc file to preview

Hi,
just recently I started to get this message in browser when I start the preview:

😴 Server is waiting ... currently is no AsciiDoc file to preview!

Tried to remove and install the plug again, but result is the same.

Any hint on why this is happening?

Thanks

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.