* PATCH: Allow class attribute for headline in HTML export
@ 2018-12-02 18:25 Jens Lechtenboerger
2018-12-02 19:29 ` Jens Lechtenboerger
0 siblings, 1 reply; 8+ messages in thread
From: Jens Lechtenboerger @ 2018-12-02 18:25 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 224 bytes --]
Dear all,
the attached patch allows to add a class attribute to headline
elements in HTML export. Is that acceptable for inclusion?
Best wishes
Jens
P.S. The change is tiny, but I assigned copyright to the FSF in
2015.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html.el-New-property-HTML_HEADLINE_CLASS-for-clas.patch --]
[-- Type: text/x-diff, Size: 2476 bytes --]
From e8f16b04903bc32c4ea006727c82dbcb40b591a8 Mon Sep 17 00:00:00 2001
From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
Date: Sun, 2 Dec 2018 19:05:55 +0100
Subject: [PATCH] ox-html.el: New property HTML_HEADLINE_CLASS for class of
headline
* lisp/ox-html.el (org-html-headline): Add new property
HTML_HEADLINE_CLASS to assign class attribute to headline.
* doc/org-manual.org: Document new property HTML_HEADLINE_CLASS.
---
doc/org-manual.org | 6 +++++-
lisp/ox-html.el | 5 ++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 458e59a4a..9d14c4cdc 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -12780,7 +12780,11 @@ external file.
In order to add styles to a sub-tree, use the =HTML_CONTAINER_CLASS=
property to assign a class to the tree. In order to specify CSS
styles for a particular headline, you can use the ID specified in
-a =CUSTOM_ID= property.
+a =CUSTOM_ID= property or =HTML_HEADLINE_CLASS= as described next.
+
+#+cindex: @samp{HTML_HEADLINE_CLASS}, property
+In order to assign a class to a headline, use the =HTML_HEADLINE_CLASS=
+property.
Never change the ~org-html-style-default~ constant. Instead use other
simpler ways of customizing as described above.
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 6a81be126..d9d976753 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2608,6 +2608,7 @@ holding contextual information."
(format "</%s>\n" html-type))))
;; Standard headline. Export it as a section.
(let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
+ (headline-class (org-element-property :HTML_HEADLINE_CLASS headline))
(first-content (car (org-element-contents headline))))
(format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
(org-html--container headline info)
@@ -2616,9 +2617,11 @@ holding contextual information."
(concat (format "outline-%d" level)
(and extra-class " ")
extra-class)
- (format "\n<h%d id=\"%s\">%s</h%d>\n"
+ (format "\n<h%d id=\"%s\"%s>%s</h%d>\n"
level
id
+ (when headline-class
+ (format " class=\"%s\"" headline-class))
(concat
(and numberedp
(format
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-02 18:25 PATCH: Allow class attribute for headline in HTML export Jens Lechtenboerger
@ 2018-12-02 19:29 ` Jens Lechtenboerger
2018-12-02 20:20 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: Jens Lechtenboerger @ 2018-12-02 19:29 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 291 bytes --]
On 2018-12-02, at 19:25, Jens Lechtenboerger wrote:
> Dear all,
>
> the attached patch allows to add a class attribute to headline
> elements in HTML export. Is that acceptable for inclusion?
In that patch, "when" should have been "if", sorry. Fixed version
attached.
Best wishes
Jens
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html.el-New-property-HTML_HEADLINE_CLASS-for-clas.patch --]
[-- Type: text/x-diff, Size: 2489 bytes --]
From 068fb45f5276d61e86271988efbcf6c29e08c411 Mon Sep 17 00:00:00 2001
From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
Date: Sun, 2 Dec 2018 20:25:38 +0100
Subject: [PATCH] ox-html.el: New property HTML_HEADLINE_CLASS for class of
headline
* lisp/ox-html.el (org-html-headline): Add new property
HTML_HEADLINE_CLASS to assign class attribute to headline.
* doc/org-manual.org: Document new property HTML_HEADLINE_CLASS.
---
doc/org-manual.org | 6 +++++-
lisp/ox-html.el | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 458e59a4a..9d14c4cdc 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -12780,7 +12780,11 @@ external file.
In order to add styles to a sub-tree, use the =HTML_CONTAINER_CLASS=
property to assign a class to the tree. In order to specify CSS
styles for a particular headline, you can use the ID specified in
-a =CUSTOM_ID= property.
+a =CUSTOM_ID= property or =HTML_HEADLINE_CLASS= as described next.
+
+#+cindex: @samp{HTML_HEADLINE_CLASS}, property
+In order to assign a class to a headline, use the =HTML_HEADLINE_CLASS=
+property.
Never change the ~org-html-style-default~ constant. Instead use other
simpler ways of customizing as described above.
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 6a81be126..b043ab8fd 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2608,6 +2608,7 @@ holding contextual information."
(format "</%s>\n" html-type))))
;; Standard headline. Export it as a section.
(let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
+ (headline-class (org-element-property :HTML_HEADLINE_CLASS headline))
(first-content (car (org-element-contents headline))))
(format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
(org-html--container headline info)
@@ -2616,9 +2617,12 @@ holding contextual information."
(concat (format "outline-%d" level)
(and extra-class " ")
extra-class)
- (format "\n<h%d id=\"%s\">%s</h%d>\n"
+ (format "\n<h%d id=\"%s\"%s>%s</h%d>\n"
level
id
+ (if headline-class
+ (format " class=\"%s\"" headline-class)
+ "")
(concat
(and numberedp
(format
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-02 19:29 ` Jens Lechtenboerger
@ 2018-12-02 20:20 ` Nicolas Goaziou
2018-12-03 6:46 ` Jens Lechtenboerger
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2018-12-02 20:20 UTC (permalink / raw)
To: Jens Lechtenboerger; +Cc: emacs-orgmode
Hello,
Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
> From 068fb45f5276d61e86271988efbcf6c29e08c411 Mon Sep 17 00:00:00 2001
> From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
> Date: Sun, 2 Dec 2018 20:25:38 +0100
> Subject: [PATCH] ox-html.el: New property HTML_HEADLINE_CLASS for class of
> headline
Thank you.
> * lisp/ox-html.el (org-html-headline): Add new property
> HTML_HEADLINE_CLASS to assign class attribute to headline.
Doesn't CUSTOM_ID already fit the bill?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-02 20:20 ` Nicolas Goaziou
@ 2018-12-03 6:46 ` Jens Lechtenboerger
2018-12-04 10:21 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: Jens Lechtenboerger @ 2018-12-03 6:46 UTC (permalink / raw)
To: emacs-orgmode
On 2018-12-02, Nicolas Goaziou wrote:
> Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
>
>> From 068fb45f5276d61e86271988efbcf6c29e08c411 Mon Sep 17 00:00:00 2001
>> From: Jens Lechtenboerger <jens.lechtenboerger@fsfe.org>
>> Date: Sun, 2 Dec 2018 20:25:38 +0100
>> Subject: [PATCH] ox-html.el: New property HTML_HEADLINE_CLASS for class of
>> headline
>
> Thank you.
>
>> * lisp/ox-html.el (org-html-headline): Add new property
>> HTML_HEADLINE_CLASS to assign class attribute to headline.
>
> Doesn't CUSTOM_ID already fit the bill?
Good morning,
I plan to use that for a table-of-contents plugin [1] of reveal.js,
which looks for class attributes inside h-elements to exclude them
selectively.
Best wishes
Jens
[1] https://github.com/e-gor/Reveal.js-TOC-Progress
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-03 6:46 ` Jens Lechtenboerger
@ 2018-12-04 10:21 ` Nicolas Goaziou
2018-12-04 10:46 ` Jens Lechtenboerger
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2018-12-04 10:21 UTC (permalink / raw)
To: emacs-orgmode
Hello,
Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
> I plan to use that for a table-of-contents plugin [1] of reveal.js,
> which looks for class attributes inside h-elements to exclude them
> selectively.
Then I suggest to submit it to "ox-reveal"
(https://github.com/yjwen/org-reveal/) instead.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-04 10:21 ` Nicolas Goaziou
@ 2018-12-04 10:46 ` Jens Lechtenboerger
2018-12-08 11:46 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: Jens Lechtenboerger @ 2018-12-04 10:46 UTC (permalink / raw)
To: emacs-orgmode
Hello,
On 2018-12-04, Nicolas Goaziou wrote:
> Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
>
>> I plan to use that for a table-of-contents plugin [1] of reveal.js,
>> which looks for class attributes inside h-elements to exclude them
>> selectively.
>
> Then I suggest to submit it to "ox-reveal"
> (https://github.com/yjwen/org-reveal/) instead.
Function org-reveal-headline calls org-html-headline to generate
h-elements. Of course, I could parse the generated HTML in
ox-reveal and add a class attribute based on org properties, but
doing so in ox-html seems much cleaner to me. (Besides, given the
current situation of ox-reveal [1], that change would only make it
into my fork, not into the original project.)
Best wishes
Jens
[1] https://github.com/yjwen/org-reveal/issues/349
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-04 10:46 ` Jens Lechtenboerger
@ 2018-12-08 11:46 ` Nicolas Goaziou
2018-12-08 15:04 ` Jens Lechtenboerger
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2018-12-08 11:46 UTC (permalink / raw)
To: emacs-orgmode
Hello,
Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
> Function org-reveal-headline calls org-html-headline to generate
> h-elements. Of course, I could parse the generated HTML in
> ox-reveal and add a class attribute based on org properties, but
> doing so in ox-html seems much cleaner to me. (Besides, given the
> current situation of ox-reveal [1], that change would only make it
> into my fork, not into the original project.)
Fair enough. I applied your patch on "next" branch.
Thank you!
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Allow class attribute for headline in HTML export
2018-12-08 11:46 ` Nicolas Goaziou
@ 2018-12-08 15:04 ` Jens Lechtenboerger
0 siblings, 0 replies; 8+ messages in thread
From: Jens Lechtenboerger @ 2018-12-08 15:04 UTC (permalink / raw)
To: emacs-orgmode
Hello!
On 2018-12-08, at 12:46, Nicolas Goaziou wrote:
> Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
>
>> Function org-reveal-headline calls org-html-headline to generate
>> h-elements. Of course, I could parse the generated HTML in
>> ox-reveal and add a class attribute based on org properties, but
>> doing so in ox-html seems much cleaner to me. (Besides, given the
>> current situation of ox-reveal [1], that change would only make it
>> into my fork, not into the original project.)
>
> Fair enough. I applied your patch on "next" branch.
Thank you, I really appreciate this change!
Best wishes
Jens
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-12-08 15:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-02 18:25 PATCH: Allow class attribute for headline in HTML export Jens Lechtenboerger
2018-12-02 19:29 ` Jens Lechtenboerger
2018-12-02 20:20 ` Nicolas Goaziou
2018-12-03 6:46 ` Jens Lechtenboerger
2018-12-04 10:21 ` Nicolas Goaziou
2018-12-04 10:46 ` Jens Lechtenboerger
2018-12-08 11:46 ` Nicolas Goaziou
2018-12-08 15:04 ` Jens Lechtenboerger
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).