0

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))))
         (section-number
          (and (org-export-numbered-headline-p parent info)
           (mapconcat
            #'number-to-string
            (org-export-get-headline-number parent info) "-"))))
        ;; Build return value.
    (format "%s"
        (or contents ""))))))

;;;###autoload
(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."
  (interactive)
  (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
                    org-html-extension
                    "html")))
     (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.

2
  • 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

0

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.

2
  • 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 that you have read and understand our privacy policy and code of conduct.

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