Closed clsty closed 2 months ago
Hello, that's a known behavior. The only solution right now is that you set :CUSTOM_ID:
uniquely for the duplicate heading. The general usecase envisioned was that it would be uncommon to have identical subheading on the same blog post, so any complicated solutions were not investigated for this.
The general usecase envisioned was that it would be uncommon to have identical subheading on the same blog post, so any complicated solutions were not investigated for this.
That is actually common for me, such as (just an example below, not real)
I've tried three well-known editors. Which one is the best? Just proceed reading.
## Emacs
### Basic info
...
### Package system
...
## Vim
### Basic info
...
### Package system
...
## VSCodium
### Basic info
...
### Package system
...
But how about other users? I don't know, maybe you're right.
However, I do hope that user is allowed to disable this auto-add-anchor behavior optionally. (I know that in such case some features like cross referencing may not work, that's OK, I'll use feature from Hugo to do that.)
One another reason is that, when I directly write the Markdown files, with same headings on one page without any anchors, the links on the generated HTML are automatically renamed to avoid duplicating, like #foo-1
#foo-2
.
Since ox-hugo
can not handle this auto-renaming, and Hugo (with the theme I'm using) can handle it, it's reasonable to allow user disable it on side of ox-hugo, and leave it to Hugo (with the theme they're using), right?
Can you try adding this to your emacs setup? This code forces the anchor to be an empty string ""
.
(defun my/org-hugo--heading-title--no-anchor (&rest args)
"Force ANCHOR arg of `org-hugo--heading-title' to be an empty string.
List of `org-hugo--heading-title' args:
style level loffset title todo tags anchor numbers
0 1 2 3 4 5 6
"
(let ((empty-anchor ""))
(setf (nth 6 (car args)) empty-anchor))
(car args))
(advice-add 'org-hugo--heading-title :filter-args #'my/org-hugo--heading-title--no-anchor)
After evaluating this code, your example code will export to:
## a
### foo
## b
### foo
Note: This might result in a case where your Org link navigation works in Emacs, but they won't work in the Hugo generated HTML.
To remove the advice:
(advice-remove 'org-hugo--heading-title #'my/org-hugo--heading-title--no-anchor)
Thanks a lot, this works just as you said.
I'm using the latest git version of ox-hugo.
Actual Behavior
In
ox-hugo.el
:By default, the value here of the
anchor
is always the same (I know it by checking the exported markdown file), only if same heading on one page, which cause duplicated anchors.Expected Behavior
Auto rename the anchor, e.g. detect if anchor
foo
already exists, if yes, then rename the anchor tofoo-1
; detect again iffoo-1
exists, if yes, then rename the anchor tofoo-2
; detect again... untilfoo-n
does not exists, then usefoo-n
.Allow disabling this auto-add-anchor behavior. This will be especially helpful because the Hugo theme I'm using also support attribute for headings, e.g.
will rendered as a highlighted heading; but the auto added anchor
{#foo}
prevent this from functioning.How to Reproduce the Issue
Example Org File
Generated Markdown File or Error
The two
{#foo}
cause conflict.