{"id":16768737,"url":"https://github.com/phptuts/svelte-prismjs","last_synced_at":"2025-07-09T21:34:13.109Z","repository":{"id":53498619,"uuid":"289571252","full_name":"phptuts/Svelte-PrismJS","owner":"phptuts","description":"Svelte Prism Plugin","archived":false,"fork":false,"pushed_at":"2024-05-31T22:31:33.000Z","size":190,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-26T00:32:15.530Z","etag":null,"topics":["plugins","prismjs","routify","sapper","svelte"],"latest_commit_sha":null,"homepage":"https://phptuts.github.io/Svelte-PrismJS/index.html","language":"Svelte","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/phptuts.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-22T21:39:35.000Z","updated_at":"2024-05-31T22:31:38.000Z","dependencies_parsed_at":"2024-05-31T23:35:40.004Z","dependency_job_id":"b3eded63-0628-4c3a-93a0-ab8e4dd4f4f1","html_url":"https://github.com/phptuts/Svelte-PrismJS","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/phptuts/Svelte-PrismJS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2FSvelte-PrismJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2FSvelte-PrismJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2FSvelte-PrismJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2FSvelte-PrismJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phptuts","download_url":"https://codeload.github.com/phptuts/Svelte-PrismJS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phptuts%2FSvelte-PrismJS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264503950,"owners_count":23618763,"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":["plugins","prismjs","routify","sapper","svelte"],"created_at":"2024-10-13T06:12:24.566Z","updated_at":"2025-07-09T21:34:13.086Z","avatar_url":"https://github.com/phptuts.png","language":"Svelte","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SvelteJS Prism\n\nThis package is a wrapper for PrismJS. It works with line numbers and whitespace clean up out of the box. You can enable other plugins and languages as well. It was inspired by [svelte-prism](https://github.com/jakobrosenberg/svelte-prism), another Svelte Prism package.\n\n[Live Svelte Demo](https://phptuts.github.io/Svelte-PrismJS/index.html)\n\nThe repo has the Svelte code to run the demo.\n\n[Sapper Example](https://github.com/phptuts/svelte-prismjs-sapper)\n\n[Routify Example](https://github.com/phptuts/routify-prismjs-example)\n\n## Features\n\n- Supports PrismJS plugins and data attributes being passed to the pre element.\n- Allows for client side loading in Sapper and Routify.\n- Supports code being changed dynamically in the Prism html element.\n- Examples and setup instructions.\n\n## Svelte Setup Instructions\n\n1. Run `npm install --save-dev svelte-prismjs`\n\n2. Load the css via CDN (if loading via CDN skip ahead to [Option B](https://github.com/Isaac-Tait/Svelte-PrismJS#option-b---cdn-links-to-copy-to-your-indexhtml)) or...\n\n3. `npm install rollup-plugin-css-only`\n\n### Rollup Config\n\n1. Import the css into your `main.js` file.\n\n```javascript\nimport \"prismjs/plugins/line-numbers/prism-line-numbers.css\";\nimport \"prismjs/plugins/command-line/prism-command-line.css\";\nimport \"prismjs/plugins/line-highlight/prism-line-highlight.css\";\n\nimport \"prismjs/themes/prism.css\";\nimport \"prismjs/themes/prism-coy.css\";\n```\n\n### Option B - CDN links to copy to your index.html\n\nBe sure to double check link integrity at [PRISM CDN](https://cdnjs.com/libraries/prism)\n\n```html\n\u003c!-- base theme --\u003e\n\u003clink\n  rel=\"stylesheet\"\n  href=\"https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism.min.css\"\n  integrity=\"sha512-tN7Ec6zAFaVSG3TpNAKtk4DOHNpSwKHxxrsiw4GHKESGPs5njn/0sMCUMl2svV4wo4BK/rCP7juYz+zx+l6oeQ==\"\n  crossorigin=\"anonymous\"\n/\u003e\n\u003c!-- coy theme --\u003e\n\u003clink\n  rel=\"stylesheet\"\n  href=\"https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism-coy.min.css\"\n  integrity=\"sha512-CKzEMG9cS0+lcH4wtn/UnxnmxkaTFrviChikDEk1MAWICCSN59sDWIF0Q5oDgdG9lxVrvbENSV1FtjLiBnMx7Q==\"\n  crossorigin=\"anonymous\"\n/\u003e\n\u003c!-- Number lines  --\u003e\n\u003clink\n  rel=\"stylesheet\"\n  href=\"https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/plugins/line-numbers/prism-line-numbers.min.css\"\n  integrity=\"sha512-cbQXwDFK7lj2Fqfkuxbo5iD1dSbLlJGXGpfTDqbggqjHJeyzx88I3rfwjS38WJag/ihH7lzuGlGHpDBymLirZQ==\"\n  crossorigin=\"anonymous\"\n/\u003e\n```\n\n## Sapper Instructions\n\n[Sapper Example](https://github.com/phptuts/svelte-prismjs-sapper)\n\n1. Run `npm install svelte-prismjs`\n\n2. You can either include the cdn links in your `template.html` file or you can install the `rollup-css-only-plugin`. It is basically what step 2 is for Svelte minus different directories. For Sapper be sure you put the file in the static folder.\n\n3. Import `Svelte-Prism` (*Because Prism uses the window object we have to do some weird stuff to get it work. For now here is the work around.*).\n\n```svelte\nlet Prism;\nonMount(async () =\u003e {\n    // Load the prismjs first after the page is loaded\n    const prismModule = await import(\"svelte-prismjs\");\n    await import(\"prismjs/components/prism-c.js\");\n    await import(\"prism-svelte\");\n\n    await import(\"prismjs/plugins/line-highlight/prism-line-highlight.js\");\n    await import(\"prismjs/plugins/file-highlight/prism-file-highlight.js\");\n    // Once everything is loaded load the prismjs module\n    Prism = prismModule.default;\n\n  });\n\n  \u003csvelte:component this={Prism}\u003e\n  {`let b = 3;\nfunction helloWorld() {\n\tconsole.log(\"Hello World\");\n}\n`}\n\u003c/svelte:component\u003e\n\n```\n\n## Routify Instructions\n\n[Routify Example](https://github.com/phptuts/routify-prismjs-example)\n\n1. Run `npm install svelte-prismjs`\n\n2. Go to `scripts/base.config.js` and add the `rollup-css-only-plugin` or go to the `static/\\_\\_index.html` file. If you do use npm to include css you will have to add it to `App.svelte` file under global styles.\n\n```svelte\nlet Prism;\nonMount(async () =\u003e {\n    // Load the prismjs first after the page is loaded\n    const prismModule = await import(\"svelte-prismjs\");\n    await import(\"prismjs/components/prism-c.js\");\n    await import(\"prism-svelte\");\n\n    await import(\"prismjs/plugins/line-highlight/prism-line-highlight.js\");\n    await import(\"prismjs/plugins/file-highlight/prism-file-highlight.js\");\n    // Once everything is loaded load the prismjs module\n    Prism = prismModule.default;\n\n  });\n\n  \u003csvelte:component this={Prism}\u003e\n  {`let b = 3;\nfunction helloWorld() {\n\tconsole.log(\"Hello World\");\n}\n`}\n\u003c/svelte:component\u003e\n\n```\n\n## Examples\n\n[Full Examples](https://phptuts.github.io/Svelte-Prism/)\n\n### Simple Example using the slot. Language will default to javascript.\n\n```html\n\u003cPrism\u003e\n  { `let b = 3; function helloWorld() { console.log(\"Hello World\"); } `}\n\u003c/Prism\u003e\n```\n\n## Example Language and line numbers and using the code prompt.\n\n```html\n\u003cPrism\n  showLineNumbers=\"{true}\"\n  language=\"c\"\n  code=\"{`int b= 3;\nint c=32;\n  `}\n/\u003e\n```\n\n## Props\n\n- code -\u003e (string) for passing code into the element. You can also pass the code between the elements because it uses a slot.\n- language -\u003e (string) Used the pass the language you are using. You will need to import the language if it is not included by default. Import this after you import the element, client side only. This is default to javascript.\n\n```javascript\nimport \"prismjs/components/prism-c.js\";\n```\n\n- showLineNumbers -\u003e (bool) Will turn on and off line numbers for your code. Defaulted to false.\n- normalizeWhiteSpace -\u003e (bool) Will clean up the white space in your code. This is default to true.\n- normalizeWhiteSpaceConfig -\u003e (object) Will be used to over ride the default config. For more information go [here](https://prismjs.com/plugins/normalize-whitespace/).\n- classes -\u003e custom css classes for the pre-element.\n- You can also pass any props or styles in the component and it will be applied to the pre-element.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphptuts%2Fsvelte-prismjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphptuts%2Fsvelte-prismjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphptuts%2Fsvelte-prismjs/lists"}