* [PATCH] lisp/ox-html.el: Move the space after exported section number
@ 2021-05-03 15:07 Mingkai Dong
2021-05-03 15:31 ` Bastien
0 siblings, 1 reply; 4+ messages in thread
From: Mingkai Dong @ 2021-05-03 15:07 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Mingkai Dong
* ox-html.el (org-html-headline, org-html-format-headline-default-function):
delete the space after the section number span format and add it back in
org-html-format-headline-default-function.
The requirement is well described in the reddit post
https://www.reddit.com/r/emacs/comments/bv8rli/org_mode_export_section_numbering/
which can be solved by setting the org-html-format-headline-function
variable to a custom function that adds the "." before the section title.
However, this results in something like "1 . Fist-Section-Title", rather
than "1. First-Section-Title", because of the extra space after the <span>
format. Moving the space to org-html-format-headline-default-function preserves
existing export behavior while allowing the users to better control the format.
---
lisp/ox-html.el | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 89da823e8..f2ce71f68 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2676,7 +2676,7 @@ holding contextual information."
(concat
(and numberedp
(format
- "<span class=\"section-number-%d\">%s</span> "
+ "<span class=\"section-number-%d\">%s</span>"
level
(mapconcat #'number-to-string numbers ".")))
formatted-text)
@@ -2696,7 +2696,8 @@ See `org-html-format-headline-function' for details."
(let ((todo (org-html--todo todo info))
(priority (org-html--priority priority info))
(tags (org-html--tags tags info)))
- (concat todo (and todo " ")
+ (concat " "
+ todo (and todo " ")
priority (and priority " ")
text
(and tags "   ") tags)))
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] lisp/ox-html.el: Move the space after exported section number
2021-05-03 15:07 [PATCH] lisp/ox-html.el: Move the space after exported section number Mingkai Dong
@ 2021-05-03 15:31 ` Bastien
2021-05-03 16:35 ` Mingkai Dong
0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2021-05-03 15:31 UTC (permalink / raw)
To: Mingkai Dong; +Cc: emacs-orgmode
Hi Mingkai,
Mingkai Dong <mk@dong.mk> writes:
> * ox-html.el (org-html-headline, org-html-format-headline-default-function):
> delete the space after the section number span format and add it back in
> org-html-format-headline-default-function.
It looks good, thanks.
Can you show the exact difference by comparing the relevant HTML
portion before and after this change?
--
Bastien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lisp/ox-html.el: Move the space after exported section number
2021-05-03 15:31 ` Bastien
@ 2021-05-03 16:35 ` Mingkai Dong
2021-05-03 17:19 ` Bastien
0 siblings, 1 reply; 4+ messages in thread
From: Mingkai Dong @ 2021-05-03 16:35 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
Hi Bastien,
At the end of the mail is the output of `diff old.html new.html`, most
differences are caused by time and randomly generated ids.
The only exception is the Table-of-Content entries, which now has two
spaces before each section title. I find that the org-html--format-toc-headline
function first appends “. “ after each section number, and then appends
the output of html-format-headline-default-function. Thus, after moving
the space to the head of html-format-headline-default-function, there are
two spaces.
Then the problem becomes more complicated, and it might be difficult to solve
it without changing the original behavior.
I can come up with three options:
1. Stay with the two spaces in ToC, since extra spaces seldom change the
appearance of rendered html. But it would cause problems when users use
custom org-html-format-headline-function.
2. Further modify the org-html--format-toc-headline function to remove
the logic of appending “. “ as below. Then the section heading in both
the text and the ToC will have the format of “1 Section-Text”, without
“.”. However, this changes the original appearance of ToC.
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index f2ce71f68..a17445ca5 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2396,8 +2396,7 @@ INFO is a plist used as a communication channel."
(concat
(and (not (org-export-low-level-p headline info))
(org-export-numbered-headline-p headline info)
- (concat (mapconcat #'number-to-string headline-number ".")
- ". "))
+ (mapconcat #'number-to-string headline-number "."))
(apply (plist-get info :html-format-headline-function)
todo todo-type priority text tags :section-number nil)))))
3. Based on the second solution, further update the org-html-format-headline-default-function
to append “. “ by default (rather than “ “) like below. This keeps the
original ToC content unchanged, but changes the default in-text section
heading format by appending one more “.” after the section number.
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index f2ce71f68..84da95ddb 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2396,8 +2396,7 @@ INFO is a plist used as a communication channel."
(concat
(and (not (org-export-low-level-p headline info))
(org-export-numbered-headline-p headline info)
- (concat (mapconcat #'number-to-string headline-number ".")
- ". "))
+ (mapconcat #'number-to-string headline-number "."))
(apply (plist-get info :html-format-headline-function)
todo todo-type priority text tags :section-number nil)))))
@@ -2696,7 +2695,7 @@ See `org-html-format-headline-function' for details."
(let ((todo (org-html--todo todo info))
(priority (org-html--priority priority info))
(tags (org-html--tags tags info)))
- (concat " "
+ (concat ". "
todo (and todo " ")
priority (and priority " ")
text
Both option 2 and 3 give users better control over of the section heading
format, but will alter the current behavior of html export.
What do you think?
- - - - Below is the diff of generated HTML - - - -
4c4
< <!-- 2021-05-03 Mon 23:53 -->
---
> <!-- 2021-05-03 Mon 23:56 -->
228,231c228,231
< <li><a href="#orgc72e91c">1. Terms</a></li>
< <li><a href="#org8c55297">2. TME</a></li>
< <li><a href="#orga4a3735">3. MKTME</a></li>
< <li><a href="#org822b2db">4. Configuration</a>
---
> <li><a href="#org329df72">1. Terms</a></li>
> <li><a href="#org870abfd">2. TME</a></li>
> <li><a href="#orgcb05acd">3. MKTME</a></li>
> <li><a href="#org48f2f09">4. Configuration</a>
233c233
< <li><a href="#org47ff03e">4.1. Exclusion Range MSRs</a></li>
---
> <li><a href="#orgcd598c6">4.1. Exclusion Range MSRs</a></li>
236,237c236,237
< <li><a href="#org463c0b8">5. Runtime Behavior</a></li>
< <li><a href="#org665a598">6. 管理 KeyID</a>
---
> <li><a href="#org993a386">5. Runtime Behavior</a></li>
> <li><a href="#org1b5b5c2">6. 管理 KeyID</a>
239c239
< <li><a href="#org48b1087">6.1. Guidance</a></li>
---
> <li><a href="#org8ebed26">6.1. Guidance</a></li>
254,255c254,255
< <div id="outline-container-orgc72e91c" class="outline-2">
< <h2 id="orgc72e91c"><span class="section-number-2">1</span> Terms</h2>
---
> <div id="outline-container-org329df72" class="outline-2">
> <h2 id="org329df72"><span class="section-number-2">1</span> Terms</h2>
264,265c264,265
< <div id="outline-container-org8c55297" class="outline-2">
< <h2 id="org8c55297"><span class="section-number-2">2</span> TME</h2>
---
> <div id="outline-container-org870abfd" class="outline-2">
> <h2 id="org870abfd"><span class="section-number-2">2</span> TME</h2>
276c276
< <figure id="org79fe63c">
---
> <figure id="org111b265">
289,290c289,290
< <div id="outline-container-orga4a3735" class="outline-2">
< <h2 id="orga4a3735"><span class="section-number-2">3</span> MKTME</h2>
---
> <div id="outline-container-orgcb05acd" class="outline-2">
> <h2 id="orgcb05acd"><span class="section-number-2">3</span> MKTME</h2>
308c308
< <figure id="orga12c576">
---
> <figure id="orgd6d7e27">
326,327c326,327
< <div id="outline-container-org822b2db" class="outline-2">
< <h2 id="org822b2db"><span class="section-number-2">4</span> Configuration</h2>
---
> <div id="outline-container-org48f2f09" class="outline-2">
> <h2 id="org48f2f09"><span class="section-number-2">4</span> Configuration</h2>
334,335c334,335
< <div id="outline-container-org47ff03e" class="outline-3">
< <h3 id="org47ff03e"><span class="section-number-3">4.1</span> Exclusion Range MSRs</h3>
---
> <div id="outline-container-orgcd598c6" class="outline-3">
> <h3 id="orgcd598c6"><span class="section-number-3">4.1</span> Exclusion Range MSRs</h3>
356,357c356,357
< <div id="outline-container-org463c0b8" class="outline-2">
< <h2 id="org463c0b8"><span class="section-number-2">5</span> Runtime Behavior</h2>
---
> <div id="outline-container-org993a386" class="outline-2">
> <h2 id="org993a386"><span class="section-number-2">5</span> Runtime Behavior</h2>
364c364
< <figure id="orgccdf090">
---
> <figure id="org27b7774">
390,391c390,391
< <div id="outline-container-org665a598" class="outline-2">
< <h2 id="org665a598"><span class="section-number-2">6</span> 管理 KeyID</h2>
---
> <div id="outline-container-org1b5b5c2" class="outline-2">
> <h2 id="org1b5b5c2"><span class="section-number-2">6</span> 管理 KeyID</h2>
400,401c400,401
< <div id="outline-container-org48b1087" class="outline-3">
< <h3 id="org48b1087"><span class="section-number-3">6.1</span> Guidance</h3>
---
> <div id="outline-container-org8ebed26" class="outline-3">
> <h3 id="org8ebed26"><span class="section-number-3">6.1</span> Guidance</h3>
418c418
< <p class="date">Created: 2021-05-03 Mon 23:53</p>
---
> <p class="date">Created: 2021-05-03 Mon 23:56</p>
Best,
Mingkai
> On May 3, 2021, at 23:31, Bastien <bzg@gnu.org> wrote:
>
> Hi Mingkai,
>
> Mingkai Dong <mk@dong.mk> writes:
>
>> * ox-html.el (org-html-headline, org-html-format-headline-default-function):
>> delete the space after the section number span format and add it back in
>> org-html-format-headline-default-function.
>
> It looks good, thanks.
>
> Can you show the exact difference by comparing the relevant HTML
> portion before and after this change?
>
> --
> Bastien
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] lisp/ox-html.el: Move the space after exported section number
2021-05-03 16:35 ` Mingkai Dong
@ 2021-05-03 17:19 ` Bastien
0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2021-05-03 17:19 UTC (permalink / raw)
To: Mingkai Dong; +Cc: emacs-orgmode
Hi Mingkai,
thanks a lot for the analysis and the diff, it helps a lot.
I pushed this change:
https://code.orgmode.org/bzg/org-mode/commit/dfdd5cd0
Keeping the headline numbering consistent with the TOC numbering seems
the right thing to do here.
Thanks!
--
Bastien
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-03 17:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-03 15:07 [PATCH] lisp/ox-html.el: Move the space after exported section number Mingkai Dong
2021-05-03 15:31 ` Bastien
2021-05-03 16:35 ` Mingkai Dong
2021-05-03 17:19 ` Bastien
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).