Open dmitryperets opened 3 years ago
Hello, can you show your command to compile this file? It could help me to reproduce this problem.
Hi,
Suppose you have the three files that I've shown in the description (10-chapter1.md
, 20-chapter2.md
and the actual source markdown file called include-test.md
), you can reproduce the problem as follows:
% cat include-test.md
---
title: Testing Implicit References
---
!include 10-chapter1.md
!include 20-chapter2.md
% pandoc --filter pandoc-include -o include-test.html include-test.md
% cat include-test.html
<p>[This is Header]</p>
<p>[Link][This is Header]</p>
<p><a href="#this-is-header">Explicit Link</a></p>
<h1 id="this-is-header">This is Header</h1>
Hi, I tried to swap the two files but the issue still exists. Is it the same on your PC?
Hmm yes, you are right... something confused me before, I thought I saw it working when the referenced item was included before the reference. Maybe I tested on a different environment, not sure.
So now it looks like pandoc-include doesn't allow implicit references at all.
This is how it works without pandoc-include:
% cat include-test.md
---
title: Testing Implicit References
---
# This is Header
[This is Header]
[Link][This is Header]
[Explicit Link](#this-is-header)
% pandoc --filter pandoc-include -o include-test.html include-test.md
% cat include-test.html
<h1 id="this-is-header">This is Header</h1>
<p><a href="#this-is-header">This is Header</a></p>
<p><a href="#this-is-header">Link</a></p>
<p><a href="#this-is-header">Explicit Link</a></p>
This feature is not supported in pandoc-include because pandoc-include processes every file independently before merging them into one file.
But pandoc renders the implicit reference only when it sees any corresponding title in the same file. So the feature is difficult to implement in this filter.
If you have any ideas to solve this problem, feel free to comment here.
Pandoc supports implicit header references, as described here.
But when using
pandoc-include
AND when the file with the referenced header is included after the file with the implicit reference, the reference is not rendered properly. Note that explicit references work fine in the same situation.For example, consider the following markdown source:
Here is
10-chapter1.md
:Here is
20-chapter2.md
:If I convert it to HTML, I get this:
Note that only the explicit reference has been properly created. If I swap the MD files (so that
20-chapter2.md
comes first), there will be no such issue.