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

stringify duplicates citation text #7855

Closed
not-my-profile opened this issue Jan 20, 2022 · 2 comments
Closed

stringify duplicates citation text #7855

not-my-profile opened this issue Jan 20, 2022 · 2 comments
Labels

Comments

@not-my-profile
Copy link
Contributor

Explain the problem.

$ printf '[foo bar baz @cite]' | pandoc -L <(echo function Block(x) return pandoc.utils.stringify(x) end)
foo bar baz[foo bar baz @cite]

Pandoc version?
pandoc 2.17.0.1 on Linux

@jgm
Copy link
Owner

jgm commented Jan 20, 2022

If you do pandoc -t native, you'll see that the AST contains

[ Para
    [ Cite
        [ Citation
            { citationId = "cite"
            , citationPrefix =
                [ Str "foo" , Space , Str "bar" , Space , Str "baz" ]
            , citationSuffix = []
            , citationMode = NormalCitation
            , citationNoteNum = 1
            , citationHash = 0
            }
        ]
        [ Str "[foo"
        , Space
        , Str "bar"
        , Space
        , Str "baz"
        , Space
        , Str "@cite]"
        ]
    ]
]

in which structure there are actually two inline lists with "foo bar baz..." (one the citationPrefix field, the other the second argument of the Cite constructor).

In fact this has nothing to do with Lua and can be reproduced using Haskell:

Prelude Text.Pandoc.Builder Text.Pandoc.Shared Text.Pandoc Data.Text> stringify  [Para [Cite [Citation {citationId = "cite", citationPrefix = [Str "foo",Space,Str "bar"], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 1, citationHash = 0}] [Str "[foo",Space,Str "bar",Space,Str "@cite]"]]]
"foo bar[foo bar @cite]"

The question, then, is whether stringify should be modified so it doesn't recurse into the [Inline] fields of the Citation elements.

@not-my-profile not-my-profile changed the title [lua] utils.stringify duplicates citation text stringify duplicates citation text Jan 20, 2022
@jgm
Copy link
Owner

jgm commented Jan 20, 2022

Actually the work is done by query from T.P.Walk.
But rather than modifying query, we could add deCitation to the walk (deNote . deQuote) in the def of stringify. deCitation would simply null out the first parameter of the Cite constructor, leaving only the fallback.

@jgm jgm closed this as completed in d9ec95e Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants