Skip to content

Commit

Permalink
refactor!: remove all deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 6, 2024
1 parent df62d03 commit 1a39ff0
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 111 deletions.
13 changes: 0 additions & 13 deletions packages/core/src/bundle-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ export interface ShorthandsBundle<L extends string, T extends string> {
* @internal
*/
getSingletonHighlighter: () => Promise<HighlighterGeneric<L, T>>

/**
* @deprecated Use `codeToTokensBase` instead.
*/
codeToThemedTokens: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>
}

export function createSingletonShorthands<L extends string, T extends string >(getHighlighter: GetHighlighterFactory<L, T>): ShorthandsBundle<L, T> {
Expand Down Expand Up @@ -178,14 +173,6 @@ export function createSingletonShorthands<L extends string, T extends string >(g
return shiki.codeToTokensBase(code, options)
},

/**
* @deprecated Use `codeToTokensBase` instead.
*/
async codeToThemedTokens(code, options) {
const shiki = await _getHighlighter(options)
return shiki.codeToThemedTokens(code, options)
},

async codeToTokensWithThemes(code, options) {
const shiki = await _getHighlighter({
lang: options.lang,
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@ export async function getHighlighterCore(options: HighlighterCoreOptions = {}):
getLoadedLanguages: internal.getLoadedLanguages,

getInternalContext: () => internal,

/** @deprecated */
codeToThemedTokens: (code, options) => codeToTokensBase(internal, code, options),
}
}
8 changes: 0 additions & 8 deletions packages/core/src/types/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ export interface HighlighterGeneric<BundledLangKeys extends string, BundledTheme
options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>
) => ThemedTokenWithVariants[][]

/**
* @deprecated Renamed to `codeToTokensBase`, or use high-level `codeToTokens` directly.
*/
codeToThemedTokens: (
code: string,
options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>
) => ThemedToken[][]

/**
* Load a theme to the highlighter, so later it can be used synchronously.
*/
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/types/textmate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,4 @@ export type {
RawGrammar,
RawTheme,
RawThemeSetting,

/**
* @deprecated Renamed to `Grammar`
*/
Grammar as IGrammar,
/**
* @deprecated Renamed to `RawGrammar`
*/
RawGrammar as IRawGrammar,
}
21 changes: 0 additions & 21 deletions packages/core/src/types/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,4 @@ export interface ShikiTransformer {
* This hook will only be called with `codeToHtml`.
*/
postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void

// deprecated
/**
* @deprecated Use `span` instead
*/
token?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element) => Element | void
}

/**
* @deprecated Rnamed to `ShikiTransformer`
*/
export interface ShikijiTransformer extends ShikiTransformer {}

/**
* @deprecated Rnamed to `ShikiTransformerContext`
*/
export interface ShikijiTransformerContext extends ShikiTransformerContext {}

/**
* @deprecated Rnamed to `ShikiTransformerContextCommon`
*/
export interface ShikijiTransformerContextCommon extends ShikiTransformerContextCommon {}
5 changes: 0 additions & 5 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ export function applyColorReplacements(color: string, replacements?: Record<stri
return replacements?.[color.toLowerCase()] || color
}

/**
* @deprecated Use `isPlainLang` instead.
*/
export const isPlaintext = isPlainLang

