Textflow
What It Is
A library to enable serial text transformation using a "pipeline" of "commands," each of which cumulatively operates on a string of text.Status
Stable and actively development. The library is in use in several customer and demo instances at Staffbase.
Details
Textflow is a “language” to perform a series of transformations on text. Text can be obtained before and sent through the “pipeline,” or it can be acquired from within the pipeline.
Textflow is normally configured using Config Lang, and a configuration can be stored as parsable text, which makes it user-editable, suitable for editing in a UI.
A very simple example:
set -text:bar
prepend -text:"foo "
append -text:" baz"
Assuming the pipeline starts with no text (meaning nothing is “poured in the top”):
- The first command sets the working text of the pipeline to
barand passes it to the next command - The second command takes the output from the first command and prepends
footo the beginning, then passes the result to the next command - The third command takes the output from the second command and appends
barto the end, then outputs the result (the result of the last command is what is output)
The result is foo bar baz.
Here’s a more practical example:
http -url:https://domain.com/some/path
extract -selector:body -scope:inner
remove -selector:h1
wrap -tag:div -style:"border: solid 1px red; padding: 1em;"
This pipeline:
- Retrieves an entire HTML document from a specified URL. The resulting response body becomes the working text of the pipeline
- Extracts the innerHTML of the
BODYelement - Removes any
H1tags in the document - Wraps what’s left inside a
DIVtag with some styling
The result is a fragment of HTML that can be injected into a DOM.
In a practical sense, imagine that pipeline is stored in some type of widget that can be placed inside rich text in a CMS editor. With this, you have effectively created a small, domain-specific language that will execute at runtime, and retrieve, transform, and format a string of HTML to display.