-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Syntax Highlighting for Code Blocks and Inline Code #5895
Comments
Some mention of it already here and later in the thread: https://bsky.app/profile/ryanskinner.com/post/3l7teiwotse2q |
Let me know if you need any help on adopting to Shiki :) |
@antfu I did some digging, and it looks like the incompatibility with React Native is due to the use of RegExp's would love to hear your thoughts on potential solutions—perhaps adding a fallback/simulation mechanism for environments without |
Uhm, I see. The |
unfortunately no WASM support natively in React Native. C binary is definitely possible and I believe that would allow for the use of Oniguruma directly |
The interface of the engine would look like this: Basically it's a single Here are the implementation of WASM oniguruma: https://github.com/shikijs/shiki/blob/93246cdbd1b9f0c170f4e5db551f11ced03bdfce/packages/engine-oniguruma/src/oniguruma/index.ts#L318-L339 I'd be happy to help if you have any questions on that |
shoot, another blocker. React Native's module bridge can only be asynchronous but RN's new architecture enables synchronous native module calls via JSI, but Bluesky isn't yet using the new architecture. however, there is a pre-release build (1.92.0-na-rc.2) with the new architecture enabled that I can use for testing this approach. |
It might not be a bad idea to submit an issue to the hermes team. I don’t know if the d flag is out of spec, but they will still support feature like that if other engines do. |
RegExp match indices are in the planned stage for hermes. |
in the unlikely event that you can't/won't use shiki, this options exists: font with builtin syntax highlighting: https://blog.glyphdrawing.club/font-with-built-in-syntax-highlighting/ |
Bluesky uses Babel, and Babel supports compiling the Maybe the build process just needs to be updated to transpile that dependency? |
@nicolo-ribaudo thanks for thinking about this! I think there might be some confusion though—the plugin you linked is for the // @shikijs/engine-javascript
function defaultJavaScriptRegexConstructor(pattern: string): RegExp {
return onigurumaToRegexp(
pattern,
{
flags: 'dgm',
ignoreContiguousAnchors: true,
},
)
} |
Oh yes, I was confused by the letter |
You may not even need regex for this. In fact, not doing it with regex might be more liberating. A finite state machine that processes the text character-by-character (while watching out for Unicode!) can match open-close patterns, which don't have to be limited to a fixed number of backticks (if you're thinking Markdown). This would make it easy to "escape" backticks inside code by using more backticks around it, just like in GFM:
|
The RegExp is to match tokens in the language inside the fenced block, without having to load full parsers. |
Fyi: posted from a previous issue |
Thanks @garfbradaz! Yeah, Paul's article perfectly explains why I think we should use code fence syntax but handle it as a Bluesky embed rather than markdown. Would give us familiar developer syntax with all the benefits of the embed system - no parsing overhead, clean implementation, elegant fallbacks... plus we could bypass char limits for code blocks. I've explored two approaches: As an embed (preferred): {
"text": "Here's a link facet:\n\n```typescript\nconst facet = {\n $type: 'app.bsky.richtext.facet',\n features: [{ uri: 'https://bsky.app' }]\n}\n```",
"embed": {
"$type": "app.bsky.embed.code",
"code": {
"content": "const facet = {\n $type: 'app.bsky.richtext.facet',\n features: [{ uri: 'https://bsky.app' }]\n}",
"lang": "typescript"
}
}
} As a facet: {
"text": "Here's a link facet:\n\n```typescript\nconst facet = {\n $type: 'app.bsky.richtext.facet',\n features: [{ uri: 'https://bsky.app' }]\n}\n```",
"facets": [{
"$type": "app.bsky.richtext.facet",
"index": { "byteStart": 23, "byteEnd": 89 },
"features": [{
"$type": "app.bsky.richtext.facet#code",
"content": "const facet = {\n $type: 'app.bsky.richtext.facet',\n features: [{ uri: 'https://bsky.app' }]\n}",
"lang": "typescript"
}]
}]
} |
This solution is now possible with React Native's New Architecture enabled and react-native-shiki-engine. |
Describe the Feature
Earlier today, @patak-dev made a post highlighting the importance of syntax highlighting, especially for developers sharing accessible code snippets rather than images. This feature would not only improve accessibility but would continue to foster a developer-friendly environment, promoting more experimentation with the protocol.
Here’s the original post:
@gaearon also expressed support for the idea, stating:
I am happy to contribute time to help work on this feature once a direction has been chosen.
Attachments
Here's the attachment from @patak-dev's post as an example:
Describe Alternatives
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: