Skip to content

Commit

Permalink
refactor!: remove deprecated APIs (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Jan 14, 2024
1 parent c057395 commit 97c9636
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 56 deletions.
3 changes: 2 additions & 1 deletion packages/shikiji-compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const BUNDLED_THEMES = bundledThemes
export * from './stub'
export * from './types'

export { toShikiTheme } from 'shikiji'
export { normalizeTheme } from 'shikiji'
export { normalizeTheme as toShikiTheme } from 'shikiji'

export async function getHighlighter(options: HighlighterOptions = {}) {
const themes = options.themes || []
Expand Down
4 changes: 2 additions & 2 deletions packages/shikiji-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export * from './utils'
export * from './types'

export { loadWasm } from './oniguruma'
export { getShikiInternal, getShikiContext } from './internal'
export { getShikiInternal } from './internal'
export { codeToThemedTokens } from './tokenizer'
export { tokenizeAnsiWithTheme } from './tokenizer-ansi'
export { codeToHast } from './renderer-hast'
export { codeToHtml } from './renderer-html'
export { codeToTokensWithThemes } from './renderer-html-themes'
export { normalizeTheme, toShikiTheme } from './normalize'
export { normalizeTheme } from './normalize'
5 changes: 0 additions & 5 deletions packages/shikiji-core/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,3 @@ export async function getShikiInternal(options: HighlighterCoreOptions = {}): Pr
loadTheme,
}
}

/**
* @deprecated Use `getShikiInternal` instead.
*/
export const getShikiContext = getShikiInternal
5 changes: 0 additions & 5 deletions packages/shikiji-core/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,3 @@ export function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistratio

return theme
}

/**
* @deprecated Use `normalizeTheme` instead.
*/
export const toShikiTheme = normalizeTheme
6 changes: 0 additions & 6 deletions packages/shikiji-core/src/renderer-hast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ export function tokensToHast(
transformers = [],
} = options

// TODO: remove this in next major version
if (options.transforms) {
transformers.push(options.transforms)
console.warn('[shikiji] `transforms` option is deprecated, use `transformers` instead')
}

if (mergeWhitespaces === true)
tokens = mergeWhitespaceTokens(tokens)
else if (mergeWhitespaces === 'never')
Expand Down
5 changes: 0 additions & 5 deletions packages/shikiji-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,6 @@ export interface TransformerOptions {
* Transformers for the Shikiji pipeline.
*/
transformers?: ShikijiTransformer[]

/**
* @deprecated use `transformers` instead
*/
transforms?: ShikijiTransformer
}

export type CodeToHastOptions<Languages extends string = string, Themes extends string = string> =
Expand Down
1 change: 0 additions & 1 deletion packages/shikiji-twoslash/src/renderer-rich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export function rendererRich(options: RendererRichOptions = {}): TwoSlashRendere
...shikijiOptions,
lang: options.lang || shikijiOptions.lang,
transformers: [],
transforms: undefined,
}).children[0] as Element).children[0] as Element).children

if (jsdoc && info.docs) {
Expand Down
29 changes: 0 additions & 29 deletions packages/shikiji/test/hast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,6 @@ describe('should', () => {
<span class="line"><span style="color:#B07D48">foo</span><span style="color:#999999">.</span><span style="color:#B07D48">bar</span></span></code></pre>"
`)
})

it('hast transformer', async () => {
const warn = vi.spyOn(console, 'warn')
warn.mockImplementation((() => {}) as any)

const code = await codeToHtml('foo\bar', {
lang: 'js',
theme: 'vitesse-light',
// Use deprecated `transforms` option on purpose to test
transforms: {
line(node, line) {
node.properties['data-line'] = line
},
code(node) {
node.properties.class = 'language-js'
},
token(node, line, col) {
node.properties.class = `token:${line}:${col}`
},
},
})

expect(code)
.toMatchInlineSnapshot(`"<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34" tabindex="0"><code class="language-js"><span class="line" data-line="1"><span style="color:#B07D48" class="token:1:0">foo</span><span style="color:#393A34" class="token:1:3"></span><span style="color:#B07D48" class="token:1:4">ar</span></span></code></pre>"`)

expect(warn).toBeCalledTimes(1)
expect(warn.mock.calls[0][0])
.toMatchInlineSnapshot('"[shikiji] `transforms` option is deprecated, use `transformers` instead"')
})
})

it('hasfocus support', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function rendererFloatingVue(options: VitePressPluginTwoSlashOptions & Re
{
...this.options,
transformers: [],
transforms: undefined,
},
).children[0] as Element).children as Element[]

Expand All @@ -56,7 +55,6 @@ export function rendererFloatingVue(options: VitePressPluginTwoSlashOptions & Re
{
...this.options,
transformers: [],
transforms: undefined,
lang,
},
).children[0] as Element
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"shikiji/wasm": ["./packages/shikiji/src/wasm.ts"],
"shikiji/langs": ["./packages/shikiji/src/langs.ts"],
"shikiji/themes": ["./packages/shikiji/src/themes.ts"],
"shikiji/bundle/web": ["./packages/shikiji/src/bundle-web.ts"],
"shikiji/bundle/full": ["./packages/shikiji/src/bundle-full.ts"],
"shikiji": ["./packages/shikiji/src/index.ts"],
"markdown-it-shikiji": ["./packages/markdown-it-shikiji/src/index.ts"]
},
Expand Down

0 comments on commit 97c9636

Please sign in to comment.