5

How can I disable inclusion of ids when exporting file as html

Say for example, in the following file I have disabled toc

#+TITLE: Using org-mode
#+HTML_DOCTYPE: html5
#+OPTIONS: toc:nil html-style:nil html-scripts:nil

* Where to start
** Let’s begin here

Now if I export it with M-x org-html-export-to-html, I get the following output:

...
<div id="outline-container-org0c7ecf1" class="outline-2">
  <h2 id="org0c7ecf1"><span class="section-number-2">1</span> Where to start</h2>
  <div class="outline-text-2" id="text-1">
  </div>
  <div id="outline-container-orga4a6d26" class="outline-3">
    <h3 id="orga4a6d26"><span class="section-number-3">1.1</span> Let’s begin here</h3>
  </div>
</div>
...

I would like to not add the id attribute at all unless a CUSTOM_ID property is set or toc is enabled.

These randomly generated ids break when regenerated and thus make it less useful as an id that can be linked from some other source.

As a side note, this results in unnecessary noise in commits (that's the primary reason I'm trying to avoid this).

  • I have the same problem here, then I dive into the org source code, the id is generated by org-export-new-reference and returned by org-export-get-reference, the latter function gets called many places in ox-html.el, and unfortunately, there is no even an option to change the behavior, so, it's quite hard to achieve this, what a tragedy... – Kelvin Hu May 30 '18 at 3:58
  • This is Emacs, you could just advise the function ( emacswiki.org/emacs/AdvisingFunctions ), or even redefine it. – Charl Botha Sep 9 '18 at 9:36
1

As others have said, it seems there is no out-of-the-box solution to this problem. Here is a hacky solution that uses an output filter and a regex to remove the id attributes from the final HTML output:

(defun html-body-id-filter (output backend info)
  "Remove random ID attributes generated by Org."
  (when (eq backend 'html)
    (replace-regexp-in-string
     " id=\"[[:alpha:]-]*org[[:alnum:]]\\{7\\}\""
     ""
     output t)))

(add-to-list 'org-export-filter-final-output-functions 'html-body-id-filter)
0

This can't be done out of the box, but there is a feature request for it at the Github repo: Feature request: More "Vanilla" HTML

  • It sounds like the answer is that it can't be done yet, but that there is a request for such a feature. If so, you might want to say that directly. – Drew Oct 10 '18 at 14:46
0

This isn't exactly what you asked for, but it does solve:

These randomly generated ids break when regenerated and thus make it less useful as an id that can be linked from some other source.

As a side note, this results in unnecessary noise in commits (that's the primary reason I'm trying to avoid this).

I was having the same problems, so I came up with this: https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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