helix
helix copied to clipboard
Markdown Preview
Markdown preview similar to this plugin: https://github.com/davidgranstrom/nvim-markdown-preview
An in-terminal preview using the builtin markdown view would be a nice option, too.
An in-terminal preview using the builtin markdown view would be a nice option, too.
I don't think so. I've used similar with neovim and it's terrible. It has all wrong colors and no way to view images.
But I wouldn't say no to both types of previews.
Subjectively, this sounds more like a plugin than a core feature.
@felix-u Ya, a plugin would suit better.
This should be a plugin
I found this: https://pypi.org/project/markdown-server/
might be helpful
Markdown preview could actually (efficiently) be handled by a language server. There is already https://github.com/euclio/mdpls which does exactly that.
Actually installing that and adding
[[language]]
name = "markdown"
language-server = { command = "/path/to/mdpls" }
config = { markdown.preview.auto = true, markdown.preview.browser = "firefox" }
to your language.toml
already gives you a markdown preview. The repo I linked seems to be missing a few core features though, e.g. images don't work and I would love some auto-scrolling.
@MDeiml I tried that but it looks like it does not support the $\neq$ :(
Not sure if latex is supported for that repo, seems like it uses https://github.com/euclio/aurelius under the hood which might support latex? I'm not sure.
You could open an issue in that repo and ask the author.
Yep I looked into that and it should support latex. I checked and it supports all other symbols like $\sqrt x$ $\gt$ etc. It actually prints the $\ne$ butit renders it like \ = wich is odd. I'll open an issue there.
Actually installing that and adding
[[language]] name = "markdown" language-server = { command = "/path/to/mdpls" } config = { markdown.preview.auto = true, markdown.preview.browser = "firefox" }
to your
language.toml
already gives you a markdown preview. The repo I linked seems to be missing a few core features though, e.g. images don't work and I would love some auto-scrolling.
how do I open the preview?
@0xlilith
:lsp-workspace-command Open\ Preview
should do the trick!
If it does not open, mdpls probably can not find the browser you specified inside your path.
The preview should also open automatically if you open a markdown file. It works for me at least.
Hopefully, helix will have better markdown preview or highlight support in the future. So far, I am using vscode for markdown editing.
Actually installing that and adding
[[language]] name = "markdown" language-server = { command = "/path/to/mdpls" } config = { markdown.preview.auto = true, markdown.preview.browser = "firefox" }
to your
language.toml
already gives you a markdown preview. The repo I linked seems to be missing a few core features though, e.g. images don't work and I would love some auto-scrolling.
Is there a way to control the presentation theme in the Firefox preview? e.g. not white text on black background. Don't think I want to manage the css directly in the markdown files as that would impact it's presentation everywhere
Doesn't seem like it, but it doesn't seem to hard to implement yourself. Maybe create an issue or pull request in https://github.com/euclio/mdpls? Or you could just fork that repo and edit the template to your liking.
I am using gh extension install yusukebe/gh-markdown-preview
, it is great and has live reload, but no mirroring the line position in Helix and the browser. Can anything do that in Helix? Does mdpls do anything extra?
Actually installing that and adding
[[language]] name = "markdown" language-server = { command = "/path/to/mdpls" } config = { markdown.preview.auto = true, markdown.preview.browser = "firefox" }
to your
language.toml
already gives you a markdown preview. The repo I linked seems to be missing a few core features though, e.g. images don't work and I would love some auto-scrolling.
This is awesome, thank you very much. This, however, disables marksman
, which has cool features (creating Table of Contents, [[wiki lins]], [[#heading links]], etc). So I instead use this:
[[language]]
name = "markdown"
language-servers = ["marksman", "mdpls"]
[language-server.mdpls]
command = "/home/arcstur/.cargo/bin/mdpls"
config = { markdown.preview.auto = true }
Open Preview doesn't appear in the workspace commands, but it always open a new preview when opening a markdown file. I don't know how to merge both workspace commands of the two LSPs.
modern browser is so weight for preview task. maybe something light more suit for this. i'll tried dillo , but not work.
vimb, midori works. any more good one?
I think that choosing a good theme makes a lot of difference. I saw that only a few themes have different colors for heading levels. Kanagawa, sonokai and papercolor have, for example. Only a few themes use colors for italic and bold, monokai being one of them. I think that using that, markdown already looks a lot better.
The only theme I found that had different colors both for h1/h2 and for bold/italic is onelight. I wonder if we can modify other themes to also differentiate colors on bold/italic/h1/h2. Doing that I think will make the markdown experience much better.
Markdown is made such that seeing it as code already makes it good, so I don't think we need different sizes for headings for example.
The only thing I would miss is having image previews. If someone that understands the codebase could guide me into where to start developing this, I would like it very much. I know it would be a plugin and we still need a plugin system haha.
Looking at the code in /runtime/themes/ we can see that some themes define what I mentioned.
Kanagawa using colors for heading levels:
"markup.heading.marker" = "springViolet2"
"markup.heading.1" = { fg = "surimiOrange", modifiers = ["bold"] }
"markup.heading.2" = { fg = "carpYellow", modifiers = ["bold"] }
"markup.heading.3" = { fg = "waveAqua2", modifiers = ["bold"] }
"markup.heading.4" = { fg = "lightBlue", modifiers = ["bold"] }
"markup.heading.5" = { fg = "oniViolet", modifiers = ["bold"] }
"markup.heading.6" = { fg = "springViolet1", modifiers = ["bold"] }
Monokai using colors for bold and italic
"markup.bold" = { fg = "yellow", modifiers = ["bold"] }
"markup.italic" = { fg = "magenta", modifiers = ["italic"] }
In my personal opinion, having colors for both heading levels and bold + italic make reading markdown much easier.
I wonder if we also can do that for other themes, or that is defined by the theme authors and we would violate their intetions. What are the maintainer thoughts on this?
I wrote a bash script that previews anything pandoc can render in the terminal itself, and detects modifications to the file to reload. My helix-config-foo isn't great so I'm not sure if this can be integrated well; I'm currently using it in a separate terminal tab/window. I hope this is useful to someone! It requires inotify-tools, termpdf.py or some other in-terminal PDF reader (do change the code if you're using something else) and pandoc.
#!/usr/bin/env bash
set -eo pipefail
FILE="$(realpath "$1")"
TMPDIR="$(mktemp -d)"
PDF="$TMPDIR/rendered.pdf"
trap "pkill -P $$ && rm -rf \"$TMPDIR\"" exit
regen() {
inotifywait -q -e modify "$FILE" "$TMPDIR/closing.signal" > "$TMPDIR/inotify.log"
grep -q "$TMPDIR/closing.signal" "$TMPDIR/inotify.log" || {
pandoc "$FILE" -o "$PDF"
pkill -P "$$" # Kills children of these script, which can only be termpdf.py at this point
}
}
pushd "$TMPDIR" >/dev/null # termpdf.py's log file will go here and will be deleted on exit
pandoc "$FILE" -o "$PDF"
touch closing.signal
while :
do
regen &
termpdf.py "$PDF" && popd>/dev/null && echo 1 >"$TMPDIR/closing.signal" && exit 0 # If the user quits the viewer, we can exit nicely
done
I'm not sure how to do it, but this seems like a fairly simple solution if it could be built into Helix, may also be able to simply use it as a language server in languages.toml: https://github.com/jannis-baum/vivify
Editor Support Vivify has a simple API to integrate your favorite editor so the viewer live updates to any changes as you are typing and the scrolling is smoothly synchronized! See below for a list of existing editor plugins. In case your favorite editor is not yet supported, use these as an example to write your own and add it to the list!
Vivify has a simple API to integrate your favorite editor
... if your "favorite editor" is written in javascript. This is something that can be covered by an LSP but it does not fit into core.