in org-mode, is there a function to export (current) subtree to HTML?

Viewed 6092

In org-mode, is there a function to export (current) subtree to HTML? How would one go about doing this?

4 Answers

The function is org-html-export-to-html which can be called with arguments nil t to export the current subtree.

(defun subtree-html () 
  (interactive) 
  (org-html-export-to-html nil t))

You can also create macro (which may then be executed by a function).

Steps:

  1. Start recording a keyboard macro: C-x ( https://www.gnu.org/software/emacs/manual/html_node/emacs/Basic-Keyboard-Macro.html#Basic-Keyboard-Macro
  2. Follow the steps of this answer: https://stackoverflow.com/a/20630177/1137803 (M-x org-export-dispatch C-s h h)
  3. Stop recording the macro: C-x e
  4. Saving with kmacro-name-last-macro (not name-last-kbd-macro)
  5. Inserting to file with M-x insert-kbd-macro
  6. Replace setq last-kbd-macro with execute-kbd-macro
  7. Now you can make this a (potentially interactive) function (or put it into a lambda and bind to a key). E.g. (defun subtree-html () (interactive) (execute-kbd-macro _____)) where _____ is the output of insert-kbd-macro.

If there is a less convoluted way to do this that doesn't impact visibility/narrowing (or can easily restore it), I'm curious to hear it.

Related