0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

markdown-modeでファイルを更新するとHTMLファイルも自動更新されるようにする

Last updated at Posted at 2023-06-04

はじめに

Emacsのmarkdown-modeでは, C-c C-c e (markdown-export) で, HTMLファイルを出力できる.
しかし, Markdownファイルを更新するたびに, 手動でHTMLファイルを再出力するのは面倒.

設定

そこで以下のように設定すると, Markdownファイル保存時に自動でHTMLファイルも更新されるようにできる.
ただし, markdown-command が存在かつ、すでにHTMLファイルが存在する場合にのみ自動出力するようにしている.

~/.emacs.d/init.el
(add-hook 'markdown-mode-hook
          (lambda ()
            (when (executable-find markdown-command)
              (add-hook 'after-save-hook
                        (lambda ()
                          (when (file-exists-p (concat (file-name-sans-extension (buffer-file-name)) ".html"))
                            (markdown-export)
                            ))
                        nil t)
              ))
          )

この設定により, 1度HTMLファイルを手動で出力すると, 以降はMarkdownファイル更新時に自動でHTMLファイルも更新されるようになる.

バージョン情報

  • Emacs 28.2
  • markdown-mode 2.6-alpha

関連記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?