Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links for cross-references with explicit an ID don't work with HTML output #18

Open
somelinguist opened this issue Jan 11, 2024 · 1 comment

Comments

@somelinguist
Copy link

somelinguist commented Jan 11, 2024

With the following markdown from readme.md, the div's ID in the HTML output gets overwritten to ex4.13 instead of test.

::: {#test .ex}
This is a test
:::

<div id="ex4.13">
<table class="linguistic-example">
<tbody>
<tr class="odd">
<td class="linguistic-example-number" style="vertical-align: top;">(4.13)</td>
<td class="linguistic-example-content" style="text-align: left;">This is a test</td>
</tr>
</tbody>
</table>
</div>

However, the cross-references using [@last], etc. maintain test as the ID to link to (the following is taken from readme.html, line 732):

<code>[@last]</code> will be formatted as <a href="#test">(4.13)</a>

Likewise, in line 733:

<code>[@last hA1l0]</code> will work also, leading to <a href="#test">(4.13 hA1l0)</a>

and line 717:

<code>[@test]</code>, leading to <a href="#test">(4.13)</a>

The ID for the div gets reset for HTML output in line 276 of pandoc-ling.lua

pandoc-ling/pandoc-ling.lua

Lines 268 to 277 in a9eae71

-- reformat!
local example
if FORMAT:match "latex" or FORMAT:match "beamer" then
example = texMakeExample(parsedDiv)
else
example = parsedDiv.examples
example = pandocMakeExample(parsedDiv)
example = pandoc.Div(example)
example.attr = {id = "ex"..parsedDiv.number}
end

Following the proposal one should be able to link from an external source to something like webpage.url/#ex4.13, should the code that makes the cross-references for HTML also change the ID to #ex4.13 instead of #test?

pandoc-ling/pandoc-ling.lua

Lines 1538 to 1547 in a9eae71

-- make the cross-reference
if FORMAT:match "latex" then
if latexPackage == "expex" then
return pandoc.RawInline("latex", "(\\getref{"..id.."}"..suffix..")")
else
return pandoc.RawInline("latex", "(\\ref{"..id.."}"..suffix..")")
end
else
return pandoc.Link("("..indexEx[id]..suffix..")", "#"..id)
end

@somelinguist
Copy link
Author

Actually, for the HTML output, if you wanted, you could make a link using either #test or #ex4.13 work if line 276 set the div's ID to test, and then added an ID for something like the cell containing the example number itself to ex4.13:

pandoc-ling/pandoc-ling.lua

Lines 556 to 558 in a9eae71

-- Add example number to top left of first table
local numberParen = pandoc.Plain( "("..parsedDiv.number..")" )
example[1].bodies[1].body[1].cells[1].contents[1] = numberParen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant