Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update documentation for auto-start and prism.ts#3885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
robert-j-webb wants to merge1 commit intoPrismJS:v2
base:v2
Choose a base branch
Loading
fromrobert-j-webb:rob/start-docs

Conversation

@robert-j-webb
Copy link
Collaborator

No description provided.

@netlify
Copy link

netlifybot commentedApr 3, 2025
edited
Loading

Deploy Preview fordev-prismjs-com ready!

NameLink
🔨 Latest commitecc9f67
🔍 Latest deploy loghttps://app.netlify.com/sites/dev-prismjs-com/deploys/67ef007ba630e9000894fb93
😎 Deploy Previewhttps://deploy-preview-3885--dev-prismjs-com.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to yourNetlify site configuration.

@github-actions
Copy link

No JS Changes

Generated by 🚫dangerJS againstecc9f67

Comment on lines +169 to +171
* prism.highlight('var foo = true;', 'javascript')
* // Returns:
* `<span class="token keyword">var</span> foo <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I wonder if it makes sense also to use modern JS in examples, like here, to uselet instead ofvar?

* empty Prism object into the global scope before the Prism script loads like this:
*
* ```js
* window.Prism = window.Prism || {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do we still rely onwindow? Shouldn't we useglobalThis here or something?

LeaVerou reacted with thumbs up emoji
*
* or you can set `data-manual` on the script tag used to load PrismJs:
* ```html
* <script src="prism.js" data-manual></script>
Copy link
Member

@DmitrySharabinDmitrySharabinApr 4, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It feels like examples of that kind depend on what Prism would look like in v2. I thought it should become ESM-first, no?

So it should be either<script src="prism.js" type="module" data-manual></script> or<script src="prism.mjs" data-manual></script>. Or something similar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can’t get a reference to the script element that triggered loading in ESM. It would need to be an attribute placed anywhere (eg data-prism-manual) or we’d key on the fil name or we’d also support non-ESM imports (by having an entry point that uses dynamic import to load everything else). Or all of the above 😀

DmitrySharabin reacted with thumbs up emoji
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a really good point, I'll try redoing the examples as an actual 3rd party project instead of doing it locally

*@returns The highlighted HTML.
*@example
* Prism.highlight('var foo = true;', 'javascript');
* import { Prism } from './src/core/prism';
Copy link
Member

@DmitrySharabinDmitrySharabinApr 4, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I might miss some essential things, but shouldn't those imports be ”shorter“ (if I could say so)? Like,import Prism, { Token } from "prismjs",import javascript from "prismjs/languages". Is this something we should fix inpackage.json? Do I understand correctly that we use these examples to show how to use Prism as an NPM package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

On a higher leve, these are meant to be small snippets, not full code examples. I think it’s ok if this doesn’t include the import code, which is different depending on tooling/env.

DmitrySharabin reacted with thumbs up emoji
Comment on lines +208 to +221
* import { Token } from './src/core';
* import { Prism } from './src/core/prism';
* import javascript from './src/languages/prism-javascript';
*
* const prism = new Prism();
* prism.components.add(javascript);
*
* const tokens = prism.tokenize(`var foo = 0;`, prism.components.getLanguage('javascript')!);
* tokens.forEach((token: Token | string) => {
* if (token instanceof Token && token.type === 'number') {
* console.log(`Found numeric literal: ${token.content}`);
* }
* });
* // Logs: Found numeric literal: 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd mark it as a code block (```ts in this case). That way, TypeDoc will know this snippet should be highlighted appropriately.

* const prism = new Prism();
* prism.components.add(javascript);
*
* const tokens = prism.tokenize(`var foo = 0;`, prism.components.getLanguage('javascript')!);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit, why not single quotes here instead of ` and `?

* ```
*
*@default false
*@public
Copy link
Member

@DmitrySharabinDmitrySharabinApr 4, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd remove it. If I'm not mistaken, the property visibility is already described in the code (if not specified, it's public by default). TypeDoc alsomentions that this tag is redundant (and not desirable). And the result TypeDoc produces is not that good:
image

LeaVerou reacted with thumbs up emoji
* <script src="prism.js" data-manual></script>
* ```
*
*@default false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

By the way, we have options here. Either use@default and get
image

Or we can use the TypeDoc@defaultValue and get the result I find a bit more readable
image

Comment on lines +165 to +171
* import { Prism } from './src/core/prism';
* import javascript from './src/languages/prism-javascript';
* const prism = new Prism();
* prism.components.add(javascript);
* prism.highlight('var foo = true;', 'javascript')
* // Returns:
* `<span class="token keyword">var</span> foo <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>`
Copy link
Member

@DmitrySharabinDmitrySharabinApr 4, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think

* ```js* import { Prism } from './src/core/prism';* import javascript from './src/languages/prism-javascript';* const prism = new Prism();* prism.components.add(javascript);* prism.highlight('var foo = true;', 'javascript')* ```* Returns:* ```html* <span>var</span> foo <span>=</span> <span>true</span><span>;</span>* ```

produces a slightly better result
image

What do you think?

Copy link
Member

@LeaVerouLeaVerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hi there, thanks for working on this! I left some comments, and I see Dmitry did too. The most important one I think is that code examples above functions don’t need to be complete with imports etc, especially since import code differs by environment (eg build tools or no build tools, JS vs TS, etc).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@DmitrySharabinDmitrySharabinDmitrySharabin left review comments

@LeaVerouLeaVerouLeaVerou requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@robert-j-webb@LeaVerou@DmitrySharabin

[8]ページ先頭

©2009-2025 Movatter.jp