Skip to content

Fix code using components.json #18

@DmitrySharabin

Description

@DmitrySharabin

It seems like the v2 branch doesn't have those files (and I don't see if they are generated either). So, before the launch, we need to fix the code where we use them:

import components from "prismjs/components.json" with { type: "json" };

let components = await (await fetch("https://dev.prismjs.com/components.json")).json();

let components = await (await fetch("https://dev.prismjs.com/components.json")).json();

let components = await (await fetch("https://dev.prismjs.com/components.json")).json();

website/benchmark.md

Lines 111 to 121 in b260bfb

components.json (25 kB)
| local 5.45ms ± 13% 138smp
| PrismJS@master 4.92ms ± 2% 145smp
| RunDevelopment@greedy-fix 5.62ms ± 4% 128smp
package-lock.json (189 kB)
| local 117.75ms ± 27% 27smp
| PrismJS@master 121.40ms ± 32% 29smp
| RunDevelopment@greedy-fix 190.79ms ± 41% 20smp
```
A case starts with its key (here `json`) and is followed by all of its files (here `components.json` and `package-lock.json`). Under each file, the results for local and all remotes are shown. To explain the meaning of the values, let's pick a single line:

**All language names must match the names from the definition in `components.json`.**

2. Edit [`components.json`](https://github.com/PrismJS/prism/blob/master/components.json) to register the new language by adding it to the `languages` object. (Please note that all language entries are sorted alphabetically by title.)

_Note:_ Any changes made to `components.json` require a rebuild (see step 3).

_Note:_ You have to reload the test page to apply changes made to `prism-foo-bar.js` but you don't have to rebuild Prism itself. However, if you change `components.json` (e.g. because you added a dependency) then these changes will not show up on the test page until you rebuild Prism.

Aliases also have to be registered in `components.json` by adding the `alias` property to the language entry. In this example, the updated entry will look like this:

You declare a dependency by adding a property to the entry of your language or plugin in the [`components.json`](https://github.com/PrismJS/prism/blob/master/components.json) file. The name of the property will be dependency kind and its value will be the component id of the dependee. If multiple languages or plugins are depended upon then you can also declare an array of component ids.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions