data oninclude - speced/respec GitHub Wiki
Applies to: elements with data-include
A space-separated list of globally-defined JavaScript function names to call on the included content before it is inserted into the document. Each function transforms the raw content string.
<script>
function addTimestamp(utils, content, url) {
return content + `\n<!-- Included from ${url} -->`;
}
</script>
<section data-include="section.html"
data-oninclude="addTimestamp">
</section>Each transform function receives:
| Argument | Type | Description |
|---|---|---|
utils |
Object |
ReSpec utility functions |
content |
string |
The raw included content as a string |
url |
string |
The URL of the included file |
The function must return the (possibly modified) content string.
- Functions are called in order, left to right — each receives the output of the previous
- Functions must be globally accessible (defined in a
<script class="remove">block) - Runs on the raw string before HTML/Markdown parsing — useful for preprocessing