svelte-preprocess-org 0.3.4 → 0.3.6
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 → index-CiNPUOqC.d.ts} +15 -6
- package/dist/index.js +36 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { PreprocessorGroup } from "svelte/compiler";
|
|
2
2
|
|
|
3
3
|
//#region src/emacs.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options for starting an Emacs intsance.
|
|
6
|
+
*/
|
|
7
|
+
type EmacsCustomization = {
|
|
8
|
+
/**
|
|
9
|
+
* Directory to use as Emacs `user-emacs-directory`.
|
|
10
|
+
*/
|
|
11
|
+
initDirectory: string;
|
|
12
|
+
/**
|
|
13
|
+
* Largest amount of data in bytes allowed on stdout or stderr.
|
|
14
|
+
*/
|
|
15
|
+
maxBuffer: number;
|
|
16
|
+
};
|
|
4
17
|
/**
|
|
5
18
|
* An S-expression.
|
|
6
19
|
*/
|
|
@@ -122,19 +135,15 @@ type OrgPreprocessOptions = Partial<{
|
|
|
122
135
|
* List of glob patterns to locate Org files for updating ID locations.
|
|
123
136
|
*/
|
|
124
137
|
idLocations: string[];
|
|
125
|
-
/**
|
|
126
|
-
* Directory to use as Emacs `user-emacs-directory`.
|
|
127
|
-
*/
|
|
128
|
-
initDirectory: string;
|
|
129
138
|
/**
|
|
130
139
|
* List of extra S-expressions to evaluate during initialization.
|
|
131
140
|
*/
|
|
132
141
|
initSexps: Sexp[];
|
|
133
|
-
}> & OrgExportCustomization & OrgSvelteCustomization;
|
|
142
|
+
}> & EmacsCustomization & OrgExportCustomization & OrgSvelteCustomization;
|
|
134
143
|
/**
|
|
135
144
|
* Preprocess Org documents to Svelte components.
|
|
136
145
|
*/
|
|
137
146
|
declare function orgPreprocess(options?: OrgPreprocessOptions): PreprocessorGroup;
|
|
138
147
|
//#endregion
|
|
139
148
|
export { OrgPreprocessOptions, orgPreprocess as default, orgPreprocess };
|
|
140
|
-
//# sourceMappingURL=index.d.ts.map
|
|
149
|
+
//# sourceMappingURL=index-CiNPUOqC.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -109,13 +109,13 @@ function stringify(sexp) {
|
|
|
109
109
|
/**
|
|
110
110
|
* Convert a list to a string.
|
|
111
111
|
*/
|
|
112
|
-
function stringifyList(list
|
|
112
|
+
function stringifyList(list) {
|
|
113
113
|
let result = "";
|
|
114
|
-
if (isCell(list
|
|
115
|
-
else result += stringify(list
|
|
116
|
-
if (isCell(list
|
|
117
|
-
else if (isNil(list
|
|
118
|
-
else result += ` . ${stringify(list
|
|
114
|
+
if (isCell(list.car)) result += `(${stringifyList(list.car)})`;
|
|
115
|
+
else result += stringify(list.car);
|
|
116
|
+
if (isCell(list.cdr)) result += ` ${stringifyList(list.cdr)}`;
|
|
117
|
+
else if (isNil(list.cdr)) return result;
|
|
118
|
+
else result += ` . ${stringify(list.cdr)}`;
|
|
119
119
|
return result;
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
@@ -127,6 +127,14 @@ function stringifyList(list$1) {
|
|
|
127
127
|
* the .eld files).
|
|
128
128
|
*/
|
|
129
129
|
var Emacs = class {
|
|
130
|
+
/**
|
|
131
|
+
* Directory that will be used as the `user-emacs-directory`.
|
|
132
|
+
*/
|
|
133
|
+
initDirectory;
|
|
134
|
+
/**
|
|
135
|
+
* Largest amount of data in bytes allowed on stdout or stderr.
|
|
136
|
+
*/
|
|
137
|
+
maxBuffer;
|
|
130
138
|
/**
|
|
131
139
|
* S-expression to evaluate when `run` method is called.
|
|
132
140
|
*/
|
|
@@ -134,18 +142,18 @@ var Emacs = class {
|
|
|
134
142
|
/**
|
|
135
143
|
* String value to be piped into the standard input.
|
|
136
144
|
*/
|
|
137
|
-
stdin;
|
|
145
|
+
stdin = "";
|
|
138
146
|
/**
|
|
139
147
|
* Initialize a new Emacs instance.
|
|
140
148
|
*
|
|
141
149
|
* Internally, this will request a temporary directory to be created, which
|
|
142
150
|
* will be used as the Emacs init directory when `Emacs.run` is called.
|
|
143
151
|
*
|
|
144
|
-
* @param initDirectory -
|
|
152
|
+
* @param initDirectory -
|
|
145
153
|
*/
|
|
146
|
-
constructor(
|
|
147
|
-
this.initDirectory = initDirectory;
|
|
148
|
-
this.
|
|
154
|
+
constructor(opts) {
|
|
155
|
+
this.initDirectory = opts.initDirectory;
|
|
156
|
+
this.maxBuffer = opts.maxBuffer;
|
|
149
157
|
}
|
|
150
158
|
/**
|
|
151
159
|
* Register the features/packages to require.
|
|
@@ -188,7 +196,10 @@ var Emacs = class {
|
|
|
188
196
|
"--batch",
|
|
189
197
|
"--eval",
|
|
190
198
|
stringify(list(a`progn`, ...this.sexps))
|
|
191
|
-
], {
|
|
199
|
+
], {
|
|
200
|
+
input: this.stdin,
|
|
201
|
+
maxBuffer: this.maxBuffer
|
|
202
|
+
});
|
|
192
203
|
if (error) throw new Error(`Error running Emacs: ${stderr}`, { cause: error });
|
|
193
204
|
this.sexps = [];
|
|
194
205
|
this.stdin = "";
|
|
@@ -213,7 +224,7 @@ function toKebabCase(s) {
|
|
|
213
224
|
/**
|
|
214
225
|
* Generate Emacs Lisp code to customize the Org export engine.
|
|
215
226
|
*/
|
|
216
|
-
function customize(options = {}) {
|
|
227
|
+
function customize$1(options = {}) {
|
|
217
228
|
const transformed = Object.entries(options).flatMap(([key, val]) => {
|
|
218
229
|
switch (key) {
|
|
219
230
|
case "withProperties": return [a`org-export-with-properties`, Array.isArray(val) ? quote(list(...val)) : val];
|
|
@@ -259,14 +270,14 @@ function customize(options = {}) {
|
|
|
259
270
|
/**
|
|
260
271
|
* Generate Emacs Lisp code to customize the Org to Svelte export engine.
|
|
261
272
|
*/
|
|
262
|
-
function customize
|
|
273
|
+
function customize(options = {}) {
|
|
263
274
|
const transformed = Object.entries(options).flatMap(([key, val]) => {
|
|
264
275
|
switch (key) {
|
|
265
276
|
case "componentImportAlist": {
|
|
266
277
|
const cia = val;
|
|
267
|
-
return [a`org-svelte-component-import-alist`, quote(list(...Object.entries(cia).map(([k
|
|
268
|
-
if (Array.isArray(v)) return cons(k
|
|
269
|
-
else return cons(k
|
|
278
|
+
return [a`org-svelte-component-import-alist`, quote(list(...Object.entries(cia).map(([k, v]) => {
|
|
279
|
+
if (Array.isArray(v)) return cons(k, list(...v));
|
|
280
|
+
else return cons(k, v);
|
|
270
281
|
})))];
|
|
271
282
|
}
|
|
272
283
|
case "metadataExportList": {
|
|
@@ -275,7 +286,7 @@ function customize$1(options = {}) {
|
|
|
275
286
|
}
|
|
276
287
|
case "textMarkupAlist": {
|
|
277
288
|
const tma = val;
|
|
278
|
-
return [a`org-svelte-text-markup-alist`, quote(list(...Object.entries(tma).map(([key
|
|
289
|
+
return [a`org-svelte-text-markup-alist`, quote(list(...Object.entries(tma).map(([key, val]) => cons(key, val))))];
|
|
279
290
|
}
|
|
280
291
|
case "anchorFormat":
|
|
281
292
|
case "brokenLinkFormat":
|
|
@@ -309,8 +320,11 @@ const exportMinibufferAsSvelte = list(a`let`, list(list(a`content`, ``)), list(a
|
|
|
309
320
|
* Preprocess Org documents to Svelte components.
|
|
310
321
|
*/
|
|
311
322
|
function orgPreprocess(options) {
|
|
312
|
-
const { extensions = [".org"], idLocations = [], initDirectory = mkdtempSync(join(tmpdir(), "svelte-preprocess-org-")), initSexps = []
|
|
313
|
-
const emacs = new Emacs(
|
|
323
|
+
const { extensions = [".org"], idLocations = [], initDirectory = mkdtempSync(join(tmpdir(), "svelte-preprocess-org-")), initSexps = [], maxBuffer = 10 * 1024 * 1024, ...rest } = options || {};
|
|
324
|
+
const emacs = new Emacs({
|
|
325
|
+
initDirectory,
|
|
326
|
+
maxBuffer
|
|
327
|
+
});
|
|
314
328
|
if (initSexps.length > 0) emacs.progn(...initSexps).run();
|
|
315
329
|
if (idLocations.length > 0) {
|
|
316
330
|
const files = globSync(idLocations);
|
|
@@ -318,11 +332,10 @@ function orgPreprocess(options) {
|
|
|
318
332
|
}
|
|
319
333
|
return { markup({ content, filename }) {
|
|
320
334
|
if (filename && !extensions.some((ext) => filename.endsWith(ext))) return { code: content };
|
|
321
|
-
return { code: emacs.require("ox-svelte", fullpath).progn(customize(rest)).progn(customize
|
|
335
|
+
return { code: emacs.require("ox-svelte", fullpath).progn(customize$1(rest)).progn(customize(rest)).progn(exportMinibufferAsSvelte).minibuffer(content).run() };
|
|
322
336
|
} };
|
|
323
337
|
}
|
|
324
|
-
var src_default = orgPreprocess;
|
|
325
338
|
|
|
326
339
|
//#endregion
|
|
327
|
-
export {
|
|
340
|
+
export { orgPreprocess as default, orgPreprocess };
|
|
328
341
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["list","initDirectory: string","customize","k","key","val","customizeOx","customizeOxSvelte"],"sources":["../src/emacs.ts","../src/utilities.ts","../src/org-export.ts","../src/org-svelte.ts","../src/index.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\n\n/**\n * An S-expression.\n */\nexport type Sexp = Value | Cell;\n\n/**\n * A value in an S-expression.\n */\nexport type Value = Atom | Keyword | Quote | string | number | boolean | null;\n\n/**\n * A cons cell.\n */\nexport type Cell = {\n car: Sexp;\n cdr: Sexp;\n};\n\n/**\n * An atom in an S-expression.\n */\nexport type Atom = {\n atom: string;\n};\n\n/**\n * A keyword in an S-expression.\n */\nexport type Keyword = {\n keyword: string;\n};\n\n/**\n * A quoted S-expression.\n */\nexport type Quote = {\n quote: Sexp;\n};\n\n/**\n * Check if a value is a cons cell.\n */\nexport function isCell(x: unknown): x is Cell {\n return x instanceof Object && \"car\" in x && \"cdr\" in x;\n}\n\n/**\n * Check if a value is an atom.\n */\nexport function isAtom(x: unknown): x is Atom {\n return x instanceof Object && \"atom\" in x;\n}\n\n/**\n * Check if a value is a keyword.\n */\nexport function isKeyword(x: unknown): x is Keyword {\n return x instanceof Object && \"keyword\" in x;\n}\n\n/**\n * Check if a value is a quoted S-expression.\n */\nexport function isQuote(x: unknown): x is Quote {\n return x instanceof Object && \"quote\" in x;\n}\n\n/**\n * Check if a value is a valid value in an S-expression.\n */\nexport function isValue(x: unknown): x is Value {\n return (\n isAtom(x) ||\n isKeyword(x) ||\n isQuote(x) ||\n isString(x) ||\n isNumber(x) ||\n isBoolean(x) ||\n isNil(x)\n );\n}\n\n/**\n * Check if a value is a nil value\n */\nexport function isNil(x: unknown): x is null {\n return x === null;\n}\n\n/**\n * Check if a value is a list.\n *\n * Note that improper lists are also considered lists.\n */\nexport function isList(x: unknown): x is Cell {\n return isCell(x) || isNil(x);\n}\n\n/**\n * Check if a value is a string.\n */\nexport function isString(x: unknown): x is string {\n return typeof x === \"string\";\n}\n\n/**\n * Check if a value is a number.\n */\nexport function isNumber(x: unknown): x is number {\n return typeof x === \"number\";\n}\n\n/**\n * Check if a value is a boolean.\n */\nexport function isBoolean(x: unknown): x is boolean {\n return typeof x === \"boolean\";\n}\n\n/**\n * Create a cons cell.\n */\nexport function cons(car: Sexp, cdr: Sexp): Cell {\n return { car, cdr };\n}\n\n/**\n * Create a quoted S-expression.\n */\nexport function quote(sexp: Sexp): Quote | Keyword {\n if (isKeyword(sexp)) {\n // A quoted keyword is still a keyword.\n return k`${sexp.keyword}`;\n } else {\n // For the rest, just quote the S-expression.\n return { quote: sexp };\n }\n}\n\n/**\n * Create a list from a sequence of S-expressions.\n */\nexport function list(...args: Sexp[]): Sexp {\n if (args.length === 0) {\n return null;\n }\n\n const [car, ...rest] = args;\n return cons(car, list(...rest));\n}\n\n/**\n * Create an atom from a tagged template string.\n */\nexport function a(\n raw: TemplateStringsArray,\n ...substitutions: unknown[]\n): Atom {\n return { atom: String.raw({ raw }, ...substitutions) };\n}\n\n/**\n * Create a keyword from a tagged template string.\n */\nexport function k(\n raw: TemplateStringsArray,\n ...substitutions: unknown[]\n): Keyword {\n return { keyword: String.raw({ raw }, ...substitutions) };\n}\n\n/**\n * Convert an S-expression to a string.\n */\nexport function stringify(sexp: Sexp): string {\n // Dispatch based on the type of the expression.\n switch (true) {\n case isCell(sexp):\n return `(${stringifyList(sexp)})`;\n case isNil(sexp):\n return \"nil\";\n case isString(sexp):\n return `\"${sexp}\"`;\n case isNumber(sexp):\n return sexp.toString();\n case isBoolean(sexp):\n return sexp ? \"t\" : \"nil\";\n case isAtom(sexp):\n return sexp.atom;\n case isKeyword(sexp):\n return `:${sexp.keyword}`;\n case isQuote(sexp):\n return `'${stringify(sexp.quote)}`;\n default:\n throw new TypeError(`Unknown type of S-expression: ${typeof sexp}`);\n }\n}\n\n/**\n * Convert a list to a string.\n */\nfunction stringifyList(list: Cell): string {\n // Stringify the car of the list.\n let result = \"\";\n if (isCell(list.car)) {\n result += `(${stringifyList(list.car)})`;\n } else {\n result += stringify(list.car);\n }\n\n // There are three cases for a cdr:\n // 1. cdr is another cell -> recursively stringify the cdr\n // 2. cdr is nil -> end of the list, so just return the result\n // 3. cdr is something else -> add a dot and the stringified cdr\n if (isCell(list.cdr)) {\n result += ` ${stringifyList(list.cdr)}`;\n } else if (isNil(list.cdr)) {\n return result;\n } else {\n result += ` . ${stringify(list.cdr)}`;\n }\n\n return result;\n}\n\n/**\n * An Emacs instance for evaluating S-expressions.\n *\n * Since each Emacs instance constructetd from this class is assigned their own\n * temporary directory as their init directory, any persistent state that needs\n * to be preserved between evaluations can be stored in that directory (e.g. in\n * the .eld files).\n */\nexport class Emacs {\n /**\n * S-expression to evaluate when `run` method is called.\n */\n private sexps: Sexp[] = [];\n\n /**\n * String value to be piped into the standard input.\n */\n private stdin: string;\n\n /**\n * Initialize a new Emacs instance.\n *\n * Internally, this will request a temporary directory to be created, which\n * will be used as the Emacs init directory when `Emacs.run` is called.\n *\n * @param initDirectory - Directory that will be used as the `user-emacs-directory`.\n */\n constructor(private initDirectory: string) {\n this.stdin = \"\";\n }\n\n /**\n * Register the features/packages to require.\n *\n * This function will append to the previous value.\n * The `run` call will not reset this value.\n */\n require(feature: string, filename?: string) {\n this.sexps.push(\n filename\n ? list(a`require`, quote(a`${feature}`), filename)\n : list(a`require`, quote(a`${feature}`)),\n );\n\n return this;\n }\n\n /**\n * Register S-expressions to evaluate.\n *\n * This function will append to the previous value.\n * The `run` call will reset this value.\n */\n progn(...sexps: Sexp[]) {\n this.sexps.push(...sexps);\n\n return this;\n }\n\n /**\n * Register the string to be fed into the standard input.\n *\n * This function will replace the previous value.\n * The `run` call will reset this value.\n */\n minibuffer(content: string) {\n this.stdin = content;\n\n return this;\n }\n\n /**\n * Run the registered S-expressions in Emacs.\n *\n * @rehturns The standard output of the Emacs process.\n */\n run() {\n // Spawn Emacs in batch mode to evaluate the S-expressions.\n const { stdout, stderr, error } = spawnSync(\n \"emacs\",\n [\n `--init-directory=${this.initDirectory}`,\n \"--batch\",\n \"--eval\",\n stringify(list(a`progn`, ...this.sexps)),\n ],\n {\n input: this.stdin,\n },\n );\n if (error) {\n throw new Error(`Error running Emacs: ${stderr}`, { cause: error });\n }\n\n // Reset the S-expressions and stdin for the next run.\n this.sexps = [];\n this.stdin = \"\";\n\n // Return the standard output.\n return stdout.toString();\n }\n}\n","/**\n * Convert a lowerCamelCase string to kebab case.\n *\n * @param s The string to convert.\n * @returns The kebab-cased string.\n */\nexport function toKebabCase(s: string): string {\n return s.replace(\n /[A-Z]+(?!a-z)|[A-Z]/g,\n (match, offset) => (offset > 0 ? \"-\" : \"\") + match.toLowerCase(),\n );\n}\n","import { a, list, quote, type Atom, type Value } from \"./emacs\";\nimport { toKebabCase } from \"./utilities\";\n\n/**\n * Customization options for Org export engine.\n *\n * See the documentation for `ox` for more details.\n */\nexport type OrgExportCustomization = Partial<{\n withSmartQuotes: boolean;\n withEmphasize: boolean;\n withSpecialStrings: boolean;\n withFixedWidth: boolean;\n withTimestamps: boolean;\n preserveBreaks: boolean;\n withSubSuperscripts: boolean | Atom;\n withArchivedTrees: boolean | Atom;\n expandLinks: boolean;\n withBrokenLinks: boolean | Atom;\n withClocks: boolean;\n withCreator: boolean;\n withDrawers: boolean;\n withDate: boolean;\n withEntities: boolean;\n withEmail: boolean;\n withFootnotes: boolean;\n headlineLevels: number;\n withInlinetasks: boolean;\n withSectionNumbers: boolean | number;\n withPlanning: boolean;\n withPriority: boolean;\n withProperties: boolean | Atom[];\n withStatisticsCookies: boolean;\n withTags: boolean | Atom;\n withTasks: boolean | Atom;\n withLatex: boolean | Atom;\n timestampFile: boolean;\n withTitle: boolean;\n withToc: boolean;\n todoKeywords: boolean;\n withTables: boolean;\n}>;\n\n/**\n * Generate Emacs Lisp code to customize the Org export engine.\n */\nexport function customize(options: OrgExportCustomization = {}) {\n const transformed = Object.entries(options).flatMap(([key, val]) => {\n switch (key) {\n case \"withProperties\": {\n return [\n a`org-export-with-properties`,\n Array.isArray(val) ? quote(list(...val)) : val,\n ]\n }\n \n case \"withSmartQuotes\":\n case \"withEmphasize\":\n case \"withSpecialStrings\":\n case \"withFixedWidth\":\n case \"withTimestamps\":\n case \"preserveBreaks\":\n case \"withSubSuperscripts\":\n case \"withArchivedTrees\":\n case \"expandLinks\":\n case \"withBrokenLinks\":\n case \"withClocks\":\n case \"withCreator\":\n case \"withDrawers\":\n case \"withDate\":\n case \"withEntities\":\n case \"withEmail\":\n case \"withFootnotes\":\n case \"headlineLevels\":\n case \"withInlinetasks\":\n case \"withSectionNumbers\":\n case \"withPlanning\":\n case \"withPriority\":\n case \"withStatisticsCookies\":\n case \"withTags\":\n case \"withTasks\":\n case \"withLatex\":\n case \"timestampFile\":\n case \"withTitle\":\n case \"withToc\":\n case \"todoKeywords\":\n case \"withTables\":\n return [a`org-export-${toKebabCase(key)}`, val as Value];\n\n default:\n return [];\n }\n });\n\n return list(a`setq`, ...transformed);\n}\n","import { a, k, cons, list, quote, type Value } from \"./emacs\";\nimport { toKebabCase } from \"./utilities\";\n\n/**\n * Customization options for exporting Org documents as Svelte components.\n *\n * See the documentation for `ox-svelte` for more details.\n */\nexport type OrgSvelteCustomization = Partial<{\n anchorFormat: `${string}%s${string}%s${string}`;\n brokenLinkFormat: string;\n componentImportAlist: Record<string, string | string[] | null>;\n metadataExportList: string[];\n imageFormat: `${string}%s${string}%s${string}`;\n latexEnvironmentFormat: `${string}%s${string}`;\n latexDisplayFragmentFormat: `${string}%s${string}`;\n latexInlineFragmentFormat: `${string}%s${string}`;\n linkOrgFileAsSvelte: boolean;\n rawScriptContent: string;\n srcBlockFormat: `${string}%s${string}%s${string}`;\n textMarkupAlist: Record<\n \"bold\" | \"code\" | \"italic\" | \"strike-through\" | \"underline\" | \"verbatim\",\n `${string}%s${string}`\n >;\n verbose: boolean;\n}>;\n\n/**\n * Generate Emacs Lisp code to customize the Org to Svelte export engine.\n */\nexport function customize(options: OrgSvelteCustomization = {}) {\n const transformed = Object.entries(options).flatMap(([key, val]) => {\n switch (key) {\n case \"componentImportAlist\": {\n const cia = val as Record<string, string | string[] | null>;\n return [\n a`org-svelte-component-import-alist`,\n quote(\n list(\n ...Object.entries(cia).map(([k, v]) => {\n if (Array.isArray(v)) {\n return cons(k, list(...v));\n } else {\n return cons(k, v);\n }\n }),\n ),\n ),\n ];\n }\n\n case \"metadataExportList\": {\n const mel = val as string[];\n return [\n a`org-svelte-metadata-export-list`,\n quote(list(...mel.map((v) => k`${v}`))),\n ];\n }\n\n case \"textMarkupAlist\": {\n const tma = val as Record<\n | \"bold\"\n | \"code\"\n | \"italic\"\n | \"strike-through\"\n | \"underline\"\n | \"verbatim\",\n `${string}%s${string}`\n >;\n return [\n a`org-svelte-text-markup-alist`,\n quote(\n list(...Object.entries(tma).map(([key, val]) => cons(key, val))),\n ),\n ];\n }\n\n case \"anchorFormat\":\n case \"brokenLinkFormat\":\n case \"imageFormat\":\n case \"latexEnvironmentFormat\":\n case \"latexDisplayFragmentFormat\":\n case \"latexInlineFragmentFormat\":\n case \"linkOrgFileAsSvelte\":\n case \"rawScriptContent\":\n case \"srcBlockFormat\":\n case \"verbose\":\n return [a`org-svelte-${toKebabCase(key)}`, val as Value];\n\n default:\n return [];\n }\n });\n\n return list(a`setq`, ...transformed);\n}\n\n/**\n * Export an Org document as Svelte code.\n *\n * Note: This function expects the content of the Org document to be provided\n * via minibuffer input (i.e., stdin).\n *\n * @param options Customization options for the export.\n * @returns The generated Svelte component as a string.\n */\nexport const exportMinibufferAsSvelte = list(\n a`let`,\n // VARLIST\n list(list(a`content`, ``)),\n // BODY\n list(\n a`while`,\n // TEST\n list(a`setq`, a`line`, list(a`ignore-errors`, list(a`read-string`, ``))),\n // BODY\n list(a`setq`, a`content`, list(a`concat`, a`content`, `\\\\n`, a`line`)),\n ),\n // Create temporary buffer, insert, and export.\n list(\n a`with-temp-buffer`,\n list(a`org-mode`),\n list(a`insert`, a`content`),\n list(a`org-svelte-export-as-svelte`),\n list(a`princ`, list(a`buffer-string`)),\n ),\n);\n","import { mkdtempSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport fullpath from \"ox-svelte\";\nimport type { PreprocessorGroup } from \"svelte/compiler\";\nimport { globSync } from \"tinyglobby\";\n\nimport { list, quote, a, Emacs, type Sexp } from \"./emacs\";\nimport {\n customize as customizeOx,\n type OrgExportCustomization,\n} from \"./org-export\";\nimport {\n customize as customizeOxSvelte,\n exportMinibufferAsSvelte,\n type OrgSvelteCustomization,\n} from \"./org-svelte\";\n\n/**\n * Options for preprocessing Org documents to Svelte components.\n *\n * See the documentation for `ox` and `ox-svelte` for more details.\n */\nexport type OrgPreprocessOptions = Partial<{\n /**\n * List of file extensions to process as Org documents.\n */\n extensions: string[];\n\n /**\n * List of glob patterns to locate Org files for updating ID locations.\n */\n idLocations: string[];\n\n /**\n * Directory to use as Emacs `user-emacs-directory`.\n */\n initDirectory: string;\n\n /**\n * List of extra S-expressions to evaluate during initialization.\n */\n initSexps: Sexp[];\n}> &\n OrgExportCustomization &\n OrgSvelteCustomization;\n\n/**\n * Preprocess Org documents to Svelte components.\n */\nexport function orgPreprocess(\n options?: OrgPreprocessOptions,\n): PreprocessorGroup {\n const {\n extensions = [\".org\"],\n idLocations = [],\n initDirectory = mkdtempSync(join(tmpdir(), \"svelte-preprocess-org-\")),\n initSexps = [],\n ...rest\n } = options || {};\n\n // Create a new Emacs instance for this preprocessor.\n const emacs = new Emacs(initDirectory);\n\n if (initSexps.length > 0) {\n emacs.progn(...initSexps).run();\n }\n\n // Update Org-mode ID locations if provided.\n if (idLocations.length > 0) {\n const files = globSync(idLocations);\n if (files.length > 0) {\n emacs\n .require(\"org\")\n .progn(list(a`org-id-update-id-locations`, quote(list(...files))))\n .run();\n }\n }\n\n return {\n markup({ content, filename }) {\n // If the file extension is not in the list of extensions, do nothing.\n if (filename && !extensions.some((ext) => filename.endsWith(ext))) {\n return { code: content };\n }\n\n // Make sure that ID location updates have been applied.\n const code = emacs\n .require(\"ox-svelte\", fullpath)\n .progn(customizeOx(rest))\n .progn(customizeOxSvelte(rest))\n .progn(exportMinibufferAsSvelte)\n .minibuffer(content)\n .run();\n return { code };\n },\n };\n}\n\nexport default orgPreprocess;\n"],"mappings":";;;;;;;;;;;AA4CA,SAAgB,OAAO,GAAuB;AAC5C,QAAO,aAAa,UAAU,SAAS,KAAK,SAAS;;;;;AAMvD,SAAgB,OAAO,GAAuB;AAC5C,QAAO,aAAa,UAAU,UAAU;;;;;AAM1C,SAAgB,UAAU,GAA0B;AAClD,QAAO,aAAa,UAAU,aAAa;;;;;AAM7C,SAAgB,QAAQ,GAAwB;AAC9C,QAAO,aAAa,UAAU,WAAW;;;;;AAqB3C,SAAgB,MAAM,GAAuB;AAC3C,QAAO,MAAM;;;;;AAef,SAAgB,SAAS,GAAyB;AAChD,QAAO,OAAO,MAAM;;;;;AAMtB,SAAgB,SAAS,GAAyB;AAChD,QAAO,OAAO,MAAM;;;;;AAMtB,SAAgB,UAAU,GAA0B;AAClD,QAAO,OAAO,MAAM;;;;;AAMtB,SAAgB,KAAK,KAAW,KAAiB;AAC/C,QAAO;EAAE;EAAK;EAAK;;;;;AAMrB,SAAgB,MAAM,MAA6B;AACjD,KAAI,UAAU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C/D,QAAO,EAAE,MAAM,SAAS;AAW1B,SAAO,EAAE,MAPI,MACV,QAAQ,aAAa,SAAS,CAC9B,MAAMC,UAAY,KAAK,CAAC,CACxB,MAAMC,YAAkB,KAAK,CAAC,CAC9B,MAAM,yBAAyB,CAC/B,WAAW,QAAQ,CACnB,KAAK,EACO;IAElB;;AAGH,kBAAe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["customize","customizeOx","customizeOxSvelte"],"sources":["../src/emacs.ts","../src/utilities.ts","../src/org-export.ts","../src/org-svelte.ts","../src/index.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\n\n/**\n * Options for starting an Emacs intsance.\n */\nexport type EmacsCustomization = {\n /**\n * Directory to use as Emacs `user-emacs-directory`.\n */\n initDirectory: string;\n\n /**\n * Largest amount of data in bytes allowed on stdout or stderr.\n */\n maxBuffer: number;\n};\n\n/**\n * An S-expression.\n */\nexport type Sexp = Value | Cell;\n\n/**\n * A value in an S-expression.\n */\nexport type Value = Atom | Keyword | Quote | string | number | boolean | null;\n\n/**\n * A cons cell.\n */\nexport type Cell = {\n car: Sexp;\n cdr: Sexp;\n};\n\n/**\n * An atom in an S-expression.\n */\nexport type Atom = {\n atom: string;\n};\n\n/**\n * A keyword in an S-expression.\n */\nexport type Keyword = {\n keyword: string;\n};\n\n/**\n * A quoted S-expression.\n */\nexport type Quote = {\n quote: Sexp;\n};\n\n/**\n * Check if a value is a cons cell.\n */\nexport function isCell(x: unknown): x is Cell {\n return x instanceof Object && \"car\" in x && \"cdr\" in x;\n}\n\n/**\n * Check if a value is an atom.\n */\nexport function isAtom(x: unknown): x is Atom {\n return x instanceof Object && \"atom\" in x;\n}\n\n/**\n * Check if a value is a keyword.\n */\nexport function isKeyword(x: unknown): x is Keyword {\n return x instanceof Object && \"keyword\" in x;\n}\n\n/**\n * Check if a value is a quoted S-expression.\n */\nexport function isQuote(x: unknown): x is Quote {\n return x instanceof Object && \"quote\" in x;\n}\n\n/**\n * Check if a value is a valid value in an S-expression.\n */\nexport function isValue(x: unknown): x is Value {\n return (\n isAtom(x) ||\n isKeyword(x) ||\n isQuote(x) ||\n isString(x) ||\n isNumber(x) ||\n isBoolean(x) ||\n isNil(x)\n );\n}\n\n/**\n * Check if a value is a nil value\n */\nexport function isNil(x: unknown): x is null {\n return x === null;\n}\n\n/**\n * Check if a value is a list.\n *\n * Note that improper lists are also considered lists.\n */\nexport function isList(x: unknown): x is Cell {\n return isCell(x) || isNil(x);\n}\n\n/**\n * Check if a value is a string.\n */\nexport function isString(x: unknown): x is string {\n return typeof x === \"string\";\n}\n\n/**\n * Check if a value is a number.\n */\nexport function isNumber(x: unknown): x is number {\n return typeof x === \"number\";\n}\n\n/**\n * Check if a value is a boolean.\n */\nexport function isBoolean(x: unknown): x is boolean {\n return typeof x === \"boolean\";\n}\n\n/**\n * Create a cons cell.\n */\nexport function cons(car: Sexp, cdr: Sexp): Cell {\n return { car, cdr };\n}\n\n/**\n * Create a quoted S-expression.\n */\nexport function quote(sexp: Sexp): Quote | Keyword {\n if (isKeyword(sexp)) {\n // A quoted keyword is still a keyword.\n return k`${sexp.keyword}`;\n } else {\n // For the rest, just quote the S-expression.\n return { quote: sexp };\n }\n}\n\n/**\n * Create a list from a sequence of S-expressions.\n */\nexport function list(...args: Sexp[]): Sexp {\n if (args.length === 0) {\n return null;\n }\n\n const [car, ...rest] = args;\n return cons(car, list(...rest));\n}\n\n/**\n * Create an atom from a tagged template string.\n */\nexport function a(\n raw: TemplateStringsArray,\n ...substitutions: unknown[]\n): Atom {\n return { atom: String.raw({ raw }, ...substitutions) };\n}\n\n/**\n * Create a keyword from a tagged template string.\n */\nexport function k(\n raw: TemplateStringsArray,\n ...substitutions: unknown[]\n): Keyword {\n return { keyword: String.raw({ raw }, ...substitutions) };\n}\n\n/**\n * Convert an S-expression to a string.\n */\nexport function stringify(sexp: Sexp): string {\n // Dispatch based on the type of the expression.\n switch (true) {\n case isCell(sexp):\n return `(${stringifyList(sexp)})`;\n case isNil(sexp):\n return \"nil\";\n case isString(sexp):\n return `\"${sexp}\"`;\n case isNumber(sexp):\n return sexp.toString();\n case isBoolean(sexp):\n return sexp ? \"t\" : \"nil\";\n case isAtom(sexp):\n return sexp.atom;\n case isKeyword(sexp):\n return `:${sexp.keyword}`;\n case isQuote(sexp):\n return `'${stringify(sexp.quote)}`;\n default:\n throw new TypeError(`Unknown type of S-expression: ${typeof sexp}`);\n }\n}\n\n/**\n * Convert a list to a string.\n */\nfunction stringifyList(list: Cell): string {\n // Stringify the car of the list.\n let result = \"\";\n if (isCell(list.car)) {\n result += `(${stringifyList(list.car)})`;\n } else {\n result += stringify(list.car);\n }\n\n // There are three cases for a cdr:\n // 1. cdr is another cell -> recursively stringify the cdr\n // 2. cdr is nil -> end of the list, so just return the result\n // 3. cdr is something else -> add a dot and the stringified cdr\n if (isCell(list.cdr)) {\n result += ` ${stringifyList(list.cdr)}`;\n } else if (isNil(list.cdr)) {\n return result;\n } else {\n result += ` . ${stringify(list.cdr)}`;\n }\n\n return result;\n}\n\n/**\n * An Emacs instance for evaluating S-expressions.\n *\n * Since each Emacs instance constructetd from this class is assigned their own\n * temporary directory as their init directory, any persistent state that needs\n * to be preserved between evaluations can be stored in that directory (e.g. in\n * the .eld files).\n */\nexport class Emacs {\n /**\n * Directory that will be used as the `user-emacs-directory`.\n */\n private initDirectory: string;\n\n /**\n * Largest amount of data in bytes allowed on stdout or stderr.\n */\n private maxBuffer: number;\n\n /**\n * S-expression to evaluate when `run` method is called.\n */\n private sexps: Sexp[] = [];\n\n /**\n * String value to be piped into the standard input.\n */\n private stdin: string = \"\";\n\n /**\n * Initialize a new Emacs instance.\n *\n * Internally, this will request a temporary directory to be created, which\n * will be used as the Emacs init directory when `Emacs.run` is called.\n *\n * @param initDirectory -\n */\n constructor(opts: EmacsCustomization) {\n this.initDirectory = opts.initDirectory;\n this.maxBuffer = opts.maxBuffer;\n }\n\n /**\n * Register the features/packages to require.\n *\n * This function will append to the previous value.\n * The `run` call will not reset this value.\n */\n require(feature: string, filename?: string) {\n this.sexps.push(\n filename\n ? list(a`require`, quote(a`${feature}`), filename)\n : list(a`require`, quote(a`${feature}`)),\n );\n\n return this;\n }\n\n /**\n * Register S-expressions to evaluate.\n *\n * This function will append to the previous value.\n * The `run` call will reset this value.\n */\n progn(...sexps: Sexp[]) {\n this.sexps.push(...sexps);\n\n return this;\n }\n\n /**\n * Register the string to be fed into the standard input.\n *\n * This function will replace the previous value.\n * The `run` call will reset this value.\n */\n minibuffer(content: string) {\n this.stdin = content;\n\n return this;\n }\n\n /**\n * Run the registered S-expressions in Emacs.\n *\n * @rehturns The standard output of the Emacs process.\n */\n run() {\n // Spawn Emacs in batch mode to evaluate the S-expressions.\n const { stdout, stderr, error } = spawnSync(\n \"emacs\",\n [\n `--init-directory=${this.initDirectory}`,\n \"--batch\",\n \"--eval\",\n stringify(list(a`progn`, ...this.sexps)),\n ],\n {\n input: this.stdin,\n maxBuffer: this.maxBuffer,\n },\n );\n if (error) {\n throw new Error(`Error running Emacs: ${stderr}`, { cause: error });\n }\n\n // Reset the S-expressions and stdin for the next run.\n this.sexps = [];\n this.stdin = \"\";\n\n // Return the standard output.\n return stdout.toString();\n }\n}\n","/**\n * Convert a lowerCamelCase string to kebab case.\n *\n * @param s The string to convert.\n * @returns The kebab-cased string.\n */\nexport function toKebabCase(s: string): string {\n return s.replace(\n /[A-Z]+(?!a-z)|[A-Z]/g,\n (match, offset) => (offset > 0 ? \"-\" : \"\") + match.toLowerCase(),\n );\n}\n","import { a, list, quote, type Atom, type Value } from \"./emacs\";\nimport { toKebabCase } from \"./utilities\";\n\n/**\n * Customization options for Org export engine.\n *\n * See the documentation for `ox` for more details.\n */\nexport type OrgExportCustomization = Partial<{\n withSmartQuotes: boolean;\n withEmphasize: boolean;\n withSpecialStrings: boolean;\n withFixedWidth: boolean;\n withTimestamps: boolean;\n preserveBreaks: boolean;\n withSubSuperscripts: boolean | Atom;\n withArchivedTrees: boolean | Atom;\n expandLinks: boolean;\n withBrokenLinks: boolean | Atom;\n withClocks: boolean;\n withCreator: boolean;\n withDrawers: boolean;\n withDate: boolean;\n withEntities: boolean;\n withEmail: boolean;\n withFootnotes: boolean;\n headlineLevels: number;\n withInlinetasks: boolean;\n withSectionNumbers: boolean | number;\n withPlanning: boolean;\n withPriority: boolean;\n withProperties: boolean | Atom[];\n withStatisticsCookies: boolean;\n withTags: boolean | Atom;\n withTasks: boolean | Atom;\n withLatex: boolean | Atom;\n timestampFile: boolean;\n withTitle: boolean;\n withToc: boolean;\n todoKeywords: boolean;\n withTables: boolean;\n}>;\n\n/**\n * Generate Emacs Lisp code to customize the Org export engine.\n */\nexport function customize(options: OrgExportCustomization = {}) {\n const transformed = Object.entries(options).flatMap(([key, val]) => {\n switch (key) {\n case \"withProperties\": {\n return [\n a`org-export-with-properties`,\n Array.isArray(val) ? quote(list(...val)) : val,\n ];\n }\n\n case \"withSmartQuotes\":\n case \"withEmphasize\":\n case \"withSpecialStrings\":\n case \"withFixedWidth\":\n case \"withTimestamps\":\n case \"preserveBreaks\":\n case \"withSubSuperscripts\":\n case \"withArchivedTrees\":\n case \"expandLinks\":\n case \"withBrokenLinks\":\n case \"withClocks\":\n case \"withCreator\":\n case \"withDrawers\":\n case \"withDate\":\n case \"withEntities\":\n case \"withEmail\":\n case \"withFootnotes\":\n case \"headlineLevels\":\n case \"withInlinetasks\":\n case \"withSectionNumbers\":\n case \"withPlanning\":\n case \"withPriority\":\n case \"withStatisticsCookies\":\n case \"withTags\":\n case \"withTasks\":\n case \"withLatex\":\n case \"timestampFile\":\n case \"withTitle\":\n case \"withToc\":\n case \"todoKeywords\":\n case \"withTables\":\n return [a`org-export-${toKebabCase(key)}`, val as Value];\n\n default:\n return [];\n }\n });\n\n return list(a`setq`, ...transformed);\n}\n","import { a, k, cons, list, quote, type Value } from \"./emacs\";\nimport { toKebabCase } from \"./utilities\";\n\n/**\n * Customization options for exporting Org documents as Svelte components.\n *\n * See the documentation for `ox-svelte` for more details.\n */\nexport type OrgSvelteCustomization = Partial<{\n anchorFormat: `${string}%s${string}%s${string}`;\n brokenLinkFormat: string;\n componentImportAlist: Record<string, string | string[] | null>;\n metadataExportList: string[];\n imageFormat: `${string}%s${string}%s${string}`;\n latexEnvironmentFormat: `${string}%s${string}`;\n latexDisplayFragmentFormat: `${string}%s${string}`;\n latexInlineFragmentFormat: `${string}%s${string}`;\n linkOrgFileAsSvelte: boolean;\n rawScriptContent: string;\n srcBlockFormat: `${string}%s${string}%s${string}`;\n textMarkupAlist: Record<\n \"bold\" | \"code\" | \"italic\" | \"strike-through\" | \"underline\" | \"verbatim\",\n `${string}%s${string}`\n >;\n verbose: boolean;\n}>;\n\n/**\n * Generate Emacs Lisp code to customize the Org to Svelte export engine.\n */\nexport function customize(options: OrgSvelteCustomization = {}) {\n const transformed = Object.entries(options).flatMap(([key, val]) => {\n switch (key) {\n case \"componentImportAlist\": {\n const cia = val as Record<string, string | string[] | null>;\n return [\n a`org-svelte-component-import-alist`,\n quote(\n list(\n ...Object.entries(cia).map(([k, v]) => {\n if (Array.isArray(v)) {\n return cons(k, list(...v));\n } else {\n return cons(k, v);\n }\n }),\n ),\n ),\n ];\n }\n\n case \"metadataExportList\": {\n const mel = val as string[];\n return [\n a`org-svelte-metadata-export-list`,\n quote(list(...mel.map((v) => k`${v}`))),\n ];\n }\n\n case \"textMarkupAlist\": {\n const tma = val as Record<\n | \"bold\"\n | \"code\"\n | \"italic\"\n | \"strike-through\"\n | \"underline\"\n | \"verbatim\",\n `${string}%s${string}`\n >;\n return [\n a`org-svelte-text-markup-alist`,\n quote(\n list(...Object.entries(tma).map(([key, val]) => cons(key, val))),\n ),\n ];\n }\n\n case \"anchorFormat\":\n case \"brokenLinkFormat\":\n case \"imageFormat\":\n case \"latexEnvironmentFormat\":\n case \"latexDisplayFragmentFormat\":\n case \"latexInlineFragmentFormat\":\n case \"linkOrgFileAsSvelte\":\n case \"rawScriptContent\":\n case \"srcBlockFormat\":\n case \"verbose\":\n return [a`org-svelte-${toKebabCase(key)}`, val as Value];\n\n default:\n return [];\n }\n });\n\n return list(a`setq`, ...transformed);\n}\n\n/**\n * Export an Org document as Svelte code.\n *\n * Note: This function expects the content of the Org document to be provided\n * via minibuffer input (i.e., stdin).\n *\n * @param options Customization options for the export.\n * @returns The generated Svelte component as a string.\n */\nexport const exportMinibufferAsSvelte = list(\n a`let`,\n // VARLIST\n list(list(a`content`, ``)),\n // BODY\n list(\n a`while`,\n // TEST\n list(a`setq`, a`line`, list(a`ignore-errors`, list(a`read-string`, ``))),\n // BODY\n list(a`setq`, a`content`, list(a`concat`, a`content`, `\\\\n`, a`line`)),\n ),\n // Create temporary buffer, insert, and export.\n list(\n a`with-temp-buffer`,\n list(a`org-mode`),\n list(a`insert`, a`content`),\n list(a`org-svelte-export-as-svelte`),\n list(a`princ`, list(a`buffer-string`)),\n ),\n);\n","import { mkdtempSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport fullpath from \"ox-svelte\";\nimport type { PreprocessorGroup } from \"svelte/compiler\";\nimport { globSync } from \"tinyglobby\";\n\nimport {\n list,\n quote,\n a,\n Emacs,\n type Sexp,\n type EmacsCustomization,\n} from \"./emacs\";\nimport {\n customize as customizeOx,\n type OrgExportCustomization,\n} from \"./org-export\";\nimport {\n customize as customizeOxSvelte,\n exportMinibufferAsSvelte,\n type OrgSvelteCustomization,\n} from \"./org-svelte\";\n\n/**\n * Options for preprocessing Org documents to Svelte components.\n *\n * See the documentation for `ox` and `ox-svelte` for more details.\n */\nexport type OrgPreprocessOptions = Partial<{\n /**\n * List of file extensions to process as Org documents.\n */\n extensions: string[];\n\n /**\n * List of glob patterns to locate Org files for updating ID locations.\n */\n idLocations: string[];\n\n /**\n * List of extra S-expressions to evaluate during initialization.\n */\n initSexps: Sexp[];\n}> &\n EmacsCustomization &\n OrgExportCustomization &\n OrgSvelteCustomization;\n\n/**\n * Preprocess Org documents to Svelte components.\n */\nexport function orgPreprocess(\n options?: OrgPreprocessOptions,\n): PreprocessorGroup {\n const {\n extensions = [\".org\"],\n idLocations = [],\n initDirectory = mkdtempSync(join(tmpdir(), \"svelte-preprocess-org-\")),\n initSexps = [],\n maxBuffer = 10 * 1024 * 1024, // 10 MiB\n ...rest\n } = options || {};\n\n // Create a new Emacs instance for this preprocessor.\n const emacs = new Emacs({\n initDirectory,\n maxBuffer,\n });\n\n if (initSexps.length > 0) {\n emacs.progn(...initSexps).run();\n }\n\n // Update Org-mode ID locations if provided.\n if (idLocations.length > 0) {\n const files = globSync(idLocations);\n if (files.length > 0) {\n emacs\n .require(\"org\")\n .progn(list(a`org-id-update-id-locations`, quote(list(...files))))\n .run();\n }\n }\n\n return {\n markup({ content, filename }) {\n // If the file extension is not in the list of extensions, do nothing.\n if (filename && !extensions.some((ext) => filename.endsWith(ext))) {\n return { code: content };\n }\n\n // Make sure that ID location updates have been applied.\n const code = emacs\n .require(\"ox-svelte\", fullpath)\n .progn(customizeOx(rest))\n .progn(customizeOxSvelte(rest))\n .progn(exportMinibufferAsSvelte)\n .minibuffer(content)\n .run();\n return { code };\n },\n };\n}\n\nexport default orgPreprocess;\n"],"mappings":";;;;;;;;;;;AA2DA,SAAgB,OAAO,GAAuB;AAC5C,QAAO,aAAa,UAAU,SAAS,KAAK,SAAS;;;;;AAMvD,SAAgB,OAAO,GAAuB;AAC5C,QAAO,aAAa,UAAU,UAAU;;;;;AAM1C,SAAgB,UAAU,GAA0B;AAClD,QAAO,aAAa,UAAU,aAAa;;;;;AAM7C,SAAgB,QAAQ,GAAwB;AAC9C,QAAO,aAAa,UAAU,WAAW;;;;;AAqB3C,SAAgB,MAAM,GAAuB;AAC3C,QAAO,MAAM;;;;;AAef,SAAgB,SAAS,GAAyB;AAChD,QAAO,OAAO,MAAM;;;;;AAMtB,SAAgB,SAAS,GAAyB;AAChD,QAAO,OAAO,MAAM;;;;;AAMtB,SAAgB,UAAU,GAA0B;AAClD,QAAO,OAAO,MAAM;;;;;AAMtB,SAAgB,KAAK,K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d,MAAM,KAAK,CAAC,8BAA8B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CACjE,KAAK;;AAIZ,QAAO,EACL,OAAO,EAAE,SAAS,YAAY;AAE5B,MAAI,YAAY,CAAC,WAAW,MAAM,QAAQ,SAAS,SAAS,IAAI,CAAC,CAC/D,QAAO,EAAE,MAAM,SAAS;AAW1B,SAAO,EAAE,MAPI,MACV,QAAQ,aAAa,SAAS,CAC9B,MAAMC,YAAY,KAAK,CAAC,CACxB,MAAMC,UAAkB,KAAK,CAAC,CAC9B,MAAM,yBAAyB,CAC/B,WAAW,QAAQ,CACnB,KAAK,EACO;IAElB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-preprocess-org",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Svelte preprocessor for Org-mode documents",
|
|
5
5
|
"author": "RangHo Lee <hello@rangho.me>",
|
|
6
6
|
"homepage": "https://github.com/RangHo/svelte-preprocess-org",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@tsconfig/node-lts": "^22.0.2",
|
|
16
16
|
"@types/node": "^22.18.12",
|
|
17
|
-
"ox-svelte": "0.4.
|
|
17
|
+
"ox-svelte": "0.4.8",
|
|
18
18
|
"svelte": "^5.2.11"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"ox-svelte": "0.4.
|
|
21
|
+
"ox-svelte": "0.4.8",
|
|
22
22
|
"svelte": "^5.2.11"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|