tstenner / luarefnos

Pure lua demo for Pandoc cross-references
BSD 2-Clause "Simplified" License
12 stars 3 forks source link

Suggest to support "clever references" with "+" #5

Open dmitryperets opened 7 months ago

dmitryperets commented 7 months ago

Since pandoc-xnos seems to be dead for now and it doesn't really support pandoc 3.x (e.g. pandoc-fignos is broken due to the new AST format), migrating to this native LUA implementation sounds like a good idea. But it would be beneficial if we could keep the documents written for pandoc-xnos...

So one of the differences is the "clever references" feature available in pandoc-xnos. The difference is the following:

Ideally, my suggestion is to implement exactly the same syntax as pandoc-xnos. But if that is too complex, maybe it is possible to implement deletion of the + sign right before the reference.

Explanation:

tstenner commented 7 months ago

Sounds good, but it's not straightforward at all to implement this. @fig:myfigure is parsed as a native Citation:

ts@liag0002:~$ echo '@fig:myfigure' | pandoc -t native
[ Para
    [ Cite
        [ Citation
            { citationId = "fig:myfigure"
            , citationPrefix = []
            , citationSuffix = []
            , citationMode = AuthorInText
            , citationNoteNum = 1
            , citationHash = 0
            }
        ]
        [ Str "@fig:myfigure" ]
    ]
]
$ echo '+@fig:myfigure' | pandoc -t native
[ Para
    [ Str "+"
    , Cite
        [ Citation
            { citationId = "fig:myfigure"
            , citationPrefix = []
            , citationSuffix = []
            , citationMode = AuthorInText
            , citationNoteNum = 1
            , citationHash = 0
            }
        ]
        [ Str "@fig:myfigure" ]
    ]
]

This is handled by the citation handler.

+@fig:myfigure is parsed as the string + followed by the citation, so it's not possible to match on prefixes before the @ sign.

tstenner commented 7 months ago
$ echo '+@fig:myfigure' | pandoc -t native
[ Para
    [ Str "+"
    , Cite
        [ Citation
            { citationId = "fig:myfigure"
            , citationPrefix = []
            , citationSuffix = []
            , citationMode = AuthorInText
            , citationNoteNum = 1
            , citationHash = 0
            }
        ]
        [ Str "@fig:myfigure" ]
    ]
]