Macro Placeholders and Transformation Templates
Note: Macro transformation templates are available as of WikiTraccs v1.20.6.
What are macro placeholders?
They are text replacements for macros.
When migrating wiki pages from Confluence to SharePoint, WikiTraccs has to transform macros to something that SharePoint understands.
If there is no equivalent to a macro in SharePoint (which is the regular case), WikiTraccs often applies a generic transformation that replaces the macro in SharePoint with a text placeholder.
This generic macro transformation is applied to all macros that are not covered by an explicit transformation rule built-in to WikiTraccs.
How does a placeholder look?
Let’s take the div macro as example. It is part of Adaptavist’s Content Formatting Macros offering.
How does the div macro look before and after having been migrated to SharePoint?
The div macro allows to apply formatting to Confluence page content, like setting the text color.
The following configuration applies a blue text color to the macro content when the macro is shown on the Confluence page:
Macro in edit mode, applying the 'color:blue' CSS style to its content, plus some other things.
Macro in view mode, displaying blue text in the Confluence page.
When migrating this macro to SharePoint, WikiTraccs discards the macro container, pulls its content out, and puts that on the page. A text placeholder highlights that this happened:
So, the result of this transformation is:
- all content of the div macro has been migrated
- formatting is gone with the macro container
- a text placeholder highlights that a former div macro has been removed, but the content retained
Now, sometimes you want to get rid of that 🚧 placeholder text. You can create a custom placeholder to do that.
How to create a custom placeholder?
Advanced Topic
This and the following sections cover macro transformation templates which are designed to change how migrated pages look in SharePoint Online.WikiTraccs allows to apply custom text placeholders in generic macro transformations, using transformation templates.
Note
Generic macro transformation means that WikiTraccs does not contain a built-in transformation rule for a macro.
An example of a non-generic macro transformation is the code snippet macro, because WikiTraccs has a transformation built-in that creates a code web part in SharePoint. Transformation templates don’t apply here.
Another example of a non-generic macro transformation is the info macro, as WikiTraccs also has special handling built-in, transforming this macro to a table that resembles the original info panel. Transformation templates don’t apply here.
Nevertheless, most third-party macros are transformed in a generic fashion and transformation templates apply.
You can use Handlebars templates to describe how the placeholder for a macro should look. Handlebars is a templating system commonly used in web development.
Note
Refer to the Handlebars documentation to learn how Handlebars templates work. It is out of scope for this article to cover this.Let’s say we want to remove the placeholder text for the transformed div macro, just migrating its content.
The Handlebars template to do that looks like this:
{{!-- Don't add placeholder text, just render body --}}
{{Body}}
Some facts about above template:
{{Body}}
is a variable, referencing the macro body; this tells WikiTraccs to just render the macro body, without additional placeholder text{{!-- --}}
marks a comment in the template; this is ignored by WikiTraccs
Using above transformation template, the transformed macro looks like this in SharePoint:
The 🚧 note is now gone.
Where to put the transformation template?
Custom transformation templates are stored as files in a folder.
When using WikiTraccs.GUI (the blue window), find WikiTraccs.GUI.exe
and starting there, find the Templates\Transformation
folder. Save your template file there.
When solely using WikiTraccs.Console, find WikiTraccs.Console.exe
and starting there, find the Templates\Transformation
folder. Save your template file there.
The Transformation folder alreads contains files and should look like this (note that this can change in future WikiTraccs releases):
Each of those .hbs files contains a transformation template.
Note
The .hbs file extension is mandatory.The transformation templates can apply to either
- a single macro type (like div, or rw-ui-tabs-macro), OR
- multiple macro types (like english,belarusian,bulgarian,canadian-en,…)
Transforming a single macro type
When you want to transform a single macro type (like div), you save the transformation template in a file that carries the internal macro name in its filename and has the .hbs extension.
The file containing the transformation template for the div macro would thus be named div.hbs.
To reiterate, the steps to create a transformation template for a single macro type are:
- identify the internal macro name
- you can see macro names in the storage format XML
- note: for our div macro we see
ac:name="div"
in the storage format XML
- create a Handlebars template that describes how the custom placeholder should look
- save the Handlebars template in a file, in the Templates\Transformation folder
- the filename follows the pattern MACRONAME.hbl where MACRONAME is the name of the macro
- the file extension must be .hbl for WikiTraccs to recognize the file
Transforming multiple macro types
You can also put a special comment as first line into your .hbl file to apply the template to multiple macros, saving you the hassle to create identical files for each of those types.
Here is an example:
{{!-- applyto:english-us,english,belarusian,bulgarian,canadian-en,canadian-fr,catalan,chinese,croatian,czech,danish,dutch,estonian,finnish,french,german,greek,hindi,hungarian,icelandic,indonesian,irish,italian,japanese,korean,latvian,lithuanian,malay,maltese,norwegian-nb,norwegian,polish,portuguese,portuguese-br,romanian,russian,serbian,slovak,slovenian,spanish,swedish,thai,turkish,ukrainian,vietnamese --}}
This tells WikiTraccs to use the template for all the macros listed after the applyto:
marker (internal macro names, separated by comma).
The filename doesn’t matter, as long as it has the .hbs ending.
Which variables are available in templates?
The following variables are available in transformation templates:
Variable | Data Type | Meaning |
---|---|---|
Body | n/a | the macro body (if the macro has one) |
HasBody | boolean | true, if the macro has a body; false otherwise |
HasNoBody | boolean | true, if the macro has no body; false otherwise |
Details.DisplayName | text | macro display name |
TypeAsString | text | ‘macro’ for macros, ‘ADF extension’ for ADF extensions, ‘unknown embedding’ otherwise |
IsMacro | boolean | true, if the macro is a macro |
IsAdfExtension | boolean | true, if the ‘macro’ is an ADF extension (so, not really a macro, but covered by macro transformation nevertheless) |
HasParameters | boolean | true, if the macro has parameters; false otherwise |
ParameterCount | number | the number of macro parameters |
Parameters | collection | macro parameters, if the macro has any; each parameter has a Name and Value property; there is also a Links property that is populated with links parsed from the parameters |
WikiTraccs brings some transformation template files along. In the Templates/Transformation folder, have a look at the unknown.hbs.sample file for an advanced usage example, or any of the other files.
Troubleshooting
If your template is not recognized check for the following issues:
- the template file is in the wrong folder
- the template file doesn’t have the .hbl file ending
- the filename doesn’t have the right pattern
- the macro is already handled by a built-in transformation rule and thus no generic placeholder is being generated (note: there is nothing you can do about that; please get in touch and give feedback)
- the template is malformed
Check the console log output or common log files to see if WikiTraccs loads your template.
This is how the log looks if a template could be successfully loaded:
Found 3 transformation template files in folder '<path>/Templates/Transformation', will handle one by one: ch.bitvoodoo.confluence.plugins.language.hbs div.hbs rw-ui-tabs-macro.hbs
Trying to load transformation template from file 'Templates/Transformation/div.hbs'
Compiling and registering transformation template for 'div'
Any issues should be visible here as well. You can also look at the logs to learn about the path WikiTraccs loads templates from, if you are unsure where to put them.