10

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).

Mohammed Sadiq
  • 261
  • 2
  • 8
  • 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 03:58
  • This is Emacs, you could just advise the function ( https://www.emacswiki.org/emacs/AdvisingFunctions ), or even redefine it. – Charl Botha Sep 09 '18 at 09:36

3 Answers3

2

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

2

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:

(require 'ox-md)
(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)
mlee
  • 3
  • 2
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

passionsplay
  • 101
  • 2
  • 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
  • 2
    The linked issue is for `org2blog` and *not* Org. Has the issue been raised with the Org developers? – Lorem Ipsum Jul 16 '20 at 13:01