helix icon indicating copy to clipboard operation
helix copied to clipboard

Markdown Preview

Open txtyash opened this issue 2 years ago • 22 comments

Markdown preview similar to this plugin: https://github.com/davidgranstrom/nvim-markdown-preview

txtyash avatar Jun 19 '22 18:06 txtyash

An in-terminal preview using the builtin markdown view would be a nice option, too.

CptPotato avatar Jun 21 '22 06:06 CptPotato

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.

txtyash avatar Jun 21 '22 09:06 txtyash

Subjectively, this sounds more like a plugin than a core feature.

felix-u avatar Jun 21 '22 20:06 felix-u

@felix-u Ya, a plugin would suit better.

txtyash avatar Jun 22 '22 06:06 txtyash

This should be a plugin

Jedsek avatar Jul 02 '22 09:07 Jedsek

I found this: https://pypi.org/project/markdown-server/

might be helpful

aikomastboom avatar Jul 21 '22 15:07 aikomastboom

Markdown preview could actually (efficiently) be handled by a language server. There is already https://github.com/euclio/mdpls which does exactly that.

MDeiml avatar Jul 21 '22 19:07 MDeiml

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 avatar Jul 21 '22 20:07 MDeiml

@MDeiml I tried that but it looks like it does not support the $\neq$ :(

TheCaptainCraken avatar Apr 06 '23 07:04 TheCaptainCraken

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.

MDeiml avatar Apr 06 '23 09:04 MDeiml

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.

TheCaptainCraken avatar Apr 06 '23 09:04 TheCaptainCraken

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 avatar Apr 14 '23 19:04 0xlilith

@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.

thorstenweber83 avatar May 10 '23 10:05 thorstenweber83

The preview should also open automatically if you open a markdown file. It works for me at least.

MDeiml avatar May 12 '23 13:05 MDeiml

Hopefully, helix will have better markdown preview or highlight support in the future. So far, I am using vscode for markdown editing.

sgon00 avatar Jun 03 '23 12:06 sgon00

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

jkoshiel avatar Oct 25 '23 02:10 jkoshiel

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.

MDeiml avatar Nov 05 '23 11:11 MDeiml

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?

David-Else avatar Nov 07 '23 21:11 David-Else

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.

arcstur avatar Dec 05 '23 13:12 arcstur

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?

superiums avatar Dec 07 '23 08:12 superiums

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.

arcstur avatar May 13 '24 17:05 arcstur

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?

arcstur avatar May 13 '24 17:05 arcstur

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

mzabani avatar May 14 '24 18:05 mzabani

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!

Gh0stGames avatar Jul 25 '24 19:07 Gh0stGames

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.

pascalkuthe avatar Jul 25 '24 21:07 pascalkuthe