Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring exports, removing dependencies, and adding new utility functions. #11

Merged
merged 17 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b0436f3
Refactor CI workflows and update dependencies
Adammatthiesen Jan 7, 2025
5d3b19e
Refactor markdown-remark package dependencies
Adammatthiesen Jan 7, 2025
fdc08fd
add changeset
Adammatthiesen Jan 7, 2025
7302a55
Merge branch 'main' into replace-decoder
Adammatthiesen Jan 7, 2025
a5b4f61
fix missing dts files
Adammatthiesen Jan 7, 2025
6cacc40
Merge remote-tracking branch 'origin/replace-decoder' into replace-de…
Adammatthiesen Jan 7, 2025
ce9769e
Refactor markdown-remark integration to export specific functions and…
Adammatthiesen Jan 7, 2025
04506f3
Refactor markdown-remark integration to export specific functions and…
Adammatthiesen Jan 7, 2025
e491bbc
Refactor markdown-remark integration to export specific functions and…
Adammatthiesen Jan 7, 2025
de3f695
add second changeset for the new changes
Adammatthiesen Jan 7, 2025
ff089b9
Refactor markdown-remark integration to export specific functions and…
Adammatthiesen Jan 7, 2025
a49e3d2
Refactor build script to disable minification and fix import comments
Adammatthiesen Jan 7, 2025
f55e4a8
Refactor build script to remove unnecessary file exclusion in clean f…
Adammatthiesen Jan 7, 2025
a14904e
Refactor build script
Adammatthiesen Jan 7, 2025
9f5b574
Add error handling for TypeScript declaration generation in build script
Adammatthiesen Jan 7, 2025
ac60676
Add error handling and refactor imports in markdown-remark integration
Adammatthiesen Jan 8, 2025
d836f68
Add TypeScript declarations for new integration utilities and shared …
Adammatthiesen Jan 8, 2025
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
12 changes: 12 additions & 0 deletions .changeset/lucky-shoes-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@studiocms/markdown-remark": minor
---

Refactor integration exports and simplification

- Default package export `@studiocms/markdown-remark` now exports the same resources as `@studiocms/markdown-remark/integration`

New Export:
- `@studiocms/markdown-remark/integration` - Direct export of the included Astro integration

No longer depends on Astro-integration-kit.
5 changes: 5 additions & 0 deletions .changeset/nine-taxis-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@studiocms/markdown-remark": patch
---

