I want to defined a new export backend derived from org-html-export backend in order to remove the divs that appear in the code (something like slimhtml but a little less drastic) and maybe later I want to change the styling a bit with some other html, my first attempt is just to remove divs.

My attempt was to do this

(defun my-org-html-section (section contents info)
  "Transcode a SECTION element from Org to HTML.
CONTENTS holds the contents of the section.  INFO is a plist
holding contextual information."
  (let ((parent (org-export-get-parent-headline section)))
    ;; Before first headline: no container, just return CONTENTS.
    (if (not parent) contents
      ;; Get div's class and id references.
      (let* ((class-num (+ (org-export-get-relative-level parent info)
               (1- (plist-get info :html-toplevel-hlevel))))
          (and (org-export-numbered-headline-p parent info)
            (org-export-get-headline-number parent info) "-"))))
        ;; Build return value.
    (format "%s"
        (or contents ""))))))

(defun my-org-html-export-to-html
  (&optional async subtreep visible-only body-only ext-plist)
  "Export current buffer to a HTML file.
If narrowing is active in the current buffer, only export its
narrowed part.
Return output file's name."
  (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
     (file (org-export-output-file-name extension subtreep))
     (org-export-coding-system org-html-coding-system))
    (org-export-to-file 'html file
      async subtreep visible-only body-only ext-plist)))

(org-export-define-derived-backend 'my-html 'html
  :translate-alist '((section . my-org-html-section))
  :menu-entry '(?s "Export to html"
      ((?H "As html buffer" my-org-html-export-to-html))))

which is an alteration of org-mode-export

But when I export I still get the divs. Any idea why my custom export does not use the custom section ? I am still new to elisp.

  • Have you defined my-org-html-export-to-html?
    – JeanPierre
    Apr 11, 2022 at 7:54
  • Sorry yes, it is a remnant of some of my attempts. It was a copy/paste of org-html-export-to-html. Maybe the problem is here, I will add it to the question.
    – TMat
    Apr 11, 2022 at 8:31

1 Answer 1


I found the answer to my question as indicated by JeanPierre the error was in my-org-html-export-to-html, I must replace 'html by 'my-html in org-export-to-file.

This solved my issue.

  • 1
    Still, you create a menu entry for exporting to buffer but it exports to file.
    – JeanPierre
    Apr 11, 2022 at 9:41
  • Yes you are right, a typo, in fact now I copied/pasted the rest and I can export either buffer or file. So it is corrected.
    – TMat
    Apr 11, 2022 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.