generated from withstudiocms/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring exports, removing dependencies, and adding new utility fu…
…nctions. (#11) * Refactor CI workflows and update dependencies * Refactor markdown-remark package dependencies * add changeset * fix missing dts files * Refactor markdown-remark integration to export specific functions and types * Refactor markdown-remark integration to export specific functions and types * Refactor markdown-remark integration to export specific functions and types * add second changeset for the new changes * Refactor markdown-remark integration to export specific functions and types * Refactor build script to disable minification and fix import comments * Refactor build script to remove unnecessary file exclusion in clean function * Refactor build script * Add error handling for TypeScript declaration generation in build script * Add error handling and refactor imports in markdown-remark integration * Add TypeScript declarations for new integration utilities and shared components
- Loading branch information
1 parent
594f048
commit b9d4b7b
Showing
30 changed files
with
1,410 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
packages/markdown-remark/src/integration/decoder/decode-codepoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/markdown-remark/src/integration/decoder/decode-data-html.ts
Large diffs are not rendered by default.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
packages/markdown-remark/src/integration/decoder/decode-data-xml.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.