threepipe
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

simple-code-preview.mjs 1.2KB

1234567891011121314151617181920
  1. import {setupCodePreview} from 'https://cdn.jsdelivr.net/gh/repalash/example-code-previewer/dist/index.js';
  2. const exampleScript = document.getElementById('example-script')
  3. const scripts = exampleScript && exampleScript.dataset.scripts ? exampleScript.dataset.scripts.split(';') : []
  4. if(exampleScript.textContent) scripts.push(exampleScript)
  5. const exampleStyle = document.querySelector('#example-style')
  6. const css = exampleStyle ? exampleStyle.textContent : ''
  7. setupCodePreview(
  8. document.getElementById('canvas-container') || document.querySelector('.code-preview-container'),
  9. scripts,
  10. scripts.map(s=>s.textContent ? 'js' : s.split('.').pop()), // title
  11. scripts.map(s=>(typeof s === 'string' && s.endsWith('.js')) ? s : 'https://github.com/repalash/threepipe/tree/master/examples/'+ window.location.pathname.split('/examples/').pop().replace('index.html', '')+(s.textContent ? 'index.html' : s)), // todo: github link
  12. (c)=>c
  13. .replaceAll(" from 'threepipe'", " from 'https://threepipe.org/dist/index.mjs'")
  14. .replaceAll(" from '../", " from 'https://threepipe.org/examples/"),
  15. {
  16. title: 'ThreePipe: ' + document.title,
  17. css,
  18. },
  19. );