@juptune/marmos-startlight-plugin 0.0.0-stage → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Copyright 2026 Bradley Chatha
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@juptune/marmos-startlight-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.2",
4
+ "description": "Starlight plugin providing extra features required by Marmos",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Juptune/marmos-starlight-plugin"
8
+ },
9
+ "author": "Bradley Chatha",
10
+ "license": "ISC",
11
+ "devEngines": {
12
+ "packageManager": {
13
+ "name": "pnpm",
14
+ "version": "12.23.0",
15
+ "onFail": "download"
16
+ }
17
+ },
18
+ "type": "module",
19
+ "devDependencies": {
20
+ "typescript": "7.0.2"
21
+ },
22
+ "peerDependencies": {
23
+ "@expressive-code/core": "^0.44.4"
24
+ },
25
+ "dependencies": {
26
+ "zod": "4.6.7"
27
+ },
28
+ "scripts": {
29
+ "build": "tsc",
30
+ "watch": "tsc --watch"
31
+ }
6
32
  }
@@ -0,0 +1,2 @@
1
+ saveExact: true
2
+ minimumReleaseAge: 10080 # 7 days in minutes
@@ -0,0 +1,100 @@
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
+ }
@@ -0,0 +1,51 @@
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
+ }
@@ -0,0 +1,25 @@
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 ADDED
@@ -0,0 +1 @@
1
+ export * from './expressive-code/plugin.js'
package/tsconfig.json ADDED
@@ -0,0 +1,36 @@
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
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.