/* ********************************************** Begin prism-core.js ********************************************** */ /// var _self = (typeof window !== 'undefined') ? window // if in browser : ( (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) ? self // if in worker : {} // if in node js ); /** * Prism: Lightweight, robust, elegant syntax highlighting * * @license MIT * @author Lea Verou * @namespace * @public */ var Prism$1 = (function (_self){ // Private helper vars var lang = /\blang(?:uage)?-([\w-]+)\b/i; var uniqueId = 0; var _ = { /** * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load * additional languages or plugins yourself. * * By setting this value to `true`, Prism will not automatically highlight all code elements on the page. * * You obviously have to change this value before the automatic highlighting started. To do this, you can add an * empty Prism object into the global scope before loading the Prism script like this: * * ```js * window.Prism = window.Prism || {}; * Prism.manual = true; * // add a new * * * * The above example will create a
inside of itself * containing syntax-highlightable markup of the code in the template. It will * also create the content of the template as DOM and insert it into the node * indicated by the "stamp-to" attribute. The "stamp-to" attribute references * another node by its ID. * * Add the "lazy" boolean attribute if you want to stamp the example manually * by invoking its "stamp" method. Note that this will prevent the snippet from * stamping itself automatically upon being connected to the DOM. * * ExampleSnippet is a simplified alternative to Polymer Project's DemoSnippet. * The key differences are: * * - ExampleSnippet does not use ShadowDOM by default * - ExampleSnippet supports stamping demos to elements other than itself * * @see https://github.com/PolymerElements/iron-demo-helpers/blob/master/demo-snippet.js */ class ExampleSnippet extends UpdatingElement { constructor() { super(...arguments); this.useShadowRoot = false; this.stampTo = null; this.template = null; this.highlightAs = 'markup'; this.lazy = false; this.preserveWhitespace = false; this.inertScript = false; this.stamped = false; } stamp() { if (this.template == null) { return; } const root = this.getRootNode(); const stampTarget = this.stampTo == null ? this : root.getElementById(this.stampTo); if (stampTarget != null) { let parentNode; if (this.useShadowRoot) { if (stampTarget.shadowRoot == null) { stampTarget.attachShadow({ mode: 'open' }); } parentNode = stampTarget.shadowRoot; } else { parentNode = stampTarget; } const { template, highlightAs } = this; const content = template.content.cloneNode(true); if (this.inertScript) { const scripts = Array.from(content.querySelectorAll('script')); for (const script of scripts) { script.parentNode.removeChild(script); } } parentNode.appendChild(content); const pre = document.createElement('pre'); const code = document.createElement('code'); pre.appendChild(code); let snippet = template.innerHTML; snippet = snippet.replace('type="noexecute" ', ''); if (!this.preserveWhitespace) { snippet = snippet.trim(); } if (highlightAs === 'html') { snippet = snippet.replace(EMPTY_ATTRIBUTE_RE, '$1'); } const highlighted = Prism.highlight(snippet, Prism.languages[highlightAs], highlightAs); code.innerHTML = highlighted; this.appendChild(pre); } } connectedCallback() { super.connectedCallback && super.connectedCallback(); this.template = this.querySelector('template'); } createRenderRoot() { return this; } updated(changedProperties) { super.updated(changedProperties); if (!this.stamped && !this.lazy && (changedProperties.has('stamp-to') || changedProperties.has('template')) && this.template != null) { this.stamp(); } } } __decorate([ property({ type: Boolean, attribute: 'use-shadow-root' }) ], ExampleSnippet.prototype, "useShadowRoot", void 0); __decorate([ property({ type: String, attribute: 'stamp-to' }) ], ExampleSnippet.prototype, "stampTo", void 0); __decorate([ property({ type: Object }) ], ExampleSnippet.prototype, "template", void 0); __decorate([ property({ type: String, attribute: 'highlight-as' }) ], ExampleSnippet.prototype, "highlightAs", void 0); __decorate([ property({ type: Boolean, attribute: 'lazy' }) ], ExampleSnippet.prototype, "lazy", void 0); __decorate([ property({ type: Boolean }) ], ExampleSnippet.prototype, "preserveWhitespace", void 0); __decorate([ property({ type: Boolean, attribute: 'inert-script' }) ], ExampleSnippet.prototype, "inertScript", void 0); customElements.define('example-snippet', ExampleSnippet); export { ExampleSnippet };