From 1a39ff02a6e71e62ae52ec8b1c4c683bab0e4987 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 6 Feb 2024 11:24:09 +0100 Subject: [PATCH] refactor!: remove all deprecated APIs --- packages/core/src/bundle-factory.ts | 13 ------------- packages/core/src/highlighter.ts | 3 --- packages/core/src/types/highlighter.ts | 8 -------- packages/core/src/types/textmate.ts | 9 --------- packages/core/src/types/transformers.ts | 21 --------------------- packages/core/src/utils.ts | 5 ----- packages/markdown-it/src/core.ts | 20 -------------------- packages/markdown-it/test/index.test.ts | 5 ++++- packages/rehype/src/core.ts | 21 --------------------- packages/rehype/test/core.test.ts | 9 +++++++-- packages/twoslash/src/renderer-rich.ts | 8 +------- packages/twoslash/test/markdown-it.test.ts | 3 ++- 12 files changed, 14 insertions(+), 111 deletions(-) diff --git a/packages/core/src/bundle-factory.ts b/packages/core/src/bundle-factory.ts index 5406738f0..1210f80dc 100644 --- a/packages/core/src/bundle-factory.ts +++ b/packages/core/src/bundle-factory.ts @@ -116,11 +116,6 @@ export interface ShorthandsBundle { * @internal */ getSingletonHighlighter: () => Promise> - - /** - * @deprecated Use `codeToTokensBase` instead. - */ - codeToThemedTokens: (code: string, options: RequireKeys, 'theme' | 'lang'>) => Promise } export function createSingletonShorthands(getHighlighter: GetHighlighterFactory): ShorthandsBundle { @@ -178,14 +173,6 @@ export function createSingletonShorthands(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, diff --git a/packages/core/src/highlighter.ts b/packages/core/src/highlighter.ts index ba71c8301..01108397c 100644 --- a/packages/core/src/highlighter.ts +++ b/packages/core/src/highlighter.ts @@ -35,8 +35,5 @@ export async function getHighlighterCore(options: HighlighterCoreOptions = {}): getLoadedLanguages: internal.getLoadedLanguages, getInternalContext: () => internal, - - /** @deprecated */ - codeToThemedTokens: (code, options) => codeToTokensBase(internal, code, options), } } diff --git a/packages/core/src/types/highlighter.ts b/packages/core/src/types/highlighter.ts index b9bd25849..312683ba9 100644 --- a/packages/core/src/types/highlighter.ts +++ b/packages/core/src/types/highlighter.ts @@ -69,14 +69,6 @@ export interface HighlighterGeneric, ResolveBundleKey> ) => ThemedTokenWithVariants[][] - /** - * @deprecated Renamed to `codeToTokensBase`, or use high-level `codeToTokens` directly. - */ - codeToThemedTokens: ( - code: string, - options: CodeToTokensBaseOptions, ResolveBundleKey> - ) => ThemedToken[][] - /** * Load a theme to the highlighter, so later it can be used synchronously. */ diff --git a/packages/core/src/types/textmate.ts b/packages/core/src/types/textmate.ts index c0f89aa55..70112d525 100644 --- a/packages/core/src/types/textmate.ts +++ b/packages/core/src/types/textmate.ts @@ -10,13 +10,4 @@ export type { RawGrammar, RawTheme, RawThemeSetting, - - /** - * @deprecated Renamed to `Grammar` - */ - Grammar as IGrammar, - /** - * @deprecated Renamed to `RawGrammar` - */ - RawGrammar as IRawGrammar, } diff --git a/packages/core/src/types/transformers.ts b/packages/core/src/types/transformers.ts index 21223e62c..7768beefe 100644 --- a/packages/core/src/types/transformers.ts +++ b/packages/core/src/types/transformers.ts @@ -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 {} diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index ef53917d2..0214809bb 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -150,11 +150,6 @@ export function applyColorReplacements(color: string, replacements?: Record = {} if (token.color) diff --git a/packages/markdown-it/src/core.ts b/packages/markdown-it/src/core.ts index 212c83a72..89e537f1b 100644 --- a/packages/markdown-it/src/core.ts +++ b/packages/markdown-it/src/core.ts @@ -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` @@ -34,7 +25,6 @@ export function setupMarkdownIt( options: MarkdownItShikiSetupOptions, ) { const { - highlightLines = false, parseMetaString, } = options @@ -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) { diff --git a/packages/markdown-it/test/index.test.ts b/packages/markdown-it/test/index.test.ts index 47509cf0a..08ab76725 100644 --- a/packages/markdown-it/test/index.test.ts +++ b/packages/markdown-it/test/index.test.ts @@ -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 () => { @@ -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')) diff --git a/packages/rehype/src/core.ts b/packages/rehype/src/core.ts index fbfe8ce54..105658590 100644 --- a/packages/rehype/src/core.ts +++ b/packages/rehype/src/core.ts @@ -4,7 +4,6 @@ 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 { get: (key: K) => V | undefined @@ -12,14 +11,6 @@ export interface MapLike { } 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 * @@ -71,7 +62,6 @@ const rehypeShikiFromHighlighter: Plugin<[HighlighterGeneric, RehypeSh options, ) { const { - highlightLines = false, addLanguageClass = false, parseMetaString, cache, @@ -140,17 +130,6 @@ const rehypeShikiFromHighlighter: Plugin<[HighlighterGeneric, 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) diff --git a/packages/rehype/test/core.test.ts b/packages/rehype/test/core.test.ts index b8f6dc3c1..b6303412a 100644 --- a/packages/rehype/test/core.test.ts +++ b/packages/rehype/test/core.test.ts @@ -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 () => { @@ -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))) @@ -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))) diff --git a/packages/twoslash/src/renderer-rich.ts b/packages/twoslash/src/renderer-rich.ts index 9d8526839..f8b67d402 100644 --- a/packages/twoslash/src/renderer-rich.ts +++ b/packages/twoslash/src/renderer-rich.ts @@ -68,11 +68,6 @@ export interface RendererRichOptions { */ lang?: string - /** - * @deprecated Use `processHoverInfo` instead. - */ - formatInfo?: (info: string) => string - /** * Custom function to render markdown. * @@ -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, diff --git a/packages/twoslash/test/markdown-it.test.ts b/packages/twoslash/test/markdown-it.test.ts index 2c386aea5..465f2ef58 100644 --- a/packages/twoslash/test/markdown-it.test.ts +++ b/packages/twoslash/test/markdown-it.test.ts @@ -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 = ` @@ -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(),