Skip to content

Commit

Permalink
feat: upgrade to vscode-textmate-v7. fix #343
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Sep 21, 2022
1 parent ce37e92 commit c49c2fe
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 9,009 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ test(`SVG renderer should ignore minimal background width when it's own boundari
})

const out = (await r).renderToSVG([[{ content: 'foo', color: '#aabbccff' }]])
expect(out).toContain(`<svg viewBox="0 0 156.4921875 `)
expect(out).toContain(`<svg viewBox="0 0 150 `)
// expect(out).toMatchSnapshot()
})
2 changes: 1 addition & 1 deletion packages/shiki/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"jsonc-parser": "^3.0.0",
"vscode-oniguruma": "^1.6.1",
"vscode-textmate": "^6.0.0"
"vscode-textmate": "^7.0.1"
},
"devDependencies": {
"@types/node": "^14.17.7"
Expand Down
12 changes: 12 additions & 0 deletions packages/shiki/src/__tests__/custom-fonts/font-bold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tokenColors": [
{
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#ffffff",
"fontStyle": "bold"
}
}
]
}
12 changes: 12 additions & 0 deletions packages/shiki/src/__tests__/custom-fonts/font-italic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tokenColors": [
{
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#ffffff",
"fontStyle": "italic"
}
}
]
}
11 changes: 11 additions & 0 deletions packages/shiki/src/__tests__/custom-fonts/font-none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tokenColors": [
{
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#ffffff"
}
}
]
}
47 changes: 47 additions & 0 deletions packages/shiki/src/__tests__/fontStyle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path'
import { getHighlighter, loadTheme } from '../index'

test('No font-style is applied if none is specified', async () => {
const fNone = await loadTheme(path.resolve(__dirname, './custom-fonts/font-none.json'))
const highlighter = await getHighlighter({
theme: fNone,
langs: ['js']
})
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).not.toContain('font-style:')
})

test('An italic font-style is applied if specified', async () => {
const fItalic = await loadTheme(path.resolve(__dirname, './custom-fonts/font-italic.json'))
const highlighter = await getHighlighter({
theme: fItalic,
langs: ['js']
})
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).toContain('font-style: italic')
})

test('A bold font-style is applied if specified', async () => {
const fBold = await loadTheme(path.resolve(__dirname, './custom-fonts/font-bold.json'))
const highlighter = await getHighlighter({
theme: fBold,
langs: ['js']
})
// console.log(JSON.stringify(highlighter.codeToThemedTokens(`function() {return 1}`, 'js'), null, 2))
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).toContain('font-weight: bold')
})

test('A bold fontStyle should not apply an italic font-style', async () => {
const fBold = await loadTheme(path.resolve(__dirname, './custom-fonts/font-bold.json'))
const highlighter = await getHighlighter({
theme: fBold,
langs: ['js']
})
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).not.toContain('font-style: italic')
})
Loading

0 comments on commit c49c2fe

Please sign in to comment.