{"id":15018316,"url":"https://github.com/polymerelements/prism-element","last_synced_at":"2025-04-10T03:49:28.888Z","repository":{"id":30136910,"uuid":"33686986","full_name":"PolymerElements/prism-element","owner":"PolymerElements","description":"Prism-based syntax highlighting","archived":false,"fork":false,"pushed_at":"2025-03-10T23:46:16.000Z","size":259,"stargazers_count":17,"open_issues_count":13,"forks_count":19,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-03T02:09:08.914Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PolymerElements.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-09T19:02:05.000Z","updated_at":"2021-10-08T12:01:34.000Z","dependencies_parsed_at":"2024-06-18T15:16:37.310Z","dependency_job_id":"7eb9131c-0807-4cce-bf7b-0c8e62f47102","html_url":"https://github.com/PolymerElements/prism-element","commit_stats":{"total_commits":116,"total_committers":24,"mean_commits":4.833333333333333,"dds":0.7586206896551724,"last_synced_commit":"c6b8cc08b88f046abe1910ebb3023537e2ff4b4e"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerElements%2Fprism-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerElements%2Fprism-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerElements%2Fprism-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerElements%2Fprism-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PolymerElements","download_url":"https://codeload.github.com/PolymerElements/prism-element/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154995,"owners_count":21056542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:51:49.338Z","updated_at":"2025-04-10T03:49:28.866Z","avatar_url":"https://github.com/PolymerElements.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Published on NPM](https://img.shields.io/npm/v/@polymer/prism-element.svg)](https://www.npmjs.com/package/@polymer/prism-element)\n[![Build status](https://travis-ci.org/PolymerElements/prism-element.svg?branch=master)](https://travis-ci.org/PolymerElements/prism-element)\n[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://webcomponents.org/element/@polymer/prism-element)\n\n## \u0026lt;prism-highlighter\u0026gt;\n\nSyntax highlighting via [Prism](http://prismjs.com/).\n\nPlace a `\u003cprism-highlighter\u003e` in your document, preferably as a direct child of\n`\u003cbody\u003e`. It will listen for `syntax-highlight` events on its parent element,\nand annotate the code being provided via that event.\n\nThe `syntax-highlight` event's detail is expected to have a `code` property\ncontaining the source to highlight. The event detail can optionally contain a\n`lang` property, containing a string like `\"html\"`, `\"js\"`, etc.\n\nThis flow is supported by [`\u003cmarked-element\u003e`](https://github.com/PolymerElements/marked-element).\n\nSee: [Documentation](https://www.webcomponents.org/element/@polymer/prism-element),\n  [Demo](https://www.webcomponents.org/element/@polymer/prism-element/demo/demo/index.html).\n\n## Usage\n\n### Installation\n```\nnpm install --save @polymer/prism-element\n```\n\n### In an html file\n```html\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"parent\"\u003e\n      \u003cprism-highlighter\u003e\u003c/prism-highlighter\u003e\n      \u003cdiv id=\"output\"\u003e\u003c/div\u003e\n    \u003c/div\u003e\n  \u003c/body\u003e\n  \u003cscript type=\"module\"\u003e\n      import '@polymer/prism-element/prism-highlighter.js';\n      import '@polymer/prism-element/prism-theme-default.js';\n      import '@polymer/polymer/lib/elements/custom-style.js';\n      import {html} from '@polymer/polymer/lib/utils/html-tag.js';\n\n      // import prism theme styles\n      const template = html`\n        \u003ccustom-style\u003e\n          \u003cstyle include=\"prism-theme-default\"\u003e\u003c/style\u003e\n        \u003c/custom-style\u003e\n      `;\n\n      document.head.appendChild(template.contents);\n\n      const parent = document.getElementById('parent');\n      const output = document.getElementById('output');\n      const ev = new CustomEvent('syntax-highlight');\n\n      // enter code and language here\n      ev.detail = {\n        code: 'p { background-color: blue }',\n        lang: 'css',\n      };\n      parent.dispatchEvent(ev);\n\n      // detail is modified by prism-highlighter\n      output.innerHTML = ev.detail.code;\n    \u003c/script\u003e\n\u003c/html\u003e\n```\n### In a Polymer 3 element\n```js\nimport {PolymerElement, html} from '@polymer/polymer';\nimport '@polymer/prism-element/prism-element.js';\nimport '@polymer/prism-element/prism-highlighter.js';\nimport '@polymer/prism-element/prism-theme-default.js';\n\nclass SampleElement extends PolymerElement {\n  static get template() {\n    return html`\n      \u003cstyle include=\"prism-theme-default\"\u003e\u003c/style\u003e\n      \u003cdiv id=\"parent\"\u003e\n        \u003cprism-highlighter\u003e\u003c/prism-highlighter\u003e\n        \u003cdiv id=\"output\"\u003e\u003c/div\u003e\n      \u003c/div\u003e\n    `;\n  }\n\n  connectedCallback() {\n    super.connectedCallback();\n    const ev = new CustomEvent('syntax-highlight');\n\n    // enter code and language here\n    ev.detail = {\n      code: 'p { background-color: blue }',\n      lang: 'css',\n    };\n    this.$.parent.dispatchEvent(ev);\n\n    // detail is modified by prism-highlighter\n    this.$.output.innerHTML = ev.detail.code;\n  }\n}\ncustomElements.define('sample-element', SampleElement);\n```\n\n## Contributing\nIf you want to send a PR to this element, here are\nthe instructions for running the tests and demo locally:\n\n### Installation\n```sh\ngit clone https://github.com/PolymerElements/prism-element\ncd prism-element\nnpm install\nnpm install -g polymer-cli\n```\n\n### Running the demo locally\n```sh\npolymer serve --npm\nopen http://127.0.0.1:\u003cport\u003e/demo/\n```\n\n### Running the tests\n```sh\npolymer test --npm\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymerelements%2Fprism-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolymerelements%2Fprism-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymerelements%2Fprism-element/lists"}