export function getTokenStyleObject(token: TokenStyles) {
const styles: Record<string, string> = {}
if (token.color)
Expand Down
20 changes: 0 additions & 20 deletions packages/markdown-it/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import type MarkdownIt from 'markdown-it'
import type { BuiltinTheme, CodeOptionsMeta, CodeOptionsThemes, CodeToHastOptions, HighlighterGeneric, ShikiTransformer, TransformerOptions } from 'shiki'
import { transformerMetaHighlight } from '@shikijs/transformers'

export interface MarkdownItShikiExtraOptions {
/**
* Add `highlighted` class to lines defined in after codeblock
*
* @deprecated Use [transformerNotationHighlight](https://shiki.style/packages/transformers#transformernotationhighlight) instead
* @default false
*/
highlightLines?: boolean | string

/**
* Custom meta string parser
* Return an object to merge with `meta`
Expand All @@ -34,7 +25,6 @@ export function setupMarkdownIt(
options: MarkdownItShikiSetupOptions,
) {
const {
highlightLines = false,
parseMetaString,
} = options

Expand All @@ -52,16 +42,6 @@ export function setupMarkdownIt(

const builtInTransformer: ShikiTransformer[] = []

if (highlightLines) {
builtInTransformer.push(
transformerMetaHighlight({
className: highlightLines === true
? 'highlighted'
: highlightLines,
}),
)
}

builtInTransformer.push({
name: '@shikijs/markdown-it:block-class',
code(node) {
Expand Down
5 changes: 4 additions & 1 deletion packages/markdown-it/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs/promises'
import { expect, it } from 'vitest'
import MarkdownIt from 'markdown-it'
import { transformerMetaHighlight } from '@shikijs/transformers'
import Shiki from '../src'

it('run', async () => {
Expand All @@ -10,7 +11,9 @@ it('run', async () => {
light: 'vitesse-light',
dark: 'vitesse-dark',
},
highlightLines: true,
transformers: [
transformerMetaHighlight(),
],
}))

const result = md.render(await fs.readFile(new URL('./fixtures/a.md', import.meta.url), 'utf-8'))
Expand Down
21 changes: 0 additions & 21 deletions packages/rehype/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@ import type { BuiltinTheme } from 'shiki'
import type { Plugin } from 'unified'
import { toString } from 'hast-util-to-string'
import { visit } from 'unist-util-visit'
import { transformerMetaHighlight } from '@shikijs/transformers'

export interface MapLike<K = any, V = any> {
get: (key: K) => V | undefined
set: (key: K, value: V) => this
}

export interface RehypeShikiExtraOptions {
/**
* Add `highlighted` class to lines defined in after codeblock
*
* @deprecated Use [transformerNotationHighlight](https://shiki.style/packages/transformers#transformernotationhighlight) instead
* @default false
*/
highlightLines?: boolean | string

/**
* Add `language-*` class to code element
*
Expand Down Expand Up @@ -71,7 +62,6 @@ const rehypeShikiFromHighlighter: Plugin<[HighlighterGeneric<any, any>, RehypeSh
options,
) {
const {
highlightLines = false,
addLanguageClass = false,
parseMetaString,
cache,
Expand Down Expand Up @@ -140,17 +130,6 @@ const rehypeShikiFromHighlighter: Plugin<[HighlighterGeneric<any, any>, RehypeSh
})
}

if (highlightLines && typeof metaString === 'string') {
codeOptions.transformers ||= []
codeOptions.transformers.push(
transformerMetaHighlight({
className: highlightLines === true
? 'highlighted'
: highlightLines,
}),
)
}

try {
const fragment = highlighter.codeToHast(code, codeOptions)
cache?.set(code, fragment.children)
Expand Down
9 changes: 7 additions & 2 deletions packages/rehype/test/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { expect, it } from 'vitest'

import { getHighlighter } from 'shiki'
import type { Root } from 'hast'
import { transformerMetaHighlight } from '../../transformers/src'
import rehypeShikiFromHighlighter from '../src/core'

it('run', async () => {
Expand All @@ -26,7 +27,9 @@ it('run', async () => {
.use(remarkRehype)
.use(rehypeShikiFromHighlighter, highlighter, {
theme: 'vitesse-light',
highlightLines: true,
transformers: [
transformerMetaHighlight(),
],
})
.use(rehypeStringify)
.processSync(await fs.readFile(new URL('./fixtures/a.md', import.meta.url)))
Expand Down Expand Up @@ -60,7 +63,9 @@ it('run with rehype-raw', async () => {
.use(rehypeRaw)
.use(rehypeShikiFromHighlighter, highlighter, {
theme: 'vitesse-light',
highlightLines: true,
transformers: [
transformerMetaHighlight(),
],
})
.use(rehypeStringify)
.processSync(await fs.readFile(new URL('./fixtures/a.md', import.meta.url)))
Expand Down
8 changes: 1 addition & 7 deletions packages/twoslash/src/renderer-rich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ export interface RendererRichOptions {
*/
lang?: string

/**
* @deprecated Use `processHoverInfo` instead.
*/
formatInfo?: (info: string) => string

/**
* Custom function to render markdown.
*
Expand Down Expand Up @@ -207,8 +202,7 @@ export function rendererRich(options: RendererRichOptions = {}): TwoslashRendere
const {
completionIcons = defaultCompletionIcons,
customTagIcons = defaultCustomTagIcons,
formatInfo,
processHoverInfo = formatInfo || defaultHoverInfoProcessor,
processHoverInfo = defaultHoverInfoProcessor,
processHoverDocs = docs => docs,
classExtra = '',
jsdoc = true,
Expand Down
3 changes: 2 additions & 1 deletion packages/twoslash/test/markdown-it.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
import MarkdownIt from 'markdown-it'
import Shiki from '@shikijs/markdown-it'
import { rendererRich, transformerTwoslash } from '@shikijs/twoslash'
import { transformerMetaHighlight } from '@shikijs/transformers'

const styleTag = `
<link rel="stylesheet" href="../../../style-rich.css" />
Expand Down Expand Up @@ -65,13 +66,13 @@ const a = 123
const md = MarkdownIt()

md.use(await Shiki({
highlightLines: true,
themes: {
light: 'vitesse-light',
dark: 'vitesse-dark',
},
defaultColor: false,
transformers: [
transformerMetaHighlight(),
transformerTwoslash({
explicitTrigger: true,
renderer: rendererRich(),
Expand Down

0 comments on commit 1a39ff0

Please sign in to comment.