shyamd/mkdocs-bibtex

Crash with .csl

Closed this issue · 6 comments

Happy to see that Pandoc versioning was implemented with v1.0.0, nice work!

It seems to have introduced a bug regarding the csl_file input. Mine is crashing upon mkdocs serve when a .cslfile is included, but runs smoothly when it's not.

The relevant error lines look like this:

File "/usr/local/lib/python3.9/site-packages/mkdocs_bibtex/plugin.py", line 109, in on_page_markdown
    references = self.format_citations(citations)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_bibtex/plugin.py", line 151, in format_citations
    entry_text = to_markdown_pandoc(entry, self.csl_file)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_bibtex/plugin.py", line 201, in to_markdown_pandoc
    citation = citation_regex.findall(" ".join(markdown.split("\n")))[0]
IndexError: list index out of range

Runs in a fresh conda environment, only installing mkdocs-material and mkdocs-bibtex.
pypandoc: 2.14.0.2
mkdocs-bibtex: 1.0.0

Still trying to understand the bug. Does it work in a specific environment and not another? Do you have a pip freeze for the environment that doesn't work?

I can confirm this issue.

I added a print(markdown) command in line 201, and got following output

::: {#refs .references .csl-bib-body .hanging-indent}
::: {#ref-KeYBook2016 .csl-entry}
[Ahrendt, W., Beckert, B., Bubel, R., Hähnle, R., Schmitt, P.H., and
Ulbrich, M., eds.]{.smallcaps} 2016. *Deductive software verification -
the KeY book - from theory to practice*. Springer.
:::
:::

Due to missing .csl-left-margin and .csl-right-margin the regular expression matches nothing. A missing check results into "out of range" error:

citation = citation_regex.findall(" ".join(markdown.split("\n")))[0]

In general, your CSL support assumes a certain output pattern, that is not commonly present---at least not in ACM or Springer CSL.

You need to find another way to sanitize the output of Pandoc.

Not sure its the same issue.

I agree the citation processing is primitive.

Can provide a small working example that throws this error?

Before I create a mkdocs project, could you just try a CSL file without the required marker in your setup. I used the springer-basic-author-date.

Should be fixed with #101 . Let me know if it's not, in which case I need a better example to figure out what could be going on.