Remove need for entities dependency, and change the one place it was being used.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint:fix": "biome check --write .",
"ci:lint": "biome ci --formatter-enabled=true --organize-imports-enabled=true --reporter=github",
"ci:install": "pnpm install --frozen-lockfile",
"ci:build": "pnpm --filter @studiocms/markdown-remark build:ci",
"ci:build": "pnpm --filter @studiocms/markdown-remark build",
"ci:test": "pnpm ci:build && vitest --reporter=github-actions --reporter=basic",
"ci:version": "pnpm changeset version",
"ci:publish": "pnpm changeset publish",
Expand Down
36 changes: 27 additions & 9 deletions packages/markdown-remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,27 @@
},
"bugs": "https://github.com/withstudiocms/markdown-remark/issues",
"homepage": "https://studiocms.dev",
"main": "./dist/index.js",
"main": "./dist/integration/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
"types": "./dist/integration/index.d.ts",
"default": "./dist/integration/index.js"
},
"./integration": {
"types": "./dist/integration/index.d.ts",
"default": "./dist/integration/index.js"
},
"./integration/utils": {
"types": "./dist/integration/utils.d.ts",
"default": "./dist/integration/utils.js"
},
"./integration/shared": {
"types": "./dist/integration/shared.d.ts",
"default": "./dist/integration/shared.js"
},
"./integration/schema": {
"types": "./dist/integration/schema.d.ts",
"default": "./dist/integration/schema.js"
},
"./processor": {
"types": "./dist/processor/index.d.ts",
Expand All @@ -27,25 +43,27 @@
"#import-plugin": {
"browser": "./dist/processor/import-plugin-browser.js",
"default": "./dist/processor/import-plugin-default.js"
},
"#processor": {
"types": "./dist/processor/index.d.ts",
"default": "./dist/processor/index.js"
}
},
"files": [
"dist"
],
"scripts": {
"prepublish": "pnpm build",
"build": "run-scripts build \"src/**/*.{ts,css}\" && tsc -p tsconfig.json",
"build:ci": "run-scripts build \"src/**/*.{ts,css}\"",
"build": "run-scripts build \"src/**/*.{ts,css}\"",
"dev": "run-scripts dev \"src/**/*.{ts,css}\"",
"test": "pnpm build && vitest run"
},
"peerDependencies": {
"astro": "^5.0.0"
"astro": "^5.0.0",
"vite": "^6.0.0"
},
"dependencies": {
"@astrojs/prism": "^3.2.0",
"astro-integration-kit": "^0.18.0",
"entities": "^6.0.0",
"github-slugger": "^2.0.0",
"hastscript": "^9.0.0",
"hast-util-from-html": "^2.0.3",
Expand All @@ -56,6 +74,7 @@
"import-meta-resolve": "^4.1.0",
"js-yaml": "^4.1.0",
"mdast-util-definitions": "^6.0.0",
"pathe": "^2.0.0",
"rehype-raw": "^7.0.0",
"rehype-stringify": "^10.0.1",
"rehype-autolink-headings": "^7.1.0",
Expand All @@ -80,7 +99,6 @@
"@types/mdast": "^4.0.4",
"@types/unist": "^3.0.3",
"esbuild": "^0.24.2",
"fast-glob": "^3.3.3",
"mdast-util-mdx-expression": "^2.0.1",
"jest-extended": "^4.0.2",
"vitest": "^2.1.8"
Expand Down
6 changes: 0 additions & 6 deletions packages/markdown-remark/src/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134

const decodeMap = new Map([
[0, 65_533],
// C1 Unicode control character reference replacements
[128, 8364],
[130, 8218],
[131, 402],
[132, 8222],
[133, 8230],
[134, 8224],
[135, 8225],
[136, 710],
[137, 8240],
[138, 352],
[139, 8249],
[140, 338],
[142, 381],
[145, 8216],
[146, 8217],
[147, 8220],
[148, 8221],
[149, 8226],
[150, 8211],
[151, 8212],
[152, 732],
[153, 8482],
[154, 353],
[155, 8250],
[156, 339],
[158, 382],
[159, 376],
]);

/**
* Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
*/
export const fromCodePoint: (...codePoints: number[]) => string =
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
String.fromCodePoint ??
((codePoint: number): string => {
let output = '';

if (codePoint > 0xff_ff) {
codePoint -= 0x1_00_00;
output += String.fromCharCode(((codePoint >>> 10) & 0x3_ff) | 0xd8_00);
codePoint = 0xdc_00 | (codePoint & 0x3_ff);
}

output += String.fromCharCode(codePoint);
return output;
});

/**
* Replace the given code point with a replacement character if it is a
* surrogate or is outside the valid range. Otherwise return the code
* point unchanged.
*/
export function replaceCodePoint(codePoint: number): number {
if ((codePoint >= 0xd8_00 && codePoint <= 0xdf_ff) || codePoint > 0x10_ff_ff) {
return 0xff_fd;
}

return decodeMap.get(codePoint) ?? codePoint;
}

/**
* Replace the code point if relevant, then convert it to a string.
*
* @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
* @param codePoint The code point to decode.
* @returns The decoded code point.
*/
export function decodeCodePoint(codePoint: number): string {
return fromCodePoint(replaceCodePoint(codePoint));
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const xmlDecodeTree: Uint16Array = /* #__PURE__ */ new Uint16Array(
// prettier-ignore
/* #__PURE__ */ '\u0200aglq\t\x15\x18\x1b\u026d\x0f\0\0\x12p;\u4026os;\u4027t;\u403et;\u403cuot;\u4022'
.split('')
.map((c) => c.charCodeAt(0))
);
49 changes: 49 additions & 0 deletions packages/markdown-remark/src/integration/decoder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { type DecodingMode, decodeHTML, decodeXML } from './util.js';

/** The level of entities to support. */
export enum EntityLevel {
/** Support only XML entities. */
XML = 0,
/** Support HTML entities, which are a superset of XML entities. */
HTML = 1,
}

export interface DecodingOptions {
/**
* The level of entities to support.
* @default {@link EntityLevel.XML}
*/
level?: EntityLevel;
/**
* Decoding mode. If `Legacy`, will support legacy entities not terminated
* with a semicolon (`;`).
*
* Always `Strict` for XML. For HTML, set this to `true` if you are parsing
* an attribute value.
*
* The deprecated `decodeStrict` function defaults this to `Strict`.
*
* @default {@link DecodingMode.Legacy}
*/
mode?: DecodingMode | undefined;
}

/**
* Decodes a string with entities.
*
* @param input String to decode.
* @param options Decoding options.
*/
export function decode(
input: string,
options: DecodingOptions | EntityLevel = EntityLevel.XML
): string {
const level = typeof options === 'number' ? options : options.level;

if (level === EntityLevel.HTML) {
const mode = typeof options === 'object' ? options.mode : undefined;
return decodeHTML(input, mode);
}

return decodeXML(input);
}
Loading
Loading