data oninclude - speced/respec GitHub Wiki

data-oninclude

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.

Usage

<script>
  function addTimestamp(utils, content, url) {
    return content + `\n<!-- Included from ${url} -->`;
  }
</script>

<section data-include="section.html"
         data-oninclude="addTimestamp">
</section>

Function signature

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.

Notes

  • 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
⚠️ **GitHub.com Fallback** ⚠️