Skip to content

Preprocessor for Foliant that replaces words using a user' dictionary

License

Notifications You must be signed in to change notification settings

foliant-docs/foliantcontrib.replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Replace text for Foliant

Preprocessor for simple search and replace in Markdown sources with support of regular expressions.

Installation

$ pip install foliantcontrib.replace

Config

To enable the preprocessor, add replace to preprocessors section in the project config:

preprocessors:
  - replace

The preprocessor has two options:

preprocessors:
  - replace:
      dictionary:
        Mike: Michael
        Sam: Samuel
        Tim: Timoel
      re_dictionary:
        '!\[\]\((.+?)\)': '![Figure](\1)'

dictionary : YAML mapping where key is string to replace, value is the replacement string.

re_dictionary : YAML mapping where key is Python regular expression pattern, value is the replacement string.

Usage

Fill up the dictionary or/and re_dictionary in preprocessor options and the keys will be replaced with values.

For example, if you wish that all images without title in your Markdown sources were titled "Figure", use the following config:

preprocessors:
  - replace:
      re_dictionary:
        '!\[\]\((.+?)\)': '![Figure](\1)'

You can also apply a sequence of regex substitions. Like case-insensitive link insertion as shown in the example below:

preprocessors:
  - replace:
      re_dictionary:
        '`(?i)(wikipedia)`': '[\1](https://www.wikipedia.org/)'
        '`(?i)(github)`': '[\1](https://github.com/)'

About

Preprocessor for Foliant that replaces words using a user' dictionary

Resources

License

Stars

Watchers

Forks

Packages

No packages published