Skip to main content

Utils for foliant plugin developers

Project description

Generic utils

This module contains various utils for inner use in Foliant preprocessors, backends and other modules.

Installation

To use functions from this module, install it with command

pip3 install foliantcontrib.utils

Usage

Right now this module offers only one useful function, called prepend_file. This function properly prepends the markdown file with text string. If file starts with a YAML Front Matter or a heading, there are options to insert the content after them.

>>> from foliant.contrib.utils import prepend_file

Let's assume we have a file which begins with YAML Front Matter:

---
author: John
---

Contents.

If we want to add some content to the beginning of this file for some reason, we will probably want to add this content after the YAML Front Matter, otherwise it will be broken by our insertion.

We can use the prepend_file function which will manage this case for us:

>>> prepend_file('myfile.md', '\nInserted content\n', before_yfm=False)

Notice the before_yfm paramter. If it is False (which it is by default), the content will be added after YAML Front Matter. The result would be:

---
author: John
---

Inserted content

Contents.

There's also an option before_heading. If it is False (it's True by default), the content will be inserted after the first heading, if the document starts with a heading. Some backends treat these heading in a special way, that's why sometimes it makes sense to insert things after them.

Example:

# System description

Contents.

let's add some text:

>>> prepend_file('myfile.md', '\nInserted content\n', before_heading=False)

Result:

# System description

Inserted content

Contents.

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

foliantcontrib.utils-1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

foliantcontrib.utils-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file foliantcontrib.utils-1.0.0.tar.gz.

File metadata

  • Download URL: foliantcontrib.utils-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.6

File hashes

Hashes for foliantcontrib.utils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 95bd880e85daf98a94b6d80466a87ccde07e4b827177a9adc4476565f48e315b
MD5 203c99be8505ed59bad57ddb0e972958
BLAKE2b-256 c9297f3a76277105aa435437bb3bf9f56c2bc484cd85fa104a8eb5f056c631a5

See more details on using hashes here.

File details

Details for the file foliantcontrib.utils-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: foliantcontrib.utils-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.6

File hashes

Hashes for foliantcontrib.utils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5dca84df81427b9d4b56b45b5345de17eaf79c412ea8b74574a1354e02f486f1
MD5 f7a2887bb0a8754a1fa8cb28b93e54f2
BLAKE2b-256 630def7a3683d4c226f8ecca8cf38d0cccc5feb0a11dc6825b94326b1617883c

See more details on using hashes here.

Supported by

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