From f28cf1279785a2f64f01e8204e81000d11e8ffaf Mon Sep 17 00:00:00 2001 From: Walter Leibbrandt Date: Fri, 29 Jul 2022 14:30:01 +0200 Subject: [PATCH 1/3] Enable passing extra args to live-server This enables a high degree of customization. I've found it useful for changing the browser being opened, and changing the port on which the live server is started. --- autoload/markdown.vim | 3 ++- doc/nvim-markdown-preview.txt | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/markdown.vim b/autoload/markdown.vim index 1238ff8..b4e2f10 100644 --- a/autoload/markdown.vim +++ b/autoload/markdown.vim @@ -59,12 +59,13 @@ function! s:LiveServer.start(root, index_path) if !exists('self.pid') let mount_path = fnamemodify(a:index_path, ':h') let index = fnamemodify(a:index_path, ':t') + let extra_opts = get(g:, 'nvim_markdown_preview_liveserver_extra_args', []) let self.pid = jobstart([ \ 'live-server', \ '--quiet', \ '--mount='.'/:'.mount_path, \ '--open='.index, - \ ], + \ ] + extra_opts, \ self, \ ) endif diff --git a/doc/nvim-markdown-preview.txt b/doc/nvim-markdown-preview.txt index de3cb6c..8ff5b82 100644 --- a/doc/nvim-markdown-preview.txt +++ b/doc/nvim-markdown-preview.txt @@ -58,4 +58,11 @@ The default is `gfm` (Github flavored markdown). let g:nvim_markdown_preview_format = 'markdown' < +Set this variable to pass any additional options to live-server. + +> + let g:nvim_markdown_preview_liveserver_extra_args = + \ ['--browser=librewolf', '--port=9999'] +< + vim:tw=78:et:ft=help:norl: From a6a00b3242ff2fd5520d24a2aff4cdcf8ec81eb7 Mon Sep 17 00:00:00 2001 From: Walter Leibbrandt Date: Sun, 31 Jul 2022 13:46:04 +0200 Subject: [PATCH 2/3] Pass input file's directory as live-server's root This fixes broken relative links when previewing files outside of the current working directory. Example: Open a terminal and `cd` to the parent directory of your clone of this repo, run `nvim nvim-markdown-preview/README.md`, and `:MarkdowPreview`. Notice how the screenshot is missing. This happens because the generated HTML's (temporary) directory is mounted at the live server's `/`. This is required for the HTML file to be accessible to live-server, but it also means that relative links are broken, because the temp directory doesn't include linked resources. Previewing files in the current directory happens to work, because live-server's root is the current directory, which live-server apparently falls back to when it can't find something in the directory mounted at `/`. (The server root and `/` mounts appear to be mapped.) This fallback functionality is leveraged to fix relative resource links by setting the live-server root to the directory of the input file. --- autoload/markdown.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/markdown.vim b/autoload/markdown.vim index b4e2f10..096ed84 100644 --- a/autoload/markdown.vim +++ b/autoload/markdown.vim @@ -65,7 +65,7 @@ function! s:LiveServer.start(root, index_path) \ '--quiet', \ '--mount='.'/:'.mount_path, \ '--open='.index, - \ ] + extra_opts, + \ ] + extra_opts + [a:root], \ self, \ ) endif From f89a7f07e1a6564f418fb74334612880a6b26372 Mon Sep 17 00:00:00 2001 From: Walter Leibbrandt Date: Sun, 31 Jul 2022 14:46:30 +0200 Subject: [PATCH 3/3] Change live-server links to point to compodoc's fork --- README.md | 2 +- doc/nvim-markdown-preview.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f11a999..68db46f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # nvim-markdown-preview -Markdown preview in the browser using [pandoc](https://pandoc.org/) and [live-server](https://github.com/tapio/live-server) through Neovim's [job-control API](https://neovim.io/doc/user/job_control.html). +Markdown preview in the browser using [pandoc](https://pandoc.org/) and [live-server](https://github.com/compodoc/live-server) through Neovim's [job-control API](https://neovim.io/doc/user/job_control.html). ## Usage diff --git a/doc/nvim-markdown-preview.txt b/doc/nvim-markdown-preview.txt index 8ff5b82..ba1c5a5 100644 --- a/doc/nvim-markdown-preview.txt +++ b/doc/nvim-markdown-preview.txt @@ -6,7 +6,7 @@ License: GPL3 INTRODUCTION *nvim-markdown-preview* Markdown preview in the browser using pandoc (https://pandoc.org/) and -live-server (https://github.com/tapio/live-server) through Neovim's +live-server (https://github.com/compdoc/live-server) through Neovim's |job-control| API.