Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ Thumbs.db

# Generated files
*.html
!examples/*.html
api
plugins
components.json
file-sizes.json
_redirects

# Cache
.cache

# Local Netlify folder
# Local Netlify folders and files
.netlify
deno.lock
2 changes: 1 addition & 1 deletion README.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"layout": "home.njk",
"resources": ["plugins/keep-markup/prism-keep-markup.js", "https://dev.prismjs.com/components/prism-bash.js"]
"resources": ["/plugins/keep-markup.js { type=module }", "/languages/bash.js { type=module }"]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Prism is used on several websites, small and large. Some of them are:
# Examples

The Prism source, highlighted with Prism (don’t you just love how meta this is?):
<pre data-src="https://dev.prismjs.com/prism.js"></pre>
<pre data-src="https://v2.dev.prismjs.com/src/core/prism.js"></pre>

This page’s CSS code, highlighted with Prism:

Expand Down Expand Up @@ -56,7 +56,7 @@ If you’re still not sold, you can [view more examples](examples.html) or [try
- Highlights embedded languages (e.g. CSS inside HTML, JavaScript inside HTML).
- Highlights inline code as well, not just code blocks.
- It doesn’t force you to use any Prism-specific markup, not even a Prism-specific class name, only standard markup you should be using anyway. So, you can just try it for a while, remove it if you don’t like it and leave no traces behind.
- Highlight specific lines and/or line ranges (requires [plugin](plugins/line-highlight/)).
- Highlight specific lines and/or line ranges (requires [plugin](plugins/line-highlight/index.html)).
- Show invisible characters like tabs, line breaks etc (requires [plugin](plugins/show-invisibles/)).
- Autolink URLs and emails, use Markdown links in comments (requires [plugin](plugins/autolinker/)).

Expand Down Expand Up @@ -221,7 +221,7 @@ This is the list of all {{ languages | length }} languages currently supported b
<ul id="languages-list">
{% for id, language in languages -%}
<li data-id="{{ id }}">
{{ language.title }}&nbsp;—
{{ language.title }}&nbsp;—
{%- for alias in language.alias -%}
<code>{{ alias }}</code>{{ ", " if not loop.last }}
{%- endfor %}
Expand Down
5 changes: 2 additions & 3 deletions _build/copy-plugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ async function copy () {
continue;
}

let name = path.parse(file.name).name;
// Copy only the README.md and demo.* files
if (["README", "demo"].includes(name)) {
let filename = path.parse(file.name).base;
if (["README.md", "demo.md"].includes(filename)) {
await fs.copyFile(path.join(source, file.name), path.join(dest, file.name));
}
}
Expand Down
4 changes: 3 additions & 1 deletion _build/eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import markdownItDeflist from "markdown-it-deflist";
import pluginTOC from "eleventy-plugin-toc";
import * as filters from "./filters.js";

import components from "../node_modules/prismjs/src/components.json" with { type: "json" };
import components from "../components.json" with { type: "json" };
import file_sizes from "../file-sizes.json" with { type: "json" };

/** @param {import("@11ty/eleventy").UserConfig} config */
export default config => {
let data = {
components,
file_sizes,
layout: "page.njk",
theme_switcher: true,
toc: true,
Expand Down
96 changes: 96 additions & 0 deletions _build/postinstall.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
import { execSync } from "child_process";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const root = path.resolve(__dirname, "../node_modules");
const prismPath = path.join(root, "prismjs");

let sourcePath, destPath;

// --- Cloning & Installing Prism ---
console.log("[postinstall] Cloning Prism...");
// Ensure we work with a fresh copy
await fs.rm(prismPath, { recursive: true, force: true });
execSync("git clone https://github.com/PrismJS/prism.git prismjs", {
cwd: root,
stdio: "inherit",
});

console.log("[postinstall] Installing Prism dependencies...");
execSync("npm install", {
cwd: prismPath,
stdio: "inherit",
});

console.log("[postinstall] Building Prism...");
execSync("npm run build", {
cwd: prismPath,
stdio: "inherit",
});

// --- Working with plugins ---
sourcePath = path.join(prismPath, "src/plugins");
destPath = path.resolve(__dirname, "../plugins");

async function copy () {
// We need { recursive: true } so the script doesn't fail if the folder already exists
await fs.mkdir(destPath, { recursive: true });

let plugins = await fs.readdir(sourcePath, { withFileTypes: true });
for (let plugin of plugins) {
if (!plugin.isDirectory()) {
continue;
}

let source = path.join(sourcePath, plugin.name);
let dest = path.join(destPath, plugin.name);
await fs.mkdir(dest, { recursive: true });

let files = await fs.readdir(source, { withFileTypes: true });
for (let file of files) {
if (!file.isFile()) {
continue;
}

let filename = path.parse(file.name).base;
if (["README.md", "demo.md"].includes(filename)) {
await fs.copyFile(path.join(source, file.name), path.join(dest, file.name));
}
}
}
}

console.log("[postinstall] Copying Prism plugins docs...");
try {
await copy();
}
catch (error) {
console.error(`[postinstall] Failed to copy Prism plugins docs: ${error.message}`);
}

// Create plugins.json in the plugins folder with global data
console.log("[postinstall] Creating plugins.json...");
let json = {
permalink: "{{ page.filePathStem.replace('README', '/index') }}.html",
tags: ["plugin"],
};

await fs.writeFile(path.join(destPath, "plugins.json"), JSON.stringify(json, null, "\t"));

// --- Copying other files (components.json, file-sizes.json, etc.) ---
sourcePath = path.join(prismPath, "dist");
destPath = path.resolve(__dirname, "..");

let filenames = ["components.json", "file-sizes.json"];
for (let file of filenames) {
console.log(`[postinstall] Copying ${file}...`);
try {
await fs.copyFile(path.join(sourcePath, file), path.join(destPath, file));
}
catch (error) {
console.error(`[postinstall] Failed to copy ${file}: ${error.message}`);
}
}
13 changes: 3 additions & 10 deletions _data/eleventyComputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {

for (let id in languages) {
let ret = [id];
let alias = languages[id].alias;
let alias = Object.keys(languages[id].aliasTitles ?? {});
if (alias) {
ret = ret.concat(Array.isArray(alias) ? alias : [alias]);
}
Expand Down Expand Up @@ -59,19 +59,12 @@ export default {
}

// We are working with plugin resources
ret.push(`./prism-${id}.js { type="module" }`);
ret.push(`/plugins/${id}.js { type="module" }`);

if (!data.noCSS) {
ret.push(`./prism-${id}.css`);
ret.push(`/plugins/${id}.css`);
}

return ret;
},
files_sizes (data) {
let ret = {};
for (let file of data.tree) {
ret[file.path] = file.size;
}
return ret;
},
};
14 changes: 0 additions & 14 deletions _data/tree.js

This file was deleted.

5 changes: 3 additions & 2 deletions _layouts/page.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<meta charset="utf-8" />
<link rel="icon" href="{{ base_url }}/assets/logo.svg" />
<link rel="stylesheet" href="{{ base_url }}/assets/style.css" />
<link rel="stylesheet" href="https://dev.prismjs.com/themes/prism.css" />
<link rel="stylesheet" href="/themes/prism.css" />
<script>var _gaq = [["_setAccount", "UA-33746269-1"], ["_trackPageview"]];</script>
<script src="https://www.google-analytics.com/ga.js" async></script>

Expand Down Expand Up @@ -89,7 +89,8 @@
</nav>
</footer>

<script src="https://dev.prismjs.com/prism.js"></script>
<script src="https://v2.dev.prismjs.com/dist/prism.js"></script>
<script src="/plugins/file-highlight.js" type="module"></script>
{% if theme_switcher -%}
<script src="{{ base_url }}/assets/theme-switcher.js" type="module"></script>
{%- endif %}
Expand Down
12 changes: 0 additions & 12 deletions _redirects

This file was deleted.

22 changes: 22 additions & 0 deletions _redirects.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
permalink: _redirects
layout: null
eleventyExcludeFromCollections: true
---

# Themes and languages
/themes/:file https://v2.dev.prismjs.com/dist/themes/:file 301
/languages/:file https://v2.dev.prismjs.com/dist/languages/:file 301

# Plugins
{% for plugin in collections.plugin -%}
{%- set id = plugin.data.id -%}
/plugins/{{ id }}.js https://v2.dev.prismjs.com/dist/plugins/{{ id }}.js 301
/plugins/{{ id }}/{{ id }}.js https://v2.dev.prismjs.com/src/plugins/{{ id }}/{{ id }}.js 301
{% if not meta.noCSS -%}
/plugins/{{ id }}.css https://v2.dev.prismjs.com/dist/plugins/{{ id }}.css 301
/plugins/{{ id }}/{{ id }}.css https://v2.dev.prismjs.com/src/plugins/{{ id }}/{{ id }}.css 301
{% endif -%}
{% endfor -%}
/plugins/:plugin/demo.js https://v2.dev.prismjs.com/dist/plugins/:plugin/demo.js 301
/plugins/:plugin/demo.css https://v2.dev.prismjs.com/dist/plugins/:plugin/demo.css 301
Loading