-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: Added the ability to add custom themes/languages to Shiki #2518
Merged
Merged
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d295815
Replaced `shikiTheme` with `shikiConfig`
JuanM04 f703715
Code.astro now accepts custom themes/langs
JuanM04 5874e38
Updated docs
JuanM04 273fbeb
Updated tests
JuanM04 948de06
Fixed language loading
JuanM04 415e403
Added customization examples
JuanM04 27be244
Updated documentation
JuanM04 030cb64
Added more tests
JuanM04 d2677f0
Changelogs
JuanM04 5ab34b8
Changed some spaces to tabs
JuanM04 0ded936
Merge branch 'main' into shiki-config
JuanM04 d318359
Fixed typo in changesets
JuanM04 63972e4
Moved tests fixtures
JuanM04 993e988
Rolled back changes to with-markdown-shiki
JuanM04 ef1873e
Removed lang example in docs
JuanM04 ffbe290
Merge branch 'main' into shiki-config
JuanM04 034f974
Optimized Code component
JuanM04 bb1fa19
Try to fix windows errors
JuanM04 af8e6c8
Merge branch 'main' into shiki-config
JuanM04 321a468
Try to see if this new tests work
JuanM04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'astro': patch | ||
'@astrojs/markdown-remark': patch | ||
--- | ||
|
||
Added the ability to use custom themes and langs with Shiki (`<Code />` and `@astrojs/markdown-remark`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/markdown-remark': patch | ||
--- | ||
|
||
Added `wrap` to Shiki config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
import Layout from '../layouts/main.astro' | ||
import {Code} from 'astro/components' | ||
|
||
import riGrammar from '../shiki/ri.tmLanguage.json' | ||
import serendipity from '../shiki/serendipity-morning.json' | ||
|
||
const rinfo = { | ||
id: 'rinfo', | ||
scopeName: 'source.rinfo', | ||
grammar: riGrammar, | ||
aliases: ['ri'], | ||
} | ||
|
||
const rinfoCode = ` | ||
programa Rinfo | ||
areas | ||
ciuadad: AreaC(1,1,100,100) | ||
robots | ||
robot robot1 | ||
comenzar | ||
Informar(PosAv, PosCa) | ||
fin | ||
variables | ||
Rinfo: robot1 | ||
comenzar | ||
AsignarArea(Rinfo, ciudad) | ||
Iniciar(Rinfo, 1, 1) | ||
fin | ||
`.trim() | ||
--- | ||
|
||
<Layout content={{}}> | ||
<h1>Customizations</h1> | ||
|
||
<Code code="console.log('Hello from GitHub Dark')" lang="js" /> | ||
<Code code="console.log('Hello from GitHub Light')" lang="js" theme="github-light" /> | ||
<Code code="console.log('Hello from Serendipity')" lang="js" theme={serendipity} /> | ||
<Code code={rinfoCode} lang={rinfo} theme="github-light" /> | ||
<Code code={rinfoCode} lang={rinfo} theme={serendipity} /> | ||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"name": "rinfo", | ||
"patterns": [{ "include": "#lf-rinfo" }], | ||
"repository": { | ||
"lf-rinfo": { | ||
"patterns": [{ "include": "#control" }, { "include": "#operator" }, { "include": "#strings" }, { "include": "#number" }, { "include": "#comment" }, { "include": "#literal" }] | ||
}, | ||
"control": { | ||
"patterns": [ | ||
{ | ||
"name": "keyword.control.ri", | ||
"match": "\\b(si|mientras|repetir)\\b" | ||
}, | ||
{ | ||
"name": "keyword.other.ri", | ||
"match": "\\b(programa|robots|areas|variables|comenzar|fin)\\b" | ||
}, | ||
{ | ||
"name": "support.function.other.ri", | ||
"match": "\\b(tomarFlor|HayFlorEnLaBolsa|HayFlorEnLaEsquina|depositarFlor|HayPapelEnLaBolsa|HayPapelEnLaEsquina|tomarPapel|depositarPapel)\\b" | ||
} | ||
] | ||
}, | ||
"operator": { | ||
"comment": "Captures operators and also puts them in different sub-groups that further describe them", | ||
"patterns": [ | ||
{ | ||
"match": "\\+|-|\\*|/", | ||
"name": "keyword.operator.arithmetic.ri" | ||
}, | ||
{ | ||
"match": "<|>|<=|>=|=|<>|!=", | ||
"name": "keyword.operator.comparison.ri" | ||
}, | ||
{ | ||
"match": "\\b(Pos|Informar|Leer|Iniciar|AsignarArea|AreaC)\\b", | ||
"name": "support.function.arithmetic.ri" | ||
}, | ||
{ | ||
"match": ":=", | ||
"name": "keyword.operator.assign.ri" | ||
}, | ||
{ | ||
"match": "(&|~)", | ||
"name": "support.function.logical.ri" | ||
} | ||
] | ||
}, | ||
"strings": { | ||
"name": "string.quoted.double.ri", | ||
"beginCaptures": { "0": { "name": "string.quoted.double.begin.ri" } }, | ||
"endCaptures": { "0": { "name": "string.quoted.double.end.ri" } }, | ||
"begin": "\"", | ||
"end": "\"", | ||
"patterns": [ | ||
{ | ||
"name": "constant.character.escape.ri", | ||
"match": "\\\\." | ||
} | ||
] | ||
}, | ||
"comment": { | ||
"patterns": [ | ||
{ | ||
"name": "comment.block.ri", | ||
"begin": "{", | ||
"end": "}", | ||
"patterns": [{ "include": "#comment" }] | ||
} | ||
] | ||
}, | ||
"literal": { | ||
"patterns": [ | ||
{ | ||
"name": "constant.language.ri", | ||
"match": "\\b(verdadero|falso|boolean|numero)\\b" | ||
} | ||
] | ||
}, | ||
"number": { | ||
"patterns": [ | ||
{ | ||
"comment": "Captures decimal numbers, with the negative sign being considered an operator", | ||
"match": "(-)?(?:((?:\\b\\d+(?:\\.\\d*)?|\\.\\d+)(?:\\b|e-?\\d+\\b)%?)|(\\$[0-9]+\\b))", | ||
"captures": { | ||
"1": { "name": "keyword.operator.arithmetic.ri" }, | ||
"2": { "name": "constant.numeric.decimal.ri" }, | ||
"3": { "name": "constant.numeric.hex.ri" } | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"scopeName": "source.rinfo" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels like a really advanced case, I feel like most users just want to change the theme, and not add a custom lang. I'd recommend removing all changes from this example.
If you wanted to mention something about this, you could maybe instead link to the docs with something like:
{ syntaxHighlight: 'shiki', shikiTheme: 'dracula', + // full documentation: ASTRO_DOCS_URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good appreciation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the changes. What do you think about them?