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

Footnote in AST lacks index information #43

Open
srid opened this issue May 13, 2020 · 5 comments
Open

Footnote in AST lacks index information #43

srid opened this issue May 13, 2020 · 5 comments

Comments

@srid
Copy link

srid commented May 13, 2020

The HasFootnote instance for Pandoc AST ignores the footnote identifiers, and labels:

instance (Rangeable (Cm a B.Inlines), Rangeable (Cm a B.Blocks))
=> HasFootnote (Cm a B.Inlines) (Cm a B.Blocks) where
footnote _num _lab _x = mempty
footnoteList _xs = mempty
footnoteRef _num _lab contents = B.note <$> contents

And it looks like Pandoc is doing its own state management to compute the identifier, and render the references accordingly. Is storing these footnote identifiers/labels in the Pandoc AST explicitly out of scope?

@jgm
Copy link
Owner

jgm commented May 14, 2020

I'm not sure where we'd store them.

@srid
Copy link
Author

srid commented May 15, 2020

Can we add an extra field to the Note constructor (which as I understand is used for footnotes exclusively)?

-- | Note <footnoterefname> <footnote>
Note Text [Block]

Just to provide some context: since I need to render in GHCJS, I'm rendering the footnotes by traversing the AST. https://github.com/srid/reflex-dom-pandoc/blob/master/src/Reflex/Dom/Pandoc/Footnotes.hs

You can see how it renders at https://www.srid.ca/1948201.html

In this example, there are four footnotes named 1, 2, 3 and 4. However if you actually look at the source markdown, the footnotes don't use numbers but custom text. I thought it would be nice re-use the same footnote ref as the user provided; but this information is not passed to the Pandoc AST. Adding a field to the Note constructor is one way to pass it. But then I haven't thought this problem in greater detail considering other pandoc use cases.

@jgm
Copy link
Owner

jgm commented May 15, 2020

Some relevant discussion here:
jgm/pandoc#2583

But I generally like to avoid changes to pandoc-types, which are painful for the whole ecosystem (everything has to be changed).

For your purposes, you could create a special instance of IsInline and IsBlock for pandoc, instead of using the one provided in commonmark-pandoc. You could put the contents of each note in a Div and put the label in an attribute of the Div. That would allow you to get it back out again.

@jgm
Copy link
Owner

jgm commented May 15, 2020

That said, it could be worth putting an issue on pandoc-types suggesting this.
But only if you're willing to do the work (should the idea be accepted) of modifying all the pandoc code to use the new type!

@jgm
Copy link
Owner

jgm commented May 15, 2020

I suppose the most obvious useful change would be to add an Attr field to the Note constructor.

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

2 participants