Closed tkyobc closed 8 years ago
@larstvei friendly ping -- it'd be great to see this in master 😄
Thanks @jkrmr. I didn't really understand what this did the last time I looked at it, so forgot about it. Please provide a minimal example with pull requests @tkyobc, that makes them easier to accept.
I think I get the basic issue now, but have one question: Does ox-md.el
suffer from the same problem?
My main concern is that this is basically a large copy-paste from ox-md.el
, which ox-gfm.el
is derived from, where just one function call is changed. Wouldn't it be better to achieve this by changing ox-md.el
? I'm guessing it has more users and is better maintained, so it would be good for ox-gfm.el
to piggyback future enhancements to ox-md.el
.
@larstvei Sorry, I should have taken a look at the implementation. I think this could be fixed with a few characters.
The plugin generates a TOC with IDs as follows:
- [Motivation](#sec-1)
- [Scenarios](#sec-2)
- [Prior art](#sec-3)
- [Tasks](#sec-4)
- [Implementation notes](#sec-5)
# Motivation<a id="orgheadline1"></a>
What we'd want in order for them to work as expected is
- [Motivation](#orgheadline1)
- [Scenarios](#orgheadline2)
- [Prior art](#orgheadline3)
- [Tasks](#orgheadline4)
- [Implementation notes](#orgheadline5)
# Motivation<a id="orgheadline1"></a>
(Or, alternatively, for all IDs to be normalized on the sec-
pattern instead of the orgheadline
one, although that approach seems like it would take more work. I believe that's the approach this PR takes.)
I think the following would suffice for the less invasive approach:
;; layers/org/extensions/ox-gfm/ox-gfm.el L90-L101
(defun org-gfm-format-toc (headline)
"Return an appropriate table of contents entry for HEADLINE. INFO is a
plist used as a communication channel."
(let* ((title (org-export-data
(org-export-get-alt-title headline info) info))
(level (1- (org-element-property :level headline)))
(indent (concat (make-string (* level 2) ? )))
(anchor (or (org-element-property :custom_id headline)
- (concat "sec-" (mapconcat 'number-to-string
+ (concat "orgheadline" (mapconcat 'number-to-string
(org-export-get-headline-number
headline info) "-")))))
(concat indent "- [" title "]" "(#" anchor ")")))
Unless I'm misunderstanding the issue?
Good idea, but it it doesn't seem to work with nested structures.
For instance, this:
* h1
** test1
* h2
*** test2
* h3
exports to this:
- [h1](#sec-1)
- [test1](#sec-1-1)
- [h2](#sec-2)
- [test2](#sec-2-0-1)
- [h3](#sec-3)
# h1<a id="orgheadline2"></a>
## test1<a id="orgheadline1"></a>
# h2<a id="orgheadline4"></a>
### test2<a id="orgheadline3"></a>
# h3<a id="orgheadline5"></a>
In addition, i think newer versions of org mode enumerates the id's completely different.
I'll see if I can find a way to simplify the implementation, if not I'll include the change from @tkyobc .
As far as I can tell commit 32dd362 fixes this. Tested it a couple of versions of org, both work fine.
The example above exports to:
- [h1](#orgheadline2)
- [test1](#orgheadline1)
- [h2](#orgheadline4)
- [test2](#orgheadline3)
- [h3](#orgheadline5)
# h1<a id="orgheadline2"></a>
## test1<a id="orgheadline1"></a>
# h2<a id="orgheadline4"></a>
### test2<a id="orgheadline3"></a>
# h3<a id="orgheadline5"></a>
I fixed the problem that different IDs are appended to a table of contents and headlines. If this fix is applied, links in a table of contents become to work well.
Please check it.