Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/rehype-shiki/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
export { default } from '../../eslint.config.js';
import baseConfig from '../../eslint.config.js';

export default baseConfig.concat([
{
files: ['src'],
ignores: ['**/*.test.*', '**/*.stories.tsx'],
languageOptions: {
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
},
},
]);
18 changes: 15 additions & 3 deletions packages/rehype-shiki/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "@node-core/rehype-shiki",
"version": "1.4.0",
"version": "1.4.1",
"type": "module",
"types": "./dist/index.d.mts",
"exports": {
".": "./src/index.mjs",
".": {
"types": "./dist/index.d.mts",
"default": "./src/index.mjs"
},
"./index.css": "./src/index.css",
"./*": "./src/*.mjs"
Comment thread
ovflowd marked this conversation as resolved.
Outdated
Comment thread
ovflowd marked this conversation as resolved.
Outdated
},
Expand All @@ -12,11 +16,18 @@
"url": "https://github.com/nodejs/nodejs.org",
"directory": "packages/rehype-shiki"
},
"imports": {
"#rs/*": "./src/*"
},
"scripts": {
"compile:ts": "tsc",
"compile": "node --run compile:ts",
"release": "node --run compile",
Comment thread
ovflowd marked this conversation as resolved.
"lint": "node --run lint:js",
"lint:fix": "node --run lint:js:fix",
"lint:js": "eslint \"**/*.mjs\"",
"lint:js:fix": "node --run lint:js -- --fix",
"lint:types": "tsc --noEmit",
"test": "node --run test:unit",
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --experimental-test-coverage --experimental-test-module-mocks --test \"**/*.test.mjs\""
},
Expand All @@ -31,6 +42,7 @@
"unist-util-visit": "^5.1.0"
},
"devDependencies": {
"cross-env": "catalog:"
"cross-env": "catalog:",
"typescript": "catalog:"
}
}
8 changes: 7 additions & 1 deletion packages/rehype-shiki/src/highlighter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ const DEFAULT_THEME = {
...shikiNordTheme,
};

/**
* @template {{ name: string; aliases?: string[] }} T
* @param {string} language
* @param {ReadonlyArray<T>} langs
* @returns {T | undefined}
*/
export const getLanguageByName = (language, langs) => {
const normalized = language.toLowerCase();

Expand All @@ -20,7 +26,7 @@ export const getLanguageByName = (language, langs) => {

/**
* @typedef {Object} SyntaxHighlighter
* @property {import('@shikijs/core').HighlighterCoreSync} shiki - The underlying shiki core instance.
* @property {import('@shikijs/core').HighlighterCore} shiki - The underlying shiki core instance.
* @property {(code: string, lang: string, meta?: Record<string, any>) => string} highlightToHtml - Highlights code and returns inner HTML of the <code> tag.
* @property {(code: string, lang: string, meta?: Record<string, any>) => any} highlightToHast - Highlights code and returns a HAST tree.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/rehype-shiki/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import shellSessionLanguage from 'shiki/langs/shellsession.mjs';
import typeScriptLanguage from 'shiki/langs/typescript.mjs';
import yamlLanguage from 'shiki/langs/yaml.mjs';

import createHighlighter, { getLanguageByName } from './highlighter.mjs';
import createHighlighter, { getLanguageByName } from '#rs/highlighter.mjs';

/**
* @typedef {Object} HighlighterOptions
Expand Down Expand Up @@ -48,7 +48,7 @@ async function getTransformers({ twoslash = false, twoslashOptions }) {
const transformers = [];

if (twoslash) {
const { twoslash } = await import('./transformers/twoslash/index.mjs');
const { twoslash } = await import('#rs/transformers/twoslash/index.mjs');
transformers.push(twoslash(twoslashOptions));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rehype-shiki/src/minimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript';
import powershellLanguage from 'shiki/langs/powershell.mjs';
import shellScriptLanguage from 'shiki/langs/shellscript.mjs';

import createHighlighter, { getLanguageByName } from './highlighter.mjs';
import createHighlighter, { getLanguageByName } from '#rs/highlighter.mjs';

export const LANGS = [...powershellLanguage, ...shellScriptLanguage];

Expand Down
4 changes: 2 additions & 2 deletions packages/rehype-shiki/src/plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'classnames';
import { toString } from 'hast-util-to-string';
import { SKIP, visit } from 'unist-util-visit';

import createHighlighter from './index.mjs';
import createHighlighter from '#rs/index.mjs';
Comment thread
ovflowd marked this conversation as resolved.

// This is what Remark will use as prefix within a <pre> className
// to attribute the current language of the <pre> element
Expand Down Expand Up @@ -54,7 +54,7 @@ function isCodeBlock(node) {
}

/**
* @param {import('./index.mjs').HighlighterOptions & { highlighter: import('./highlighter.mjs').SyntaxHighlighter }} options
* @param {import('#rs/index.mjs').HighlighterOptions & { highlighter: import('#rs/highlighter.mjs').SyntaxHighlighter }} options
*/
export default async function rehypeShikiji(options) {
const highlighter =
Expand Down
22 changes: 22 additions & 0 deletions packages/rehype-shiki/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"jsx": "react-jsx",
"declaration": true,
"emitDeclarationOnly": true,
"baseUrl": "./src",
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"],
"exclude": ["**/*.test.*", "**/*.stories.tsx"]
}
1 change: 0 additions & 1 deletion packages/ui-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"isolatedModules": true,
"jsx": "react-jsx",
"declaration": true,
"incremental": true,
"baseUrl": "./src",
"rootDir": "./src",
Comment thread
ovflowd marked this conversation as resolved.
"outDir": "./dist"
Expand Down
26 changes: 16 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading