posthtml is an emacs org-mode export filter for cosmetic touchups of HTML output; a macro that gives access to the DOM structure, allowing for querying and modification with CSS-like selectors.

It takes an HTML string, or the final HTML output of an org mode export/publishing action, and works with an esxml representation of the DOM tree, as parsed by libxml-parse-html-region; returns a string via esxml-to-xml. Querying is done with enlive.

($each [header nav li]
       (lambda (nav-element uri)
         (let ((href (posthtml$ nav-element [a] :attr 'href)))
           (when (and (not (string= "/" href))
                      (string-prefix-p href uri t))
             (posthtml-attribute nav-element 'class 'current))))
       (page-uri info))


(posthtml:filter-final-output [...])
(posthtml:filter content options [...])


posthtml$ (container selector &optional fn &rest args)

(posthtml$ esxml-container [html] 'posthtml-append "this")
($ [html] :append "this")
($ [html] (lambda (container this) (posthtml-append container this)) "this")

posthtml$each (container selector &optional fn &rest args)

(posthtml$each esxml-container [body p] 'posthtml-append "this")
($each [body p] :append "this")
($each [body p] (lambda (element this) (posthtml-append element this)) "this")

Query CONTAINER for SELECTOR; apply (each) found element and ARGS to FN - the following shorthands are available for FN;

dom manipulation



emacs -batch \
      -l ert \
      -l posthtml-tests.el \
      -f ert-run-tests-batch-and-exit