Skip to content

Commit

Permalink
chore: progress
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Jul 5, 2024
1 parent f4a806d commit a1c8eb9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ cache
*.timestamp-*
site
.zed
html
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"useAwait": "off",
"noConsoleLog": "off",
"noExplicitAny": "off",
"noFocusedTests": "off",
"noEmptyInterface": "off",
"noConfusingVoidType": "off"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"scripts": {
"build": "tsup --config=tsup.config.ts",
"test": "vitest --run",
"test:ui": "vitest --ui",
"typecheck": "tsc --project tsconfig.json --noEmit",
"clean": "rm -rf dist",
"prebuild": "rm -rf dist",
Expand All @@ -38,11 +39,13 @@
"@arethetypeswrong/cli": "^0.15.3",
"@shikijs/transformers": "^1.10.1",
"@types/node": "^20.14.9",
"@vitest/ui": "^1.6.0",
"hast-util-to-html": "^9.0.1",
"mdast-util-to-hast": "^13.2.0",
"prettier": "^3.3.2",
"remark": "^15.0.1",
"shiki": "^1.10.1",
"ts-dedent": "^2.2.0",
"tsup": "^8.1.0",
"tsx": "^4.16.2",
"typescript": "^5.5.3",
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,18 @@ export function rehypePrettyCode(
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
visit(codeTree, 'element', (element) => {
if (element.tagName === 'code') {
const showLineNumbers = /srebmuNeniLwohs/.test(reverseString(meta));
const showLineNumbers = /(?:^|\s)showLineNumbers(?:\s|$)/.test(meta);
if (showLineNumbers) {
if (element.properties) {
element.properties['data-line-numbers'] = '';
}

const lineNumbersStartAtMatch = reverseString(meta).match(
/(?:\}(\d+){)?srebmuNeniLwohs/,
const lineNumbersStartAtMatch = meta.match(
/showLineNumbers=(\d+)/
);
const startNumberString = lineNumbersStartAtMatch?.[1];
if (startNumberString) {
const startAt = startNumberString
? Number(reverseString(startNumberString)) - 1
: 0;
const startAt = Number(startNumberString) - 1;
lineNumbersMaxDigits = startAt;
if (element.properties) {
element.properties.style = `counter-set: line ${startAt};`;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
},
});
74 changes: 41 additions & 33 deletions pnpm-lock.yaml

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

0 comments on commit a1c8eb9

Please sign in to comment.