@riebeckite/plugin-shortcodes 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +76 -3
- package/dist/src/remark.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { builtinInlineShortcodes, builtinShortcodeNames, builtinShortcodes } from "./src/builtins.js";
|
|
2
|
-
import { DIAGNOSTIC_INLINE_UNSUPPORTED, DIAGNOSTIC_INVALID, DIAGNOSTIC_UNKNOWN, remarkShortcodes, SHORTCODES_SOURCE } from "./src/remark.js";
|
|
2
|
+
import { containsShortcodeDirective, DIAGNOSTIC_INLINE_UNSUPPORTED, DIAGNOSTIC_INVALID, DIAGNOSTIC_UNKNOWN, remarkShortcodes, SHORTCODES_SOURCE } from "./src/remark.js";
|
|
3
3
|
import { createShortcodeRenderContext, DEFAULT_SHORTCODE_CLASS_NAME, isInlineShortcode, renderShortcode, resolveShortcodeOptions, SHORTCODE_CHILDREN_MARKER } from "./src/render.js";
|
|
4
4
|
import type { ShortcodeOptions } from "./src/types.js";
|
|
5
5
|
export type { DirectiveNode, RemarkShortcodesOptions, ResolvedShortcodeOptions, ShortcodeAttributes, ShortcodeOptions, ShortcodeRenderer, ShortcodeRenderInput, ShortcodeRenderRequest, } from "./src/types.js";
|
|
6
|
-
export { builtinInlineShortcodes, builtinShortcodeNames, builtinShortcodes, createShortcodeRenderContext, DEFAULT_SHORTCODE_CLASS_NAME, DIAGNOSTIC_INLINE_UNSUPPORTED, DIAGNOSTIC_INVALID, DIAGNOSTIC_UNKNOWN, isInlineShortcode, remarkShortcodes, renderShortcode, resolveShortcodeOptions, SHORTCODE_CHILDREN_MARKER, SHORTCODES_SOURCE, };
|
|
6
|
+
export { builtinInlineShortcodes, builtinShortcodeNames, builtinShortcodes, containsShortcodeDirective, createShortcodeRenderContext, DEFAULT_SHORTCODE_CLASS_NAME, DIAGNOSTIC_INLINE_UNSUPPORTED, DIAGNOSTIC_INVALID, DIAGNOSTIC_UNKNOWN, isInlineShortcode, remarkShortcodes, renderShortcode, resolveShortcodeOptions, SHORTCODE_CHILDREN_MARKER, SHORTCODES_SOURCE, };
|
|
7
7
|
export declare function shortcodes(options?: ShortcodeOptions): import("@riebeckite/core").RiebeckitePlugin<ShortcodeOptions>;
|
|
8
8
|
export declare const shortcodesPlugin: typeof shortcodes;
|
package/dist/index.js
CHANGED
|
@@ -324,6 +324,75 @@ var DIAGNOSTIC_UNKNOWN = "shortcodes-unknown";
|
|
|
324
324
|
var DIAGNOSTIC_INVALID = "shortcodes-invalid";
|
|
325
325
|
var DIAGNOSTIC_INLINE_UNSUPPORTED = "shortcodes-inline-unsupported";
|
|
326
326
|
var ATTRIBUTE_NAME_PATTERN = /^[A-Za-z_][\w-]*$/;
|
|
327
|
+
function containsShortcodeDirective(source) {
|
|
328
|
+
const lines = source.split(/\r?\n/);
|
|
329
|
+
const frontmatterEnd = findFrontmatterEnd(lines);
|
|
330
|
+
let fence;
|
|
331
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
|
|
332
|
+
if (frontmatterEnd !== void 0 && lineIndex <= frontmatterEnd) continue;
|
|
333
|
+
const line = lines[lineIndex] ?? "";
|
|
334
|
+
const fenceMarker = line.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
335
|
+
if (fence) {
|
|
336
|
+
if (fenceMarker?.[1]?.[0] === fence.character && fenceMarker[1].length >= fence.length) {
|
|
337
|
+
fence = void 0;
|
|
338
|
+
}
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (fenceMarker) {
|
|
342
|
+
const marker = fenceMarker[1];
|
|
343
|
+
if (marker) {
|
|
344
|
+
fence = {
|
|
345
|
+
character: marker[0],
|
|
346
|
+
length: marker.length
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (lineContainsShortcodeDirective(line)) return true;
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
function findFrontmatterEnd(lines) {
|
|
356
|
+
const opening = lines[0]?.trim();
|
|
357
|
+
if (opening !== "---" && opening !== "+++") return void 0;
|
|
358
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
359
|
+
const line = lines[index]?.trim();
|
|
360
|
+
if (line === opening || opening === "---" && line === "...") return index;
|
|
361
|
+
}
|
|
362
|
+
return void 0;
|
|
363
|
+
}
|
|
364
|
+
function lineContainsShortcodeDirective(line) {
|
|
365
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
366
|
+
if (line[index] === "`") {
|
|
367
|
+
const ticks = countRun(line, index, "`");
|
|
368
|
+
const closing = line.indexOf("`".repeat(ticks), index + ticks);
|
|
369
|
+
if (closing >= 0) {
|
|
370
|
+
index = closing + ticks - 1;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (line[index] !== ":" || isEscaped(line, index)) continue;
|
|
375
|
+
const colonCount = countRun(line, index, ":");
|
|
376
|
+
const nameStart = index + Math.min(colonCount, 3);
|
|
377
|
+
if (colonCount <= 3 && isDirectiveNameStart(line[nameStart])) return true;
|
|
378
|
+
}
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
function countRun(value, start, character) {
|
|
382
|
+
let end = start;
|
|
383
|
+
while (value[end] === character) end += 1;
|
|
384
|
+
return end - start;
|
|
385
|
+
}
|
|
386
|
+
function isEscaped(value, index) {
|
|
387
|
+
let escapes = 0;
|
|
388
|
+
for (let cursor = index - 1; cursor >= 0 && value[cursor] === "\\"; cursor -= 1) {
|
|
389
|
+
escapes += 1;
|
|
390
|
+
}
|
|
391
|
+
return escapes % 2 === 1;
|
|
392
|
+
}
|
|
393
|
+
function isDirectiveNameStart(value) {
|
|
394
|
+
return value !== void 0 && /[A-Za-z]/.test(value);
|
|
395
|
+
}
|
|
327
396
|
function remarkShortcodes(options = {}) {
|
|
328
397
|
const resolved = resolveShortcodeOptions(options);
|
|
329
398
|
return (tree, file) => {
|
|
@@ -536,8 +605,9 @@ function shortcodes(options = {}) {
|
|
|
536
605
|
return definePlugin({
|
|
537
606
|
name: PLUGIN_NAME,
|
|
538
607
|
processedContentCache: {
|
|
539
|
-
version: "shortcodes-
|
|
540
|
-
dependencyMode: "unsafe"
|
|
608
|
+
version: "shortcodes-v2",
|
|
609
|
+
dependencyMode: "unsafe",
|
|
610
|
+
appliesToContent: ({ source }) => containsShortcodeDirective(source) ? "applies" : "does-not-apply"
|
|
541
611
|
},
|
|
542
612
|
options,
|
|
543
613
|
extendMarkdownPipeline: (pipeline, context) => {
|
|
@@ -547,7 +617,9 @@ function shortcodes(options = {}) {
|
|
|
547
617
|
contentSource: context.contentSource
|
|
548
618
|
});
|
|
549
619
|
},
|
|
550
|
-
assets: [
|
|
620
|
+
assets: [
|
|
621
|
+
createStyleAsset(PLUGIN_NAME, "@riebeckite/plugin-shortcodes/style.css")
|
|
622
|
+
]
|
|
551
623
|
});
|
|
552
624
|
}
|
|
553
625
|
var shortcodesPlugin = shortcodes;
|
|
@@ -561,6 +633,7 @@ export {
|
|
|
561
633
|
builtinInlineShortcodes,
|
|
562
634
|
builtinShortcodeNames,
|
|
563
635
|
builtinShortcodes,
|
|
636
|
+
containsShortcodeDirective,
|
|
564
637
|
createShortcodeRenderContext,
|
|
565
638
|
isInlineShortcode,
|
|
566
639
|
remarkShortcodes,
|
package/dist/src/remark.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare const SHORTCODES_SOURCE = "@riebeckite/plugin-shortcodes";
|
|
|
4
4
|
export declare const DIAGNOSTIC_UNKNOWN = "shortcodes-unknown";
|
|
5
5
|
export declare const DIAGNOSTIC_INVALID = "shortcodes-invalid";
|
|
6
6
|
export declare const DIAGNOSTIC_INLINE_UNSUPPORTED = "shortcodes-inline-unsupported";
|
|
7
|
+
export declare function containsShortcodeDirective(source: string): boolean;
|
|
7
8
|
export declare function remarkShortcodes(options?: RemarkShortcodesOptions): (tree: Root, file: unknown) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-shortcodes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@types/mdast": "^4.0.4",
|
|
19
19
|
"unist-util-visit": "^5.1.0",
|
|
20
|
-
"@riebeckite/core": "0.0.
|
|
20
|
+
"@riebeckite/core": "0.0.23"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"tsx": "^4.22.4",
|
|
24
|
-
"@riebeckite/test": "0.0.
|
|
24
|
+
"@riebeckite/test": "0.0.23"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|