Re: [O] [PATCH] Suggestion to self-link headlines exported to HTML
Hello, Toon Claes writes: > Thanks Nicolas for taking time to have look at my patch. > > I'm a attaching a second version of the patch. Please have another > look. I applied your patch to master, with a few changes to markup syntax in manual. Thank you! Regards, -- Nicolas Goaziou
Re: [O] [PATCH] Suggestion to self-link headlines exported to HTML
Thanks Nicolas for taking time to have look at my patch. I'm a attaching a second version of the patch. Please have another look. -- Toon From 094576d4c082fc384aa56bf2f4ec2749fec540a7 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Sun, 16 Dec 2018 21:55:40 +0100 Subject: [PATCH] ox-html: Make it possible to self link headlines * lisp/ox-html.el (org-html-self-link-headlines): New variable. (org-html-headline): Create a hyperlink on headlines when :html-self-link-headlines is set. --- doc/org-manual.org | 16 etc/ORG-NEWS | 5 + lisp/ox-html.el| 18 +++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 59e31d8b3..884975d8f 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -12495,6 +12495,21 @@ For larger raw HTML code blocks, use these HTML export code blocks: ,#+END_EXPORT #+end_example +*** Headlines in HTML export +:PROPERTIES: +:DESCRIPTION: Formatting headlines. +:END: +#+cindex: headlines, in HTML export + +Headlines are exported to ~~, ~~, etc. Each headline will get +the ~id~ attribute from =CUSTOM_ID= property, or a unique generated +value, 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 ~~ tags. These tags have +a ~href~ attribute making the headlines link to the headline itself. + *** Links in HTML export :PROPERTIES: :DESCRIPTION: Inserting and formatting links. @@ -15610,6 +15625,7 @@ Settings]]), however, override everything. | ~:html-postamble~ | ~org-html-postamble~ | | ~:html-preamble-format~| ~org-html-preamble-format~| | ~:html-preamble~ | ~org-html-preamble~ | +| ~:html-self-link-headlines~| ~org-html-self-link-headlines~| | ~:html-table-align-individual-field~ | ~de{org-html-table-align-individual-fields~ | | ~:html-table-attributes~ | ~org-html-table-default-attributes~ | | ~:html-table-caption-above~| ~org-html-table-caption-above~| diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 811e98147..817d6eacc 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -312,6 +312,11 @@ beginning of a headline when using Org speed commands. Now, if there is already a restriction at point, hitting =<= again (or =C-x C-x <=) will remove it. +*** Headlines can now link to themselves in HTML export + +When enabling ~org-html-self-link-headlines~ the headlines exported to +HTML contain a hyperlink to themselves. + ** New commands and functions *** ~org-insert-structure-template~ diff --git a/lisp/ox-html.el b/lisp/ox-html.el index b4ec25786..728e156f1 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -152,6 +152,7 @@ (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format) (:html-postamble-format nil nil org-html-postamble-format) (:html-preamble-format nil nil org-html-preamble-format) +(:html-self-link-headlines nil nil 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) @@ -802,6 +803,13 @@ but without \"name\" attribute." :package-version '(Org . "8.0") :type 'boolean) +(defcustom org-html-self-link-headlines nil + "When non-nil, the headlines contain a hyperlink to themselves." + :group 'org-export-html + :package-version '(Org . "9.3") + :type 'boolean + :safe #'booleanp) + Inlinetasks (defcustom org-html-format-inlinetask-function @@ -2592,7 +2600,11 @@ holding contextual information." todo todo-type priority text tags info)) (contents (or contents "")) (id (or (org-element-property :CUSTOM_ID headline) - (org-export-get-reference headline info + (org-export-get-reference headline info))) + (formatted-text + (if (plist-get info :html-self-link-headlines) + (format "%s" id full-text) + full-text))) (if (org-export-low-level-p headline info) ;; This is a deep sub-tree: export it as a list item. (let* ((html-type (if numberedp "ol" "ul"))) @@ -2603,7 +2615,7 @@ holding contextual information." (org-html-format-list-item contents (if numberedp 'ordered 'unordered) nil info nil - (concat (org-html--anchor id nil nil info) full-text)) "\n" + (concat (org-html--anchor id nil nil info) formatted-text)) "\n" (and (org-export-last-sibling-p headline info) (format "\n" html-type ;; Standard headline. Export it as a section. @@ -2625,7 +2637,7 @@ holding contextual information."
Re: [O] [PATCH] Suggestion to self-link headlines exported to HTML
Hello, Toon Claes writes: > Recently I wrote a blog post on making headlines clickable when Org mode > is exported to HTML: > https://writepermission.com/org-blogging-clickable-headlines.html > > With this mail, I'd like to suggest a change to bring this feature to > the Org mode core. > > It's my first contribution to Org mode, but I've already completed the > paperwork to contribute to Emacs core in the past. > > Of course any comment is welcome. Thank you. Comments, indeed, follow :) > | ~:html-postamble~ | ~org-html-postamble~ > | > | ~:html-preamble-format~| > ~org-html-preamble-format~| > | ~:html-preamble~ | ~org-html-preamble~ > | > +| ~:html-self-link-headlines~| > ~org-html-self-link-headlines~| > | ~:html-table-align-individual-field~ | > ~de{org-html-table-align-individual-fields~ | > | ~:html-table-attributes~ | > ~org-html-table-default-attributes~ | > | ~:html-table-caption-above~| > ~org-html-table-caption-above~| Could this also be documented somewhere in "HTML Export" section of the manual? > +(defcustom org-html-self-link-headlines nil > + "When set, the headlines contain a hyperlink to themselves." When non-nil, ... > + :group 'org-export-html > + :version "27.1" No need for :version keyword if :package-version is provided. > + :package-version '(Org . "9.2") It should be "9.3" actually, since 9.2 is feature-freeze. > + :type 'boolean) Please also add :safe #'booleanp > Inlinetasks > > (defcustom org-html-format-inlinetask-function > @@ -2592,7 +2600,11 @@ holding contextual information." > todo todo-type priority text tags info)) > (contents (or contents "")) > (id (or (org-element-property :CUSTOM_ID headline) > -(org-export-get-reference headline info > +(org-export-get-reference headline info))) > +(formatted-text > + (if (and id (plist-get info :html-self-link-headlines)) `id' cannot be nil, so you only need (plist-get ...) > + (format "%s" id full-text) > + text))) Why `text' and not `full-text' as a fall-back? Regards, -- Nicolas Goaziou
[O] [PATCH] Suggestion to self-link headlines exported to HTML
Hi, Recently I wrote a blog post on making headlines clickable when Org mode is exported to HTML: https://writepermission.com/org-blogging-clickable-headlines.html With this mail, I'd like to suggest a change to bring this feature to the Org mode core. It's my first contribution to Org mode, but I've already completed the paperwork to contribute to Emacs core in the past. Of course any comment is welcome. -- Toon From 5b279778326d844b6dd2895dba7eae2c096056cc Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Sun, 16 Dec 2018 21:55:40 +0100 Subject: [PATCH] ox-html: Make it possible to self link headlines * lisp/ox-html.el (org-html-self-link-headlines): New variable. (org-html-headline): Create a hyperlink on headlines when :html-self-link-headlines is set. --- doc/org-manual.org | 1 + etc/ORG-NEWS | 5 + lisp/ox-html.el| 18 +++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 59e31d8b3..4f00655fa 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -15610,6 +15610,7 @@ Settings]]), however, override everything. | ~:html-postamble~ | ~org-html-postamble~ | | ~:html-preamble-format~| ~org-html-preamble-format~| | ~:html-preamble~ | ~org-html-preamble~ | +| ~:html-self-link-headlines~| ~org-html-self-link-headlines~| | ~:html-table-align-individual-field~ | ~de{org-html-table-align-individual-fields~ | | ~:html-table-attributes~ | ~org-html-table-default-attributes~ | | ~:html-table-caption-above~| ~org-html-table-caption-above~| diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 811e98147..817d6eacc 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -312,6 +312,11 @@ beginning of a headline when using Org speed commands. Now, if there is already a restriction at point, hitting =<= again (or =C-x C-x <=) will remove it. +*** Headlines can now link to themselves in HTML export + +When enabling ~org-html-self-link-headlines~ the headlines exported to +HTML contain a hyperlink to themselves. + ** New commands and functions *** ~org-insert-structure-template~ diff --git a/lisp/ox-html.el b/lisp/ox-html.el index b4ec25786..826d97a5d 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -152,6 +152,7 @@ (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format) (:html-postamble-format nil nil org-html-postamble-format) (:html-preamble-format nil nil org-html-preamble-format) +(:html-self-link-headlines nil nil 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) @@ -802,6 +803,13 @@ but without \"name\" attribute." :package-version '(Org . "8.0") :type 'boolean) +(defcustom org-html-self-link-headlines nil + "When set, the headlines contain a hyperlink to themselves." + :group 'org-export-html + :version "27.1" + :package-version '(Org . "9.2") + :type 'boolean) + Inlinetasks (defcustom org-html-format-inlinetask-function @@ -2592,7 +2600,11 @@ holding contextual information." todo todo-type priority text tags info)) (contents (or contents "")) (id (or (org-element-property :CUSTOM_ID headline) - (org-export-get-reference headline info + (org-export-get-reference headline info))) + (formatted-text + (if (and id (plist-get info :html-self-link-headlines)) + (format "%s" id full-text) + text))) (if (org-export-low-level-p headline info) ;; This is a deep sub-tree: export it as a list item. (let* ((html-type (if numberedp "ol" "ul"))) @@ -2603,7 +2615,7 @@ holding contextual information." (org-html-format-list-item contents (if numberedp 'ordered 'unordered) nil info nil - (concat (org-html--anchor id nil nil info) full-text)) "\n" + (concat (org-html--anchor id nil nil info) formatted-text)) "\n" (and (org-export-last-sibling-p headline info) (format "\n" html-type ;; Standard headline. Export it as a section. @@ -2625,7 +2637,7 @@ holding contextual information." "%s " level (mapconcat #'number-to-string numbers "."))) - full-text) + formatted-text) level) ;; When there is no section, pretend there is an ;; empty one to get the correct signature.asc Description: PGP signature