demo.html 1.2 KB

12345678910111213141516171819
  1. {{ $uniq := .Inner | htmlEscape | base64Encode | truncate 20 "" | lower }}
  2. {{ $template := printf "template-%s" $uniq }}
  3. {{ $string := replace "<script>ShadyCSS.prepareTemplate(template%s, 'demo-elem%s'); var script = template%s.content.querySelector('script'); if (script) { script.textContent = `(function() { var demo = document.querySelector('demo-elem%s').shadowRoot; ${script.textContent} })()` } class DemoElem extends HTMLElement { connectedCallback() { ShadyCSS.styleElement(this); this.attachShadow({mode: 'open'}); this.shadowRoot.appendChild(template%s.content.cloneNode(true)); } } customElements.define('demo-elem%s', DemoElem);</script>" "%s" $uniq }}
  4. <div class="demo-container">
  5. {{ if .Get "caption" }}
  6. <figure role="group" aria-labelledby="caption-{{ $uniq }}">
  7. {{ end }}
  8. <demo-elem{{ $uniq }} class="demo" id="demo-{{ $uniq }}"></demo-elem{{ $uniq }}>
  9. {{ if .Get "caption" }}
  10. <figcaption id="caption-{{ $uniq }}">{{ .Get "caption" | markdownify }}</figcaption>
  11. {{ end }}
  12. {{ if .Get "caption" }}
  13. </figure>
  14. {{ end }}
  15. <template id="template{{ $uniq }}">
  16. {{ .Inner | safeHTML }}
  17. </template>
  18. {{ $string | safeHTML }}
  19. </div>