jrblevin / markdown-mode

Emacs Markdown Mode
http://jblevins.org/projects/markdown-mode/
GNU General Public License v3.0
877 stars 160 forks source link

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

Open Kabouik opened 11 months ago

Kabouik commented 11 months ago

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

Kabouik commented 11 months ago

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.

syohex commented 11 months ago

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

Kabouik commented 11 months ago

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?

syohex commented 11 months ago

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 ?

Kabouik commented 11 months ago

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.

syohex commented 11 months ago

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.

snan commented 8 months ago

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