Skip to main content

A Python filter to manage acronyms

Project description

pandoc-acronyms - A Pandoc filter for managing acronyms

Acronyms? WTF?

There is a convention in more precise writing to provide the full text of an acronym at first use. This can get difficult for example if the text of documents is split over multiple files, which makes it hard for the authors to know where the acronym will be used first. Such a task is best left to the computer. This is what the pandoc-acronyms filter is for. Authors list acronyms in a data file and then reference them in the text.

HOWTO

Write a data file that contains your acronyms:

{
	"aba": {
		"shortform": "ABA",
		"longform": "a better acronym"
	},
	"bba": {
		"shortform": "BBA",
		"longform": "beer brewing attitude"
	}
}

Then in the text, use the acronym in encoded form like [!bba]. The filter will recognize it. On first use it replaces the marker with beer brewing attitude (BBA). Any later use will be replaced by BBA. The filter will print a notice if an acronym is found in the text that is not defined in the data file.

Using the filter

The filter mechanism is a built-in feature of pandoc. The filter is added to how pandoc is invoked:

> pandoc --filter pandoc-acronyms document.md

Unfortunately, pandoc does not allow to pass parameters to filters. The acronym filter needs to load the acronyms from the data file. To work around this, the parameters to the filter can be passed in environment variables:

> pandoc-acronyms --help
Usage: pandoc-acronyms [OPTIONS] [FORMAT]...

The pandoc-acronyms filter.

Options:
	-a, --acronyms TEXT           A file with acronym definitions in JSON format.
	-v, --verbose / --no-verbose  Enable verbose output.
	-v, --debug / --no-debug      Enable debug output.
	--help                        Show this message and exit.

The environment variable PANDOC_ACRONYMS_ACRONYMS can be used to replace the --acronyms option. Similarly, the variable PANDOC_ACRONYMS_VERBOSE enables diagnostic output.

Installation

The pandoc acronym filter is installed using Python setuptools:

> python setup.py install
...

After that, it is available as a stand-alone program in the installation location used by Python.

Testing and debugging

The pandoc-acronyms code uses the standard Python unittest framework. Most tests are data-driven in that they use regular Markdown files and JSON acronym dictionaries as input and test how the code handles them. To test the filter code as regular Python unit tests, test Markdown input is first converted into the Pandoc "native JSON" format in memory and then fed to the filter code by the tests. This means the unit tests run stand-alone (without the need for Pandon to invoke them as a filter), making the test code easily debugable.

How to contribute

The Git repository for the pandoc acronym filter is hosted on Gitlab. It uses the Gitlab CI to ensure quality, also for development branches and incoming merge requests. To contribute, please submit a merge request. Your merge request should maintain or increase the test coverage.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandoc-acronyms-0.4.dev202002291140.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pandoc-acronyms-0.4.dev202002291140.tar.gz.

File metadata

  • Download URL: pandoc-acronyms-0.4.dev202002291140.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for pandoc-acronyms-0.4.dev202002291140.tar.gz
Algorithm Hash digest
SHA256 ae7ef0b3178b2a70357b135783f081a9076f0ffe666a3eb7341cb9fbf14a06b8
MD5 677fd9e2a1bd0fdc65ac48e126b58841
BLAKE2b-256 b107d050b86539f00777ec1eccc4ee21900f1257ee73af586906cad4e4dce785

See more details on using hashes here.

File details

Details for the file pandoc_acronyms-0.4.dev202002291140-py3-none-any.whl.

File metadata

  • Download URL: pandoc_acronyms-0.4.dev202002291140-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for pandoc_acronyms-0.4.dev202002291140-py3-none-any.whl
Algorithm Hash digest
SHA256 f574cff2f632f126eb4d3682b8c1b417bebe4b647b72f55c6b7f26308b3cb7b1
MD5 2691f037cb0f1a78a10c1f3aaf277fe8
BLAKE2b-256 f9c1e5cd702110a594caa6236dad0b4fef7962e65d7c1b9d0603bb712f0b170d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page