markdown-mode icon indicating copy to clipboard operation
markdown-mode copied to clipboard

`markdown-it` as `markdown-command` not found, despite being visible in shell

Open Kabouik opened this issue 1 year ago • 7 comments

I am trying to use markdown-it as my markdown-command but markdown-mode returns "Markdown command markdown-it is not found". Yet, it is well available and working when I run it from my shell in a terminal.

Expected Behavior

Markdown export to html should work. markdown-it works from the shell:

$ echo "# toto" > toto.md
$ markdown-it toto.md
<h1>toto</h1>

Actual Behavior

I get the above error.

Steps to Reproduce

Evaluate the following and try a Markdown export in a Markdown buffer:

(use-package markdown-mode
  :ensure t
  :mode ("README\\.md\\'" . gfm-mode)
  :init (setq markdown-command "markdown-it"))

Software Versions

  • Markdown Mode: version 2.6-alpha (Guix package)
  • Emacs: GNU Emacs 30.0.50
  • OS: Linux, Guix system

Kabouik avatar Aug 03 '23 08:08 Kabouik

The error vanishes if I hardcode the absolute path of the markdown-it executable:

(use-package markdown-mode
  :ensure t
  :mode ("README\\.md\\'" . gfm-mode)
  :init (setq markdown-command "/home/mat/.local/bin/markdown-it"))

But this is weird because $HOME/.local/bin is in my $PATH, so there is still something off.

Also, the export didn't actually work, but my CPU use got quite high. I don't know if this is a markdown-it issue or because markdown-mode was missing some arguments after the command.

Kabouik avatar Aug 03 '23 09:08 Kabouik

Please check PATH environment variable and exec-path value on Emacs(M-: exec-path, M-: (getenv "PATH") etc).

If you don't launch Emacs from shell, Emacs doesn't inherit PATH value and you have to set PATH configurations in your init.el.

There are some tools to set PATH configuration from your shell configuration files like .bashrc, .zshrc

  • https://github.com/purcell/exec-path-from-shell

syohex avatar Aug 03 '23 09:08 syohex

Thanks, you're right, that was my issue because I launch emacs-daemon from my sway configuration, so it doesn't inherit my shell $PATH.

I'm still experiencing the second issue though: using markdown-it as my markdown-command makes the export use a lot of CPU (and never end unless interrupted) like it is stalling, while running markdown-it somefile.md in shell works immediately. Can markdown-mode work with markdown-it or does it expect a different command line syntax than COMMAND FILE.md?

Kabouik avatar Aug 03 '23 11:08 Kabouik

I cannot reproduce your high CPU usage issue by converting markdown file to HTML with markdown-it and M-x markdown . When does your issue happen ? Could you tell us how to reproduce your issue ?

syohex avatar Aug 04 '23 01:08 syohex

Alright, good to know it does not happen on your end. The steps to reproduce are exactly what you did:

  1. Open a markdown buffer
  2. M-x markdown or M-x markdown-export

So somehow it's on my end, but what I don't get is why markdown-it outside of emacs and markdown-mode works fine. My emacs configuration related to markdown-mode is just the 4 lines of elisp written in the first post.

Kabouik avatar Aug 04 '23 07:08 Kabouik

FYI markdown-mode evaluates (shell-command-on-region (point-min) (point-max) "markdown-it" (get-buffer-create "*markdown-output*")) to convert markdown file into a HTML file.

syohex avatar Aug 07 '23 03:08 syohex

@Kabouik try setting markdown-command-needs-filename to t

snan avatar Nov 10 '23 10:11 snan