Changelog¶
All notable changes to panflute are documented in this file. The format is based on Keep a Changelog. Entries before 3.0.0 are brief; see the commit history for details.
3.0.0 (2026-11-20)¶
The first release since 2.3.1 (March 2024). It requires Python 3.10 or later,
ships type hints, accepts any raw format (such as typst, comment or
latex-merge), fixes many bugs in element navigation and containers, and
makes filters start and run faster. Most filters run unchanged. The breaking
changes below are the main incompatibilities, and “Changed” lists smaller
differences in behavior; the
What’s new in 3.0
page of the documentation explains how to migrate.
Breaking changes¶
Python 3.10 or later is required (2.3.1 supported Python 3.7 and later). Python 3.10 to 3.15 are supported, as is PyPy (tested with PyPy 3.11). Migration: on older Pythons, pip keeps installing panflute 2.3.1; if a project must keep working there, require
panflute<3for those Pythons.MetaList.indexis now the list methodindex(value, start=0, stop=None)(#258). It used to be the index of theMetaListin its container, sometalist.index(value)andmetalist.remove(value)failed. That index is now the attributeElement.index_in_parent, on every element; on every element exceptMetaList,.indexremains a read/write alias of it. Migration: where your code reads the.indexof aMetaList, use.index_in_parent. Beware thatif metalist.index is not Noneis now always true, and that assigning tometalist.indexraisesAttributeError.Pickles of a
MetaListmade with panflute 2.x cannot be loaded by 3.0 (AttributeError), nor can pickles of anything that contains one, such as aDocwhose metadata has a list. Other pickled elements still load. Migration: re-create the pickles with 3.0, or store documents as pandoc JSON (dump()/load()), which does not depend on the panflute version.Slices of a
ListContainer(elem.content[1:3]) are now instances of a private subclass ofListContainer, sotype(s) is ListContaineris false (isinstance(s, ListContainer)is still true). As before, a slice is a new container that holds the same elements. Reading, iterating or changing a slice no longer changes theparent/index_in_parentof the elements (reading it used to re-index them relative to the slice). Migration: useisinstance(), orlist(s)for a plain list.TableCellrequires integerrowspanandcolspanand raisesTypeErrorotherwise (a float used to be accepted and written into the JSON sent to pandoc). Migration: passint(...).
Added¶
Type hints. The public API is annotated inline and panflute ships a
py.typedmarker (PEP 561), so mypy, pyright and IDEs use the hints to check filters and complete attributes.If you installed a separate stub package, such as
panflute-stubs, uninstall it: type checkers prefer it to the hints shipped with panflute.Filters that are already type-checked may see new errors where the hints are stricter (see the simplifications below).
Arguments that take a few fixed values have
Literaltypes (e.g.Quoted(quote_type=...),OrderedList(style=..., delimiter=...),Math(format=...),TableCell(alignment=...),Citation(mode=...)).Filter actions are typed
(Element, Doc) -> Element | list[Element] | None;walk()returns the element or what the action returned for it;convert_text()returnslist[Element], aDocwithstandalone=True, orAnyfor other output formats;MetaListslicing is typed (#260).Deliberate simplifications: the
docpassed to an action is typedDoc, although it isNonewhenwalk()is called on an element that is not part of a document;identifier,classesandattributesare declared on everyElement, although only elements with attributes have them; and passing a bare class (Para(Space)) instead of an instance (Para(Space())) still works at runtime but is rejected by type checkers.The hints build on an unreleased first version contributed in #257, thanks to Leilei332, and correct its
walk()hints (#259); castedo/panflute-stubs was used as a reference.
Element.index_in_parent: the index of an element within the list container that holds it (elem.container), orNonewhen no list container holds it (e.g. a table caption, or a value of aMetaMap); seeMetaList.indexabove.panflute --help,panflute -handpanflute --versionprint a short usage text or the version (they used to wait for a document on stdin).
Changed¶
Supported pandoc versions: 2.11.4 to 3.14, i.e. pandoc API 1.22 to 1.23.1.x (2.3.1 was documented for pandoc up to 3.1); the table in the README says which versions are tested (#248).
import panfluteno longer importsclick,yaml/yamlloaderorpanflute.autofilter; panflute imports them the first time it uses them (yaml_filter(),panfl,panflute.autofilter, …). A missing or broken click or PyYAML installation is therefore reported when it is first needed, not at import. All names remain available as attributes, indir()and throughfrom panflute import *, which therefore still imports click andpanflute.autofilter(useimport panflute as pfto start faster).dump()without an output stream no longer replacessys.stdout: it used to replace it for good with a UTF-8 writer, so text printed to stdout afterdump()now uses the stream’s own encoding.dump()writes the JSON as UTF-8 bytes tosys.stdout.buffer, or as text tosys.stdoutwhen it has no buffer (e.g. anio.StringIOset bycontextlib.redirect_stdoutor by pytest’s capture, where it used to raiseio.UnsupportedOperation). Likewise,load()without an input stream no longer closessys.stdin.buffer, and works whensys.stdinis a text stream.yaml_filter(..., strict_yaml=True)no longer raisesValueError,TypeErrororParserErrorfor a YAML chunk that is not a mapping (a list or a scalar) or that fails to parse with ayaml.parser.ParserError: it prints a warning to stderr and leaves the code block unchanged, as it already did for ayaml.scanner.ScannerError. A chunk with only comments counts as no options.The “invalid api version”
TypeError, raised for documents from pandoc older than 2.11, now explains the problem and its usual cause:convert_text()andrun_pandoc()run the firstpandocon thePATH, which can be older than the one running the filter (#246). The exception is still aTypeErrorwhose message starts with “invalid api version”, but itsargsare now that single message (they used to be('invalid api version', [1, 20])).Citation’sprefixandsuffixdefault to()instead of''in its signature (same behavior; passing''still works).
Fixed¶
RawBlockandRawInlineaccept any format string, as pandoc does, so documents with e.g.{=comment},{=typst},{=asciidoc}, Quarto’slatex-mergeor custom-writer raw elements can be loaded and built (#236, #247). Other formats used to raiseTypeError; non-string formats still do. This generalizes unreleased fixes fortypstandlatex-mergefrom #244 and #251, thanks to jkub6 and matthew-brett.panflute.elements.RAW_FORMATSis no longer used, and is kept only as a reference list.convert_text(..., standalone=True, extra_args=args)no longer appends'--standalone'to the caller’sargslist, which made later calls with the same list standalone too (#262).An element’s
parent(and itsindex_in_parent, in a list container) is set as soon as the element is added, and not only when it is read back from its container: when the parent is built, and byappend,insert, item and slice assignment, andMetaMap/DictContaineritem assignment (#255, #256, thanks to me-kell).Element indexes (
index_in_parent/index, and sonext,prevandoffset()) are now always non-negative and kept up to date by insertions, deletions and slice assignments. They used to go stale or wrong: afterinsert()ordelon a container, the elements after the change kept their old index (b.nextcould bebitself); reading with a negative index (content[-1]) stored a negative index; and reading a slice re-indexed the original elements.MetaList.index(value)andMetaList.remove(value)raisedTypeError(#258; see “Breaking changes” above).Setting
MetaMap.contentto adict,MetaMaporDictContainerraisedAttributeError; it now accepts any mapping or iterable of pairs.Comparing a
ListContainerwith a non-container (elem.content == 1) raisedAttributeError; it is nowFalse.yaml_filtertriggered aDeprecationWarningon Python 3.13+ (positional arguments tore.split()).panflute.tools.pandoc_version(aPandocVersion, used to find pandoc’s data directory) never used its cache, and ranpandoc --versionon every access to.version,.data_dirorstr().shell(cmd, wait=False)always raisedValueErroron Linux and macOS. The command now runs detached, in its own session, with stdin and stdout redirected to/dev/nullso that it cannot write into the document sent to pandoc (stderr is inherited; Windows is unchanged).panfl --no-sys-pathhad no effect with click 8.2 or later.When running the filters listed in the metadata (
pandoc -F panflute,panfl), panflute setsys.stdouttosys.__stdout__afterwards instead of restoring the previous stream, and left it redirected when a filter raised; its “filter wrote to stdout” warning was printed as a tuple.ContextImportleft its directory onsys.pathwhen the import failed.A docstring in
panflute.iocaused aSyntaxWarning(invalid escape sequence) on Python 3.12+ (#264, thanks to cdlm).Example filters:
lilypond.pyused undefined names,myemph.pyandtable.pyused theElement.itemsattribute removed in panflute 2.0 (table.pyis rewritten for the current table model),table-better.pyused undefined names,graphviz.pylinked to the wrong image path, andmetavars.pyhad invalid escape sequences.
Performance¶
Measured with tests/benchmark.py on CPython 3.12, panflute 2.3.1 against
3.0.0 (the minimum over several runs, on the same machine):
import panflute: 82 ms → 22 ms.from panflute import *gains less, because it still imports click.A no-op filter run as pandoc runs it, on a small document: 107 ms → 45 ms.
walk(): 36–42% faster when the action changes nothing, 27–37% faster when it replaces and deletes elements;stringify(): 27–35% faster.load()anddump(): unchanged.
Packaging and infrastructure¶
Built from
pyproject.tomlonly (setup.pyremoved; #250, thanks to paddatrapper), with setuptools 77.0.3 or later and PEP 639 metadata: the license is the SPDX expressionBSD-3-Clause.Extras: the
pypiextra is removed;devis now pytest, pytest-cov, ruff, mypy and types-PyYAML (configparser, coverage, flake8, pandocfilters and requests are dropped); a newdocsextra installs what the documentation build needs;extras(yamlloader) is unchanged. Therequirements.txtfiles are removed.The sdist includes
CHANGELOG.md,CONTRIBUTING.md, the test suite and the example filters, so the tests can be run from it (pandoc required).New project URLs (documentation, repository, issues, changelog).
Continuous integration rewritten: ruff and mypy; tests on Python 3.10–3.15 and PyPy 3.11 against pandoc 2.11.4 up to the latest release; the example filters; a docs build; and a build check with
twine check --strict.Releases are published to PyPI from GitHub Actions with Trusted Publishing (PyPI accepts the upload from the workflow itself, with no stored password or token), and the workflow refuses to publish when the release tag differs from the package version (see #243, #252).
force-publish.ymlis removed; Dependabot keeps the actions up to date.The test suite was rebuilt: from 37 to 741 tests, with golden JSON round-trip fixtures and about 98% branch coverage.
tests/benchmark.pytimes import, load, walk, stringify, dump and a whole filter run, optionally against another copy of panflute.The documentation was updated for 3.0, with a What’s new in 3.0 page and this changelog.
Known limitations (unchanged in 3.0.0)¶
stringify()inserts the text of a footnote where the note is, with no separator (#225).Caption(short_caption=[])is written as “no short caption” (null).MetaMap(...) == {...}isFalse(compare withdoc.get_metadata()instead), andDoc.__eq__ignoresformatandapi_version.An element removed from a container keeps its old
parentandindex_in_parent; an element held by two containers (not counting slices) reports the one it was last added to or read from.
2.3.1 (2024-03-20)¶
2.3.0 (2023-01-26)¶
Update the Pandoc API from 1.22 to 1.23 (Pandoc 3.0):
Add
Figureblock objectRemove
Nullblock object (scheduled for removed)