Skip to content

Introduction

Creating preprocessors for Foliant is quite straightforward because they are essentially just Python scripts wrapped in a Preprocessor class, which is provided by Foliant core. In this tutorial, we will go through all steps of creating a new preprocessor.

The full source code of the preprocessor created in this tutorial can be found here.


First of all, we need to decide what our preprocessor will do. Let's say you need a preprocessor that will generate some placeholder gibberish text for your documentation, somewhat like Lorem Ipsum.

We need a way to tell Foliant to insert the placeholder into a specific part of our document. The Foliant way of doing that is using an XML-tag like the following.

<gibberish></gibberish>

After the preprocessor is applied, this tag should be transformed into some placeholder text.

Hiteap zoiouxwaf jyrcaay yty xuzuapo eyuigouu. Ysseotaeq ytuiio qqyy yehiiy koyiyoky uul. Pan osfu zoiz oy ikcya tcsxecy qxiiyo. Gryxeye ogeelaee atprwm mjioy eigyyoov nx qe tayoiaud jodmaofue yvo ieyuunyrq eaowu. Jyqnr aej elqj wuytjcae oy igy ak.

We would also want to specify the size of the generated text, so our tag should accept the size parameter which will define the number of generated sentences:

<gibberish size="15"></gibberish>

The tutorial is split into three stages:

  1. Writing the gibberish generator,

  2. Wrapping it in a Preprocessor class,

  3. Installing and testing the preprocessor.

So let's get started!

Next: Creating the Gibberish Generator

Back to top