@juptune/marmos-startlight-plugin 1.0.2 → 1.0.3
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/expressive-code/config.d.ts +15 -0
- package/dist/expressive-code/config.d.ts.map +1 -0
- package/dist/expressive-code/config.js +70 -0
- package/dist/expressive-code/config.js.map +1 -0
- package/dist/expressive-code/links.d.ts +9 -0
- package/dist/expressive-code/links.d.ts.map +1 -0
- package/dist/expressive-code/links.js +37 -0
- package/dist/expressive-code/links.js.map +1 -0
- package/dist/expressive-code/plugin.d.ts +5 -0
- package/dist/expressive-code/plugin.d.ts.map +1 -0
- package/dist/expressive-code/plugin.js +23 -0
- package/dist/expressive-code/plugin.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +10 -1
- package/pnpm-workspace.yaml +0 -2
- package/src/expressive-code/config.ts +0 -100
- package/src/expressive-code/links.ts +0 -51
- package/src/expressive-code/plugin.ts +0 -25
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -36
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import type { ExpressiveCodeLine } from '@expressive-code/core';
|
|
3
|
+
export declare const fullConfigSchema: zod.ZodObject<{
|
|
4
|
+
links: zod.ZodOptional<zod.ZodObject<{
|
|
5
|
+
href: zod.ZodString;
|
|
6
|
+
}, zod.core.$strict>>;
|
|
7
|
+
}, zod.core.$strict>;
|
|
8
|
+
export type MetadataConfig = zod.infer<typeof fullConfigSchema>;
|
|
9
|
+
export type LineMetadata = {
|
|
10
|
+
metadata: MetadataConfig;
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function extractMetadataFromLine(line: ExpressiveCodeLine): LineMetadata[];
|
|
15
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/expressive-code/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAE1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,eAAO,MAAM,gBAAgB;;;;oBAE3B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAE/D,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,cAAc,CAAA;IAGxB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,kBAAkB,GAAG,YAAY,EAAE,CAiFhF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { configSchema as linksConfigSchema } from './links.js';
|
|
3
|
+
export const fullConfigSchema = zod.strictObject({
|
|
4
|
+
links: linksConfigSchema.optional(),
|
|
5
|
+
});
|
|
6
|
+
export function extractMetadataFromLine(line) {
|
|
7
|
+
const result = [];
|
|
8
|
+
let cursor = 0;
|
|
9
|
+
while (cursor < line.text.length) {
|
|
10
|
+
// Not the start of our metadata, so move on
|
|
11
|
+
if (line.text[cursor] !== '@') {
|
|
12
|
+
cursor++;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
// Not the start of a metadata still (or we're at EOF), so move on
|
|
16
|
+
if (cursor + 1 >= line.text.length || line.text[cursor + 1] !== '<') {
|
|
17
|
+
cursor++;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
/**** It looks like our metadata, so start parsing ****/
|
|
21
|
+
const startOfEntireThing = cursor;
|
|
22
|
+
const startOfJson = cursor + 2;
|
|
23
|
+
cursor += 2;
|
|
24
|
+
let endOfEntireThing = -1;
|
|
25
|
+
let endOfJson = -1;
|
|
26
|
+
// Keep reading until we hit ">"
|
|
27
|
+
while (true) {
|
|
28
|
+
if (cursor >= line.text.length)
|
|
29
|
+
throw new Error('Unterminated metadata');
|
|
30
|
+
if (line.text[cursor] === '>') {
|
|
31
|
+
endOfJson = cursor;
|
|
32
|
+
cursor++;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
cursor++; // Move onto the next char
|
|
36
|
+
}
|
|
37
|
+
// We're now reading the wrapped text, which is also between "<" and ">"
|
|
38
|
+
if (cursor >= line.text.length)
|
|
39
|
+
throw new Error('Expected wrapped text after metadata');
|
|
40
|
+
if (line.text[cursor] !== '<')
|
|
41
|
+
throw new Error('Expected "<" after metadata');
|
|
42
|
+
cursor++;
|
|
43
|
+
const startOfWrapped = cursor;
|
|
44
|
+
let endOfWrapped = -1;
|
|
45
|
+
while (true) {
|
|
46
|
+
if (cursor >= line.text.length)
|
|
47
|
+
throw new Error('Unterminated wraped');
|
|
48
|
+
if (line.text[cursor] === '>') {
|
|
49
|
+
endOfWrapped = cursor;
|
|
50
|
+
endOfEntireThing = cursor + 1;
|
|
51
|
+
cursor++;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
cursor++; // Move onto the next char
|
|
55
|
+
}
|
|
56
|
+
/**** Extract the metadata; wrapped text, and then edit the line so it's just the wrapped text ****/
|
|
57
|
+
const metadataJson = line.text.substring(startOfJson, endOfJson);
|
|
58
|
+
const wrappedText = line.text.substring(startOfWrapped, endOfWrapped);
|
|
59
|
+
const metadata = fullConfigSchema.parse(JSON.parse(metadataJson));
|
|
60
|
+
const lengthOfEntireThing = endOfEntireThing - startOfEntireThing;
|
|
61
|
+
line.editText(startOfEntireThing, endOfEntireThing, wrappedText);
|
|
62
|
+
cursor -= lengthOfEntireThing; // As if the entire metadata + wrapped text didn't exist
|
|
63
|
+
cursor += wrappedText.length; // As if only the metadata syntax wrapping the wrapped text didn't exist, but the wrapped text still does
|
|
64
|
+
const startOfUnwrapped = cursor - wrappedText.length;
|
|
65
|
+
const endOfUnwrapped = cursor;
|
|
66
|
+
result.push({ metadata, start: startOfUnwrapped, end: endOfUnwrapped });
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/expressive-code/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAG9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC,YAAY,CAAC;IAC/C,KAAK,EAAE,iBAAiB,CAAC,QAAQ,EAAE;CACpC,CAAC,CAAA;AAYF,MAAM,UAAU,uBAAuB,CAAC,IAAwB;IAC9D,MAAM,MAAM,GAAmB,EAAE,CAAA;IAEjC,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,OAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,4CAA4C;QAC5C,IAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;YAC7B,MAAM,EAAE,CAAA;YACR,SAAQ;QACV,CAAC;QAED,kEAAkE;QAClE,IAAG,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACnE,MAAM,EAAE,CAAA;YACR,SAAQ;QACV,CAAC;QAED,wDAAwD;QACxD,MAAM,kBAAkB,GAAG,MAAM,CAAA;QACjC,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAA;QAC9B,MAAM,IAAI,CAAC,CAAA;QAEX,IAAI,gBAAgB,GAAG,CAAC,CAAC,CAAA;QACzB,IAAI,SAAS,GAAG,CAAC,CA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C,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;QACtE,MAAM,QAAQ,GAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAA;QAErE,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;QACjE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAA;QAEhE,MAAM,IAAI,mBAAmB,CAAA,CAAC,wDAAwD;QACtF,MAAM,IAAI,WAAW,CAAC,MAAM,CAAA,CAAC,yGAAyG;QAEtI,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,CAAC,MAAM,CAAA;QACpD,MAAM,cAAc,GAAK,MAAM,CAAA;QAE/B,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ExpressiveCodeLine } from '@expressive-code/core';
|
|
2
|
+
import * as zod from 'zod';
|
|
3
|
+
export declare const configSchema: zod.ZodObject<{
|
|
4
|
+
href: zod.ZodString;
|
|
5
|
+
}, zod.core.$strict>;
|
|
6
|
+
type LinksConfig = zod.infer<typeof configSchema>;
|
|
7
|
+
export declare function processLinks(line: ExpressiveCodeLine, config: LinksConfig, start: number, end: number, baseUrl: string): void;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/expressive-code/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsF,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAEnJ,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAE1B,eAAO,MAAM,YAAY;;oBAEvB,CAAA;AAEF,KAAK,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAEjD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,QAgBhB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ExpressiveCodeAnnotation } from '@expressive-code/core';
|
|
2
|
+
import { h } from '@expressive-code/core/hast';
|
|
3
|
+
import * as zod from 'zod';
|
|
4
|
+
export const configSchema = zod.strictObject({
|
|
5
|
+
href: zod.string()
|
|
6
|
+
});
|
|
7
|
+
export function processLinks(line, config, start, end, baseUrl) {
|
|
8
|
+
// If the href is relative, then we need to attach the baseUrl onto it
|
|
9
|
+
let href;
|
|
10
|
+
if (URL.parse(config.href))
|
|
11
|
+
href = config.href;
|
|
12
|
+
else
|
|
13
|
+
href = `${baseUrl}${config.href}`;
|
|
14
|
+
line.addAnnotation(new LinkAnnotation({
|
|
15
|
+
href,
|
|
16
|
+
inlineRange: {
|
|
17
|
+
columnStart: start,
|
|
18
|
+
columnEnd: end,
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
class LinkAnnotation extends ExpressiveCodeAnnotation {
|
|
23
|
+
href;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options);
|
|
26
|
+
this.href = options.href;
|
|
27
|
+
}
|
|
28
|
+
render({ nodesToTransform }) {
|
|
29
|
+
if (!this.inlineRange)
|
|
30
|
+
throw new Error('inlineRange was not set');
|
|
31
|
+
return nodesToTransform.map(node => {
|
|
32
|
+
// Wraps the node in an anchor
|
|
33
|
+
return h('a.ec-link', { href: this.href, style: 'text-decoration: dotted underline !important' }, node);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 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AE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,8CAA8C,EAAE,EAAE,IAAI,CAAC,CAAA;QACzG,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/expressive-code/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAI/E,wBAAgB,0BAA0B,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,oBAAoB,CAoBjG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { definePlugin } from '@expressive-code/core';
|
|
2
|
+
import { extractMetadataFromLine } from './config.js';
|
|
3
|
+
import { processLinks } from './links.js';
|
|
4
|
+
export function pluginMarmosExpressiveCode({ baseUrl }) {
|
|
5
|
+
return definePlugin({
|
|
6
|
+
name: 'juptune-marmos-ec',
|
|
7
|
+
hooks: {
|
|
8
|
+
preprocessCode: ({ codeBlock }) => {
|
|
9
|
+
/**** Find any parts of the line containing what looks like our metadata syntax ****/
|
|
10
|
+
const lines = codeBlock.getLines();
|
|
11
|
+
for (const line of lines) {
|
|
12
|
+
const metadata = extractMetadataFromLine(line);
|
|
13
|
+
/**** Call each processor that was enabled ****/
|
|
14
|
+
for (const md of metadata) {
|
|
15
|
+
if (md.metadata.links)
|
|
16
|
+
processLinks(line, md.metadata.links, md.start, md.end, baseUrl);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/expressive-code/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6B,MAAM,uBAAuB,CAAA;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,UAAU,0BAA0B,CAAC,EAAE,OAAO,EAAuB;IACzE,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE;YACL,cAAc,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;gBAChC,qFAAqF;gBACrF,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAA;gBAElC,KAAI,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACxB,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;oBAE9C,gDAAgD;oBAChD,KAAI,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;wBACzB,IAAG,EAAE,CAAC,QAAQ,CAAC,KAAK;4BAClB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;oBACpE,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juptune/marmos-startlight-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Starlight plugin providing extra features required by Marmos",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/Juptune/marmos-starlight-plugin"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
9
18
|
"author": "Bradley Chatha",
|
|
10
19
|
"license": "ISC",
|
|
11
20
|
"devEngines": {
|
package/pnpm-workspace.yaml
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod'
|
|
2
|
-
import { configSchema as linksConfigSchema } from './links.js'
|
|
3
|
-
import type { ExpressiveCodeLine } from '@expressive-code/core'
|
|
4
|
-
|
|
5
|
-
export const fullConfigSchema = zod.strictObject({
|
|
6
|
-
links: linksConfigSchema.optional(),
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
export type MetadataConfig = zod.infer<typeof fullConfigSchema>
|
|
10
|
-
|
|
11
|
-
export type LineMetadata = {
|
|
12
|
-
metadata: MetadataConfig
|
|
13
|
-
|
|
14
|
-
// (These are "fixed" so that they're valid for the modified line)
|
|
15
|
-
start: number
|
|
16
|
-
end: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function extractMetadataFromLine(line: ExpressiveCodeLine): LineMetadata[] {
|
|
20
|
-
const result: LineMetadata[] = []
|
|
21
|
-
|
|
22
|
-
let cursor = 0
|
|
23
|
-
while(cursor < line.text.length) {
|
|
24
|
-
// Not the start of our metadata, so move on
|
|
25
|
-
if(line.text[cursor] !== '@') {
|
|
26
|
-
cursor++
|
|
27
|
-
continue
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Not the start of a metadata still (or we're at EOF), so move on
|
|
31
|
-
if(cursor + 1 >= line.text.length || line.text[cursor + 1] !== '<') {
|
|
32
|
-
cursor++
|
|
33
|
-
continue
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**** It looks like our metadata, so start parsing ****/
|
|
37
|
-
const startOfEntireThing = cursor
|
|
38
|
-
const startOfJson = cursor + 2
|
|
39
|
-
cursor += 2
|
|
40
|
-
|
|
41
|
-
let endOfEntireThing = -1
|
|
42
|
-
let endOfJson = -1
|
|
43
|
-
|
|
44
|
-
// Keep reading until we hit ">"
|
|
45
|
-
while(true) {
|
|
46
|
-
if(cursor >= line.text.length)
|
|
47
|
-
throw new Error('Unterminated metadata')
|
|
48
|
-
|
|
49
|
-
if(line.text[cursor] === '>') {
|
|
50
|
-
endOfJson = cursor
|
|
51
|
-
cursor++
|
|
52
|
-
break
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
cursor++ // Move onto the next char
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// We're now reading the wrapped text, which is also between "<" and ">"
|
|
59
|
-
if(cursor >= line.text.length)
|
|
60
|
-
throw new Error('Expected wrapped text after metadata')
|
|
61
|
-
if(line.text[cursor] !== '<')
|
|
62
|
-
throw new Error('Expected "<" after metadata')
|
|
63
|
-
|
|
64
|
-
cursor++
|
|
65
|
-
const startOfWrapped = cursor
|
|
66
|
-
let endOfWrapped = -1
|
|
67
|
-
|
|
68
|
-
while(true) {
|
|
69
|
-
if(cursor >= line.text.length)
|
|
70
|
-
throw new Error('Unterminated wraped')
|
|
71
|
-
|
|
72
|
-
if(line.text[cursor] === '>') {
|
|
73
|
-
endOfWrapped = cursor
|
|
74
|
-
endOfEntireThing = cursor + 1
|
|
75
|
-
cursor++
|
|
76
|
-
break
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
cursor++ // Move onto the next char
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**** Extract the metadata; wrapped text, and then edit the line so it's just the wrapped text ****/
|
|
83
|
-
const metadataJson = line.text.substring(startOfJson, endOfJson)
|
|
84
|
-
const wrappedText = line.text.substring(startOfWrapped, endOfWrapped)
|
|
85
|
-
const metadata = fullConfigSchema.parse(JSON.parse(metadataJson))
|
|
86
|
-
|
|
87
|
-
const lengthOfEntireThing = endOfEntireThing - startOfEntireThing
|
|
88
|
-
line.editText(startOfEntireThing, endOfEntireThing, wrappedText)
|
|
89
|
-
|
|
90
|
-
cursor -= lengthOfEntireThing // As if the entire metadata + wrapped text didn't exist
|
|
91
|
-
cursor += wrappedText.length // As if only the metadata syntax wrapping the wrapped text didn't exist, but the wrapped text still does
|
|
92
|
-
|
|
93
|
-
const startOfUnwrapped = cursor - wrappedText.length
|
|
94
|
-
const endOfUnwrapped = cursor
|
|
95
|
-
|
|
96
|
-
result.push({ metadata, start: startOfUnwrapped, end: endOfUnwrapped })
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return result
|
|
100
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ExpressiveCodeAnnotation, type AnnotationBaseOptions, type AnnotationRenderOptions, type ExpressiveCodeLine } from '@expressive-code/core'
|
|
2
|
-
import { h, type Parents } from '@expressive-code/core/hast';
|
|
3
|
-
import * as zod from 'zod'
|
|
4
|
-
|
|
5
|
-
export const configSchema = zod.strictObject({
|
|
6
|
-
href: zod.string()
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
type LinksConfig = zod.infer<typeof configSchema>
|
|
10
|
-
|
|
11
|
-
export function processLinks(
|
|
12
|
-
line: ExpressiveCodeLine,
|
|
13
|
-
config: LinksConfig,
|
|
14
|
-
start: number,
|
|
15
|
-
end: number,
|
|
16
|
-
baseUrl: string
|
|
17
|
-
) {
|
|
18
|
-
// If the href is relative, then we need to attach the baseUrl onto it
|
|
19
|
-
let href: string
|
|
20
|
-
if(URL.parse(config.href))
|
|
21
|
-
href = config.href
|
|
22
|
-
else
|
|
23
|
-
href = `${baseUrl}${config.href}`
|
|
24
|
-
|
|
25
|
-
line.addAnnotation(new LinkAnnotation({
|
|
26
|
-
href,
|
|
27
|
-
inlineRange: {
|
|
28
|
-
columnStart: start,
|
|
29
|
-
columnEnd: end,
|
|
30
|
-
}
|
|
31
|
-
}))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class LinkAnnotation extends ExpressiveCodeAnnotation {
|
|
35
|
-
href: string;
|
|
36
|
-
|
|
37
|
-
constructor(options: AnnotationBaseOptions & { href: string }) {
|
|
38
|
-
super(options);
|
|
39
|
-
this.href = options.href;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
override render({ nodesToTransform }: AnnotationRenderOptions): Parents[] {
|
|
43
|
-
if(!this.inlineRange)
|
|
44
|
-
throw new Error('inlineRange was not set')
|
|
45
|
-
|
|
46
|
-
return nodesToTransform.map(node => {
|
|
47
|
-
// Wraps the node in an anchor
|
|
48
|
-
return h('a.ec-link', { href: this.href, style: 'text-decoration: dotted underline !important' }, node)
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { definePlugin, type ExpressiveCodePlugin } from '@expressive-code/core'
|
|
2
|
-
import { extractMetadataFromLine } from './config.js'
|
|
3
|
-
import { processLinks } from './links.js'
|
|
4
|
-
|
|
5
|
-
export function pluginMarmosExpressiveCode({ baseUrl }: { baseUrl: string }): ExpressiveCodePlugin {
|
|
6
|
-
return definePlugin({
|
|
7
|
-
name: 'juptune-marmos-ec',
|
|
8
|
-
hooks: {
|
|
9
|
-
preprocessCode: ({ codeBlock }) => {
|
|
10
|
-
/**** Find any parts of the line containing what looks like our metadata syntax ****/
|
|
11
|
-
const lines = codeBlock.getLines()
|
|
12
|
-
|
|
13
|
-
for(const line of lines) {
|
|
14
|
-
const metadata = extractMetadataFromLine(line)
|
|
15
|
-
|
|
16
|
-
/**** Call each processor that was enabled ****/
|
|
17
|
-
for(const md of metadata) {
|
|
18
|
-
if(md.metadata.links)
|
|
19
|
-
processLinks(line, md.metadata.links, md.start, md.end, baseUrl)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './expressive-code/plugin.js'
|
package/tsconfig.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// File Layout
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
|
|
7
|
-
// Environment Settings
|
|
8
|
-
"module": "nodenext",
|
|
9
|
-
"target": "esnext",
|
|
10
|
-
|
|
11
|
-
// Other Outputs
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"declarationMap": true,
|
|
15
|
-
|
|
16
|
-
// Stricter Typechecking Options
|
|
17
|
-
"noUncheckedIndexedAccess": true,
|
|
18
|
-
"exactOptionalPropertyTypes": true,
|
|
19
|
-
|
|
20
|
-
// Style Options
|
|
21
|
-
"noImplicitReturns": true,
|
|
22
|
-
"noImplicitOverride": true,
|
|
23
|
-
"noUnusedLocals": true,
|
|
24
|
-
"noUnusedParameters": true,
|
|
25
|
-
"noFallthroughCasesInSwitch": true,
|
|
26
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
27
|
-
|
|
28
|
-
// Recommended Options
|
|
29
|
-
"strict": true,
|
|
30
|
-
"verbatimModuleSyntax": true,
|
|
31
|
-
"isolatedModules": true,
|
|
32
|
-
"noUncheckedSideEffectImports": true,
|
|
33
|
-
"moduleDetection": "force",
|
|
34
|
-
"skipLibCheck": true,
|
|
35
|
-
}
|
|
36
|
-
}
|