Hello,

Attached to this e-mail you could find a small patch for the HTML export
backend.

This patch add an in-file option for enabling headlines self link.


# Motivation

Until now, to add a self link on each headline in the HTML export, user
needed to set the variable `org-html-self-link-headlines' to a non-nil
value.

While I was writing some documentation in 1 org-mode file, I needed to
have headline with self links. But I doesn't wanted to set this option
for all my org-mode export. Or use org-publish for 1 file. I could set
the variable locally to my buffer, but I found it more elegant to have
an Org-mode file level option for it.

Now, to enable self link in headline, user only need to add this to
their Org-mode file:

    #+options: html-self-link-headlines:nil


Also, I wanted to familiarize myself the Org html export backend and
patch submission before doing anything more ambitious.


Best regards

-------
Gendre Sébastien


From 9e7eddf1a7da640a1a9d4ff9d2ac66c8c870c01d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gendre?= <s...@k-7.ch>
Date: Fri, 18 Apr 2025 18:18:12 +0200
Subject: [PATCH] lisp/ox-html.el: Add file level option to manage headlines
 self link

* lisp/ox-html.el (html): In the backend options-alist, add an OPTION
name to the option key `:html-self-link-headlines'.  The new OPITON
name is `html-self-link-headlines'.

* doc/org-manual.org (Headlines in HTML export): Update this manual
section to talk about the new file level option
`html-self-link-headlines'.  Rewrite the paragraph.

* etc/ORG-NEWS (New and changed options): Add a sub-section to talk
about the new file level option `html-self-link-headlines'.

TINYCHANGE
---
 doc/org-manual.org | 14 +++++++++++---
 etc/ORG-NEWS       | 10 ++++++++++
 lisp/ox-html.el    |  2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 360260149..9f67131f4 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -13617,9 +13617,17 @@ Headlines are exported to =<h1>=, =<h2>=, etc.  Each headline gets the
 see [[*Internal Links]].
 
 #+vindex: org-html-self-link-headlines
-When ~org-html-self-link-headlines~ is set to a non-~nil~ value, the
-text of the headlines is also wrapped in =<a>= tags.  These tags have
-a =href= attribute making the headlines link to themselves.
+Headlines can contain a link to themselves. To enable it, you have 2 ways:
+
+- Set the variable ~org-html-self-link-headlines~ to a non-~nil~ value
+- In an org-mode file, use an =OPTIONS= line to set
+  =html-self-link-headlines= to a non-~nil~ value
+
+
+#+texinfo: @noindent
+When enabled, the text of the headlines is wrapped in =<a>= tags.
+These tags have a =href= attribute making the headlines link to
+themselves.
 
 *** Links in HTML export
 :PROPERTIES:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 982bac4e9..cd6e05985 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -313,6 +313,16 @@ slide to specific animation steps.
 This text will be displayed on animation step 2 and later.
 #+END_SRC
 
+*** ox-html: Headline self links can be enabled from an Org-mode file
+
+Previously HTML export could add, to each headline, a link to itself.
+To enable it, you had to use the variable
+~org-html-self-link-headlines~.
+
+Now, it's also possible to enable it per Org-mode file.  By adding
+~html-self-link-headlines:t~ to =#+OPTION=.
+
+
 *** ox-latex: Table of contents generation has been fixed and augmented
 
 The LaTeX exporter differs from other exporters in that it *does not*
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 2f4ec12e2..026a93735 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -161,7 +161,7 @@
     (:html-postamble-format nil nil org-html-postamble-format)
     (:html-preamble-format nil nil org-html-preamble-format)
     (:html-prefer-user-labels nil nil org-html-prefer-user-labels)
-    (:html-self-link-headlines nil nil org-html-self-link-headlines)
+    (:html-self-link-headlines nil "html-self-link-headlines" org-html-self-link-headlines)
     (:html-table-align-individual-fields
      nil nil org-html-table-align-individual-fields)
     (:html-table-caption-above nil nil org-html-table-caption-above)
-- 
2.49.0

Attachment: signature.asc
Description: PGP signature

Reply via email to