Precompile

QName: f:precompile

Marks a node as having zero or more text properties that contain markdown or templated text that should be compiled (or transformed) when the document is saved. This transformation should occur when the source property is modified and the result should be stored on a new property that will store the compiled text.

Suppose you have a property on a node called text. It is a Markdown field where your editors make changes to text stored in the markdown format. When the node is saved (either created or deleted), this feature will let you have this markdown text automatically converted to HTML. The HTML can then be saved on a field called html.

The html field can then be utilized by your front-end application.

This allows your editors to work in Markdown but have the result be consumed by your downstream applications in the markup format of their choice.

Configuration

<tabl class="table table-bordered table-striped properties"e> Property Type Default Read-Only Description steps array An array of steps. See the documentation on Steps below.

Steps

To compile the content from a source property and store it in a target property, define your step like this:

{
    "sourceProperty": "/text",
    "targetProperty": "/html",
    "processor": "markdown"
}

Where:

  • fromProperty is a slash-delimited path to the property in your node that contains the markdown or templated content
  • toProperty is a slash-delimited path to the property in your node that should store the compiled text
  • processor identifies the processor to be used.

There are 2 processors supported at this time:

  • markdown for the Markdown processor
  • handlebars for the Handlebars processor

The Handlebars processor has access to the following root scoped variables:

  • node - the document being processed

Examples

Markdown Example

Let's define a content type (my:article) that looks like this:

{
	"_qname": "my:article",
    "_parent": "n:node",
	"_type": "d:type",

    "type": "object",	
    "properties":{
        "title": {
            "type": "string"
        },
        "text": {
            "type": "string"
        },
        "html": {
            "type": "string"
        }
    },
    "mandatoryFeatures": {
        "f:precompile": {
            "steps": [{
                "sourceProperty": "/text",
                "targetProperty": "/html",
                "processor": "markdown"
            }]
        }
    }
}

Note that we're using the markdown processor and setting things up so that the markdown stored in text will transform and save to html.

If we now create a my:article instance with the following JSON:

{
    "title": "Ford Prefect",
    "text": "# Ford Prefect"
}

When the node creation completes, we'll have this:

{
    "title": "Ford Prefect",
    "text": "# Ford Prefect",
    "html": "<h1>Ford Prefect</h1>"
}

Handlebars Example

Let's define a content type (my:article) that looks like this:

{
	"_qname": "my:article",
    "_parent": "n:node",
	"_type": "d:type",

    "type": "object",	
    "properties":{
        "title": {
            "type": "string"
        },
        "text": {
            "type": "string"
        },
        "html": {
            "type": "string"
        }
    },
    "mandatoryFeatures": {
        "f:precompile": {
            "steps": [{
                "sourceProperty": "/text",
                "targetProperty": "/html",
                "processor": "handlebars"
            }]
        }
    }
}

Note that we're using the handlebars processor and setting things up so that the markdown stored in text will transform and save to html.

If we now create a my:article instance with the following JSON:

{
    "title": "Arthur Dent",
    "text": "<h1></h1>"
}

When the node creation completes, we'll have this:

{
    "title": "Arthur Dent",
    "text": "<h1></h1>"
    "html": "<h1>Arthur Dent</h1>"
}