-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ab89e0
commit acb88f1
Showing
21 changed files
with
124 additions
and
15 deletions.
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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Add new `<Code>` component, powered by the more modern shiki syntax highlighter. |
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
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
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,9 @@ | ||
--- | ||
import shiki from 'shiki'; | ||
const { code, lang = 'plaintext', theme = 'nord' } = Astro.props; | ||
const highlighter = await shiki.getHighlighter({theme}); | ||
const html = highlighter.codeToHtml(code, lang); | ||
--- | ||
{html} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as Markdown } from './Markdown.astro'; | ||
export { default as Prism } from './Prism.astro'; | ||
export { default as Code } from './Code.astro'; |
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,37 @@ | ||
import { suite } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { doc } from './test-utils.js'; | ||
import { setup, setupBuild } from './helpers.js'; | ||
|
||
const Components = suite('<Code>'); | ||
|
||
setup(Components, './fixtures/astro-component-code'); | ||
|
||
Components('<Code> without lang or theme', async ({ runtime }) => { | ||
let result = await runtime.load('/no-lang'); | ||
assert.ok(!result.error, `build error: ${result.error}`); | ||
const $ = doc(result.contents); | ||
assert.equal($('pre').length, 1); | ||
assert.equal($('pre').attr('style'), 'background-color: #2e3440ff', 'applies default theme'); | ||
assert.equal($('pre > code').length, 1); | ||
assert.ok($('pre > code span').length > 1, 'contains some generated spans'); | ||
}); | ||
|
||
Components('<Code lang="...">', async ({ runtime }) => { | ||
let result = await runtime.load('/basic'); | ||
assert.ok(!result.error, `build error: ${result.error}`); | ||
const $ = doc(result.contents); | ||
assert.equal($('pre').length, 1); | ||
assert.equal($('pre > code').length, 1); | ||
assert.ok($('pre > code span').length > 6, 'contains many generated spans'); | ||
}); | ||
|
||
Components('<Code theme="...">', async ({ runtime }) => { | ||
let result = await runtime.load('/custom-theme'); | ||
assert.ok(!result.error, `build error: ${result.error}`); | ||
const $ = doc(result.contents); | ||
assert.equal($('pre').length, 1); | ||
assert.equal($('pre').attr('style'), 'background-color: #1E1E1E', 'applies custom theme'); | ||
}); | ||
|
||
Components.run(); |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/astro-component-code/snowpack.config.json
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,3 @@ | ||
{ | ||
"workspaceRoot": "../../../../../" | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/astro-component-code/src/pages/basic.astro
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,9 @@ | ||
--- | ||
import {Code} from 'astro/components'; | ||
--- | ||
<html> | ||
<head><title>Code component</title></head> | ||
<body> | ||
<Code code="console.log('hello world');" lang="js" /> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/astro-component-code/src/pages/custom-theme.astro
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,9 @@ | ||
--- | ||
import {Code} from 'astro/components'; | ||
--- | ||
<html> | ||
<head><title>Code component</title></head> | ||
<body> | ||
<Code code="console.log('hello world');" lang="js" theme="dark-plus" /> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/astro-component-code/src/pages/no-lang.astro
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,9 @@ | ||
--- | ||
import {Code} from 'astro/components'; | ||
--- | ||
<html> | ||
<head><title>Code component</title></head> | ||
<body> | ||
<Code code="console.log('hello world');" /> | ||
</body> | ||
</html> |
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