svelte-preprocess-org 0.2.4 → 0.3.0
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 +139 -8
- package/dist/index.js +328 -1
- package/package.json +22 -30
- package/.editorconfig +0 -15
- package/.gitmodules +0 -3
- package/README.md +0 -11
- package/dist/emacs.d.ts +0 -7
- package/dist/lisp/convert.el +0 -86
- package/dist/lisp/ox-svelte/LICENSE +0 -674
- package/dist/lisp/ox-svelte/README.md +0 -4
- package/dist/lisp/ox-svelte/README.org +0 -3
- package/dist/lisp/ox-svelte/index.d.ts +0 -19
- package/dist/lisp/ox-svelte/ox-svelte.el +0 -353
- package/dist/lisp/ox-svelte/package.json +0 -11
- package/dist/lisp/ox-svelte/pnpm-lock.yaml +0 -155
- package/dist/sexp.d.ts +0 -17
- package/eslint.config.js +0 -9
- package/jest.config.js +0 -11
- package/prettier.config.js +0 -5
- package/rollup.config.js +0 -22
- package/src/emacs.ts +0 -55
- package/src/index.ts +0 -29
- package/src/lisp/convert.el +0 -86
- package/src/lisp/ox-svelte/LICENSE +0 -674
- package/src/lisp/ox-svelte/README.md +0 -4
- package/src/lisp/ox-svelte/index.d.ts +0 -19
- package/src/lisp/ox-svelte/ox-svelte.el +0 -353
- package/src/lisp/ox-svelte/package.json +0 -11
- package/src/lisp/ox-svelte/pnpm-lock.yaml +0 -155
- package/src/sexp.ts +0 -112
- package/test/sexp.test.ts +0 -45
- package/tsconfig.json +0 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { PreprocessorGroup } from "svelte/compiler";
|
|
2
|
+
|
|
3
|
+
//#region src/emacs.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* An S-expression.
|
|
6
|
+
*/
|
|
7
|
+
type Sexp = Value | Cell;
|
|
8
|
+
/**
|
|
9
|
+
* A value in an S-expression.
|
|
10
|
+
*/
|
|
11
|
+
type Value = Atom | Keyword | Quote | string | number | boolean | null;
|
|
12
|
+
/**
|
|
13
|
+
* A cons cell.
|
|
14
|
+
*/
|
|
15
|
+
type Cell = {
|
|
16
|
+
car: Sexp;
|
|
17
|
+
cdr: Sexp;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* An atom in an S-expression.
|
|
21
|
+
*/
|
|
22
|
+
type Atom = {
|
|
23
|
+
atom: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A keyword in an S-expression.
|
|
27
|
+
*/
|
|
28
|
+
type Keyword = {
|
|
29
|
+
keyword: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A quoted S-expression.
|
|
33
|
+
*/
|
|
34
|
+
type Quote = {
|
|
35
|
+
quote: Sexp;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Check if a value is a cons cell.
|
|
39
|
+
*/
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/org-export.d.ts
|
|
42
|
+
/**
|
|
43
|
+
* Customization options for Org export engine.
|
|
44
|
+
*
|
|
45
|
+
* See the documentation for `ox` for more details.
|
|
46
|
+
*/
|
|
47
|
+
type OrgExportCustomization = Partial<{
|
|
48
|
+
withSmartQuotes: boolean;
|
|
49
|
+
withEmphasize: boolean;
|
|
50
|
+
withSpecialStrings: boolean;
|
|
51
|
+
withFixedWidth: boolean;
|
|
52
|
+
withTimestamps: boolean;
|
|
53
|
+
preserveBreaks: boolean;
|
|
54
|
+
withSubSuperscripts: boolean | Atom;
|
|
55
|
+
withArchivedTrees: boolean | Atom;
|
|
56
|
+
expandLinks: boolean;
|
|
57
|
+
withBrokenLinks: boolean | Atom;
|
|
58
|
+
withClocks: boolean;
|
|
59
|
+
withCreator: boolean;
|
|
60
|
+
withDrawers: boolean;
|
|
61
|
+
withDate: boolean;
|
|
62
|
+
withEntities: boolean;
|
|
63
|
+
withEmail: boolean;
|
|
64
|
+
withFootnotes: boolean;
|
|
65
|
+
headlineLevels: number;
|
|
66
|
+
withInlinetasks: boolean;
|
|
67
|
+
withSectionNumbers: boolean | number;
|
|
68
|
+
withPlanning: boolean;
|
|
69
|
+
withPriority: boolean;
|
|
70
|
+
withProperties: boolean | Atom[];
|
|
71
|
+
withStatisticsCookies: boolean;
|
|
72
|
+
withTags: boolean | Atom;
|
|
73
|
+
withTasks: boolean | Atom;
|
|
74
|
+
withLatex: boolean | Atom;
|
|
75
|
+
timestampFile: boolean;
|
|
76
|
+
withTitle: boolean;
|
|
77
|
+
withToc: boolean;
|
|
78
|
+
todoKeywords: boolean;
|
|
79
|
+
withTables: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Generate Emacs Lisp code to customize the Org export engine.
|
|
83
|
+
*/
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/org-svelte.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Customization options for exporting Org documents as Svelte components.
|
|
88
|
+
*
|
|
89
|
+
* See the documentation for `ox-svelte` for more details.
|
|
90
|
+
*/
|
|
91
|
+
type OrgSvelteCustomization = Partial<{
|
|
92
|
+
anchorFormat: `${string}%s${string}%s${string}`;
|
|
93
|
+
brokenLinkFormat: string;
|
|
94
|
+
componentImportAlist: Record<string, string | string[] | null>;
|
|
95
|
+
metadataExportList: string[];
|
|
96
|
+
imageFormat: `${string}%s${string}%s${string}`;
|
|
97
|
+
latexEnviromnetFormat: `${string}%s${string}`;
|
|
98
|
+
latexDisplayFragmentFormat: `${string}%s${string}`;
|
|
99
|
+
latexInlineFragmentFormat: `${string}%s${string}`;
|
|
100
|
+
linkOrgFileAsSvelte: boolean;
|
|
101
|
+
rawScriptContent: string;
|
|
102
|
+
srcBlockFormat: `${string}%s${string}%s${string}`;
|
|
103
|
+
textMarkupAlist: Record<"bold" | "code" | "italic" | "strike-through" | "underline" | "verbatim", `${string}%s${string}`>;
|
|
104
|
+
verbose: boolean;
|
|
105
|
+
}>;
|
|
106
|
+
/**
|
|
107
|
+
* Generate Emacs Lisp code to customize the Org to Svelte export engine.
|
|
108
|
+
*/
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/index.d.ts
|
|
111
|
+
/**
|
|
112
|
+
* Options for preprocessing Org documents to Svelte components.
|
|
113
|
+
*
|
|
114
|
+
* See the documentation for `ox` and `ox-svelte` for more details.
|
|
115
|
+
*/
|
|
116
|
+
type OrgPreprocessOptions = Partial<{
|
|
117
|
+
/**
|
|
118
|
+
* List of file extensions to process as Org documents.
|
|
119
|
+
*/
|
|
120
|
+
extensions: string[];
|
|
121
|
+
/**
|
|
122
|
+
* List of glob patterns to locate Org files for updating ID locations.
|
|
123
|
+
*/
|
|
124
|
+
idLocations: string[];
|
|
125
|
+
/**
|
|
126
|
+
* Directory to use as Emacs `user-emacs-directory`.
|
|
127
|
+
*/
|
|
128
|
+
initDirectory: string;
|
|
129
|
+
/**
|
|
130
|
+
* List of extra S-expressions to evaluate during initialization.
|
|
131
|
+
*/
|
|
132
|
+
initSexps: Sexp[];
|
|
133
|
+
}> & OrgExportCustomization & OrgSvelteCustomization;
|
|
134
|
+
/**
|
|
135
|
+
* Preprocess Org documents to Svelte components.
|
|
136
|
+
*/
|
|
137
|
+
declare function orgPreprocess(options?: OrgPreprocessOptions): PreprocessorGroup;
|
|
138
|
+
//#endregion
|
|
139
|
+
export { OrgPreprocessOptions, orgPreprocess as default, orgPreprocess };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,328 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { mkdtempSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import fullpath from "ox-svelte";
|
|
5
|
+
import { globSync } from "tinyglobby";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
//#region src/emacs.ts
|
|
9
|
+
/**
|
|
10
|
+
* Check if a value is a cons cell.
|
|
11
|
+
*/
|
|
12
|
+
function isCell(x) {
|
|
13
|
+
return x instanceof Object && "car" in x && "cdr" in x;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if a value is an atom.
|
|
17
|
+
*/
|
|
18
|
+
function isAtom(x) {
|
|
19
|
+
return x instanceof Object && "atom" in x;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if a value is a keyword.
|
|
23
|
+
*/
|
|
24
|
+
function isKeyword(x) {
|
|
25
|
+
return x instanceof Object && "keyword" in x;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if a value is a quoted S-expression.
|
|
29
|
+
*/
|
|
30
|
+
function isQuote(x) {
|
|
31
|
+
return x instanceof Object && "quote" in x;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is a nil value
|
|
35
|
+
*/
|
|
36
|
+
function isNil(x) {
|
|
37
|
+
return x === null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if a value is a string.
|
|
41
|
+
*/
|
|
42
|
+
function isString(x) {
|
|
43
|
+
return typeof x === "string";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a value is a number.
|
|
47
|
+
*/
|
|
48
|
+
function isNumber(x) {
|
|
49
|
+
return typeof x === "number";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if a value is a boolean.
|
|
53
|
+
*/
|
|
54
|
+
function isBoolean(x) {
|
|
55
|
+
return typeof x === "boolean";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a cons cell.
|
|
59
|
+
*/
|
|
60
|
+
function cons(car, cdr) {
|
|
61
|
+
return {
|
|
62
|
+
car,
|
|
63
|
+
cdr
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a quoted S-expression.
|
|
68
|
+
*/
|
|
69
|
+
function quote(sexp) {
|
|
70
|
+
if (isKeyword(sexp)) return k`${sexp.keyword}`;
|
|
71
|
+
else return { quote: sexp };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a list from a sequence of S-expressions.
|
|
75
|
+
*/
|
|
76
|
+
function list(...args) {
|
|
77
|
+
if (args.length === 0) return null;
|
|
78
|
+
const [car, ...rest] = args;
|
|
79
|
+
return cons(car, list(...rest));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create an atom from a tagged template string.
|
|
83
|
+
*/
|
|
84
|
+
function a(raw, ...substitutions) {
|
|
85
|
+
return { atom: String.raw({ raw }, ...substitutions) };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a keyword from a tagged template string.
|
|
89
|
+
*/
|
|
90
|
+
function k(raw, ...substitutions) {
|
|
91
|
+
return { keyword: String.raw({ raw }, ...substitutions) };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Convert an S-expression to a string.
|
|
95
|
+
*/
|
|
96
|
+
function stringify(sexp) {
|
|
97
|
+
switch (true) {
|
|
98
|
+
case isCell(sexp): return `(${stringifyList(sexp)})`;
|
|
99
|
+
case isNil(sexp): return "nil";
|
|
100
|
+
case isString(sexp): return `"${sexp}"`;
|
|
101
|
+
case isNumber(sexp): return sexp.toString();
|
|
102
|
+
case isBoolean(sexp): return sexp ? "t" : "nil";
|
|
103
|
+
case isAtom(sexp): return sexp.atom;
|
|
104
|
+
case isKeyword(sexp): return `:${sexp.keyword}`;
|
|
105
|
+
case isQuote(sexp): return `'${stringify(sexp.quote)}`;
|
|
106
|
+
default: throw new TypeError(`Unknown type of S-expression: ${typeof sexp}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Convert a list to a string.
|
|
111
|
+
*/
|
|
112
|
+
function stringifyList(list$1) {
|
|
113
|
+
let result = "";
|
|
114
|
+
if (isCell(list$1.car)) result += `(${stringifyList(list$1.car)})`;
|
|
115
|
+
else result += stringify(list$1.car);
|
|
116
|
+
if (isCell(list$1.cdr)) result += ` ${stringifyList(list$1.cdr)}`;
|
|
117
|
+
else if (isNil(list$1.cdr)) return result;
|
|
118
|
+
else result += ` . ${stringify(list$1.cdr)}`;
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* An Emacs instance for evaluating S-expressions.
|
|
123
|
+
*
|
|
124
|
+
* Since each Emacs instance constructetd from this class is assigned their own
|
|
125
|
+
* temporary directory as their init directory, any persistent state that needs
|
|
126
|
+
* to be preserved between evaluations can be stored in that directory (e.g. in
|
|
127
|
+
* the .eld files).
|
|
128
|
+
*/
|
|
129
|
+
var Emacs = class {
|
|
130
|
+
/**
|
|
131
|
+
* S-expression to evaluate when `run` method is called.
|
|
132
|
+
*/
|
|
133
|
+
sexps = [];
|
|
134
|
+
/**
|
|
135
|
+
* String value to be piped into the standard input.
|
|
136
|
+
*/
|
|
137
|
+
stdin;
|
|
138
|
+
/**
|
|
139
|
+
* Initialize a new Emacs instance.
|
|
140
|
+
*
|
|
141
|
+
* Internally, this will request a temporary directory to be created, which
|
|
142
|
+
* will be used as the Emacs init directory when `Emacs.run` is called.
|
|
143
|
+
*
|
|
144
|
+
* @param initDirectory - Directory that will be used as the `user-emacs-directory`.
|
|
145
|
+
*/
|
|
146
|
+
constructor(initDirectory) {
|
|
147
|
+
this.initDirectory = initDirectory;
|
|
148
|
+
this.stdin = "";
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Register the features/packages to require.
|
|
152
|
+
*
|
|
153
|
+
* This function will append to the previous value.
|
|
154
|
+
* The `run` call will not reset this value.
|
|
155
|
+
*/
|
|
156
|
+
require(feature, filename) {
|
|
157
|
+
this.sexps.push(filename ? list(a`require`, quote(a`${feature}`), filename) : list(a`require`, quote(a`${feature}`)));
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Register S-expressions to evaluate.
|
|
162
|
+
*
|
|
163
|
+
* This function will append to the previous value.
|
|
164
|
+
* The `run` call will reset this value.
|
|
165
|
+
*/
|
|
166
|
+
progn(...sexps) {
|
|
167
|
+
this.sexps.push(...sexps);
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Register the string to be fed into the standard input.
|
|
172
|
+
*
|
|
173
|
+
* This function will replace the previous value.
|
|
174
|
+
* The `run` call will reset this value.
|
|
175
|
+
*/
|
|
176
|
+
minibuffer(content) {
|
|
177
|
+
this.stdin = content;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Run the registered S-expressions in Emacs.
|
|
182
|
+
*
|
|
183
|
+
* @rehturns The standard output of the Emacs process.
|
|
184
|
+
*/
|
|
185
|
+
run() {
|
|
186
|
+
const { stdout, stderr, error } = spawnSync("emacs", [
|
|
187
|
+
`--init-directory=${this.initDirectory}`,
|
|
188
|
+
"--batch",
|
|
189
|
+
"--eval",
|
|
190
|
+
stringify(list(a`progn`, ...this.sexps))
|
|
191
|
+
], { input: this.stdin });
|
|
192
|
+
if (error) throw new Error(`Error running Emacs: ${stderr}`, { cause: error });
|
|
193
|
+
this.sexps = [];
|
|
194
|
+
this.stdin = "";
|
|
195
|
+
return stdout.toString();
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/utilities.ts
|
|
201
|
+
/**
|
|
202
|
+
* Convert a lowerCamelCase string to kebab case.
|
|
203
|
+
*
|
|
204
|
+
* @param s The string to convert.
|
|
205
|
+
* @returns The kebab-cased string.
|
|
206
|
+
*/
|
|
207
|
+
function toKebabCase(s) {
|
|
208
|
+
return s.replace(/[A-Z]+(?!a-z)|[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/org-export.ts
|
|
213
|
+
/**
|
|
214
|
+
* Generate Emacs Lisp code to customize the Org export engine.
|
|
215
|
+
*/
|
|
216
|
+
function customize(options = {}) {
|
|
217
|
+
const transformed = Object.entries(options).flatMap(([key, val]) => {
|
|
218
|
+
switch (key) {
|
|
219
|
+
case "withProperties": return [a`org-export-with-properties`, Array.isArray(val) ? quote(list(...val)) : val];
|
|
220
|
+
case "withSmartQuotes":
|
|
221
|
+
case "withEmphasize":
|
|
222
|
+
case "withSpecialStrings":
|
|
223
|
+
case "withFixedWidth":
|
|
224
|
+
case "withTimestamps":
|
|
225
|
+
case "preserveBreaks":
|
|
226
|
+
case "withSubSuperscripts":
|
|
227
|
+
case "withArchivedTrees":
|
|
228
|
+
case "expandLinks":
|
|
229
|
+
case "withBrokenLinks":
|
|
230
|
+
case "withClocks":
|
|
231
|
+
case "withCreator":
|
|
232
|
+
case "withDrawers":
|
|
233
|
+
case "withDate":
|
|
234
|
+
case "withEntities":
|
|
235
|
+
case "withEmail":
|
|
236
|
+
case "withFootnotes":
|
|
237
|
+
case "headlineLevels":
|
|
238
|
+
case "withInlinetasks":
|
|
239
|
+
case "withSectionNumbers":
|
|
240
|
+
case "withPlanning":
|
|
241
|
+
case "withPriority":
|
|
242
|
+
case "withStatisticsCookies":
|
|
243
|
+
case "withTags":
|
|
244
|
+
case "withTasks":
|
|
245
|
+
case "withLatex":
|
|
246
|
+
case "timestampFile":
|
|
247
|
+
case "withTitle":
|
|
248
|
+
case "withToc":
|
|
249
|
+
case "todoKeywords":
|
|
250
|
+
case "withTables": return [a`org-export-${toKebabCase(key)}`, val];
|
|
251
|
+
default: return [];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
return list(a`setq`, ...transformed);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/org-svelte.ts
|
|
259
|
+
/**
|
|
260
|
+
* Generate Emacs Lisp code to customize the Org to Svelte export engine.
|
|
261
|
+
*/
|
|
262
|
+
function customize$1(options = {}) {
|
|
263
|
+
const transformed = Object.entries(options).flatMap(([key, val]) => {
|
|
264
|
+
switch (key) {
|
|
265
|
+
case "componentImportAlist": {
|
|
266
|
+
const cia = val;
|
|
267
|
+
return [a`org-svelte-component-import-alist`, quote(list(...Object.entries(cia).map(([k$1, v]) => {
|
|
268
|
+
if (Array.isArray(v)) return cons(k$1, list(...v));
|
|
269
|
+
else return cons(k$1, v);
|
|
270
|
+
})))];
|
|
271
|
+
}
|
|
272
|
+
case "metadataExportList": {
|
|
273
|
+
const mel = val;
|
|
274
|
+
return [a`org-svelte-metadata-export-list`, quote(list(...mel.map((v) => k`${v}`)))];
|
|
275
|
+
}
|
|
276
|
+
case "textMarkupAlist": {
|
|
277
|
+
const tma = val;
|
|
278
|
+
return [a`org-svelte-text-markup-alist`, quote(list(...Object.entries(tma).map(([key$1, val$1]) => cons(key$1, val$1))))];
|
|
279
|
+
}
|
|
280
|
+
case "anchorFormat":
|
|
281
|
+
case "brokenLinkFormat":
|
|
282
|
+
case "imageFormat":
|
|
283
|
+
case "latexEnviromnetFormat":
|
|
284
|
+
case "latexDisplayFragmentFormat":
|
|
285
|
+
case "latexInlineFragmentFormat":
|
|
286
|
+
case "linkOrgFileAsSvelte":
|
|
287
|
+
case "rawScriptContent":
|
|
288
|
+
case "srcBlockFormat":
|
|
289
|
+
case "verbose": return [a`org-svelte-${toKebabCase(key)}`, val];
|
|
290
|
+
default: return [];
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
return list(a`setq`, ...transformed);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Export an Org document as Svelte code.
|
|
297
|
+
*
|
|
298
|
+
* Note: This function expects the content of the Org document to be provided
|
|
299
|
+
* via minibuffer input (i.e., stdin).
|
|
300
|
+
*
|
|
301
|
+
* @param options Customization options for the export.
|
|
302
|
+
* @returns The generated Svelte component as a string.
|
|
303
|
+
*/
|
|
304
|
+
const exportMinibufferAsSvelte = list(a`let`, list(list(a`content`, ``)), list(a`while`, list(a`setq`, a`line`, list(a`ignore-errors`, list(a`read-string`, ``))), list(a`setq`, a`content`, list(a`concat`, a`content`, `\\n`, a`line`))), list(a`with-temp-buffer`, list(a`org-mode`), list(a`insert`, a`content`), list(a`org-svelte-export-as-svelte`), list(a`princ`, list(a`buffer-string`))));
|
|
305
|
+
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/index.ts
|
|
308
|
+
/**
|
|
309
|
+
* Preprocess Org documents to Svelte components.
|
|
310
|
+
*/
|
|
311
|
+
function orgPreprocess(options) {
|
|
312
|
+
const { extensions = [".org"], idLocations = [], initDirectory = mkdtempSync(join(tmpdir(), "svelte-preprocess-org-")), initSexps = [],...rest } = options || {};
|
|
313
|
+
const emacs = new Emacs(initDirectory);
|
|
314
|
+
if (initSexps.length > 0) emacs.progn(...initSexps).run();
|
|
315
|
+
if (idLocations.length > 0) {
|
|
316
|
+
const files = globSync(idLocations);
|
|
317
|
+
if (files.length > 0) emacs.require("org").progn(list(a`org-id-update-id-locations`, quote(list(...files)))).run();
|
|
318
|
+
}
|
|
319
|
+
return { markup({ content, filename }) {
|
|
320
|
+
if (filename && !extensions.some((ext) => filename.endsWith(ext))) return { code: content };
|
|
321
|
+
const code = emacs.require("ox-svelte", fullpath).progn(customize(rest)).progn(customize$1(rest)).progn(exportMinibufferAsSvelte).minibuffer(content).run();
|
|
322
|
+
return { code };
|
|
323
|
+
} };
|
|
324
|
+
}
|
|
325
|
+
var src_default = orgPreprocess;
|
|
326
|
+
|
|
327
|
+
//#endregion
|
|
328
|
+
export { src_default as default, orgPreprocess };
|
package/package.json
CHANGED
|
@@ -1,45 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-preprocess-org",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "Svelte preprocessor for Org-mode",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Svelte preprocessor for Org-mode documents",
|
|
6
5
|
"author": "RangHo Lee <hello@rangho.me>",
|
|
7
6
|
"homepage": "https://github.com/RangHo/svelte-preprocess-org",
|
|
8
7
|
"license": "GPL-3.0-or-later",
|
|
8
|
+
"type": "module",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
|
-
"files":
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/*"
|
|
13
|
+
],
|
|
15
14
|
"devDependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"@tsconfig/node-lts": "^20.1.1",
|
|
21
|
-
"@types/jest": "^29.5.12",
|
|
22
|
-
"@types/node": "^20.11.19",
|
|
23
|
-
"eslint": "^8.56.0",
|
|
24
|
-
"jest": "^29.7.0",
|
|
25
|
-
"ox-svelte": "^0.1.0",
|
|
26
|
-
"prettier": "^3.1.1",
|
|
27
|
-
"rollup": "^4.12.0",
|
|
28
|
-
"rollup-plugin-copy": "^3.5.0",
|
|
29
|
-
"svelte": "^4.2.12",
|
|
30
|
-
"ts-jest": "^29.1.2",
|
|
31
|
-
"tslib": "^2.6.2",
|
|
32
|
-
"typescript": "^5.3.3",
|
|
33
|
-
"typescript-eslint": "^7.2.0"
|
|
15
|
+
"@tsconfig/node-lts": "^22.0.2",
|
|
16
|
+
"@types/node": "^22.17.0",
|
|
17
|
+
"ox-svelte": "0.4.4",
|
|
18
|
+
"svelte": "^5.2.11"
|
|
34
19
|
},
|
|
35
20
|
"peerDependencies": {
|
|
36
|
-
"ox-svelte": "
|
|
37
|
-
"svelte": "^
|
|
21
|
+
"ox-svelte": "0.4.4",
|
|
22
|
+
"svelte": "^5.2.11"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"tinyglobby": "^0.2.14"
|
|
38
26
|
},
|
|
39
27
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"build:watch": "tsdown --watch",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"test:watch": "vitest watch",
|
|
42
32
|
"format": "prettier --write .",
|
|
43
|
-
"
|
|
33
|
+
"format:check": "prettier --check .",
|
|
34
|
+
"lint": "eslint . --fix",
|
|
35
|
+
"lint:check": "eslint ."
|
|
44
36
|
}
|
|
45
37
|
}
|
package/.editorconfig
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# This is the top-level editorconfig
|
|
2
|
-
root = true
|
|
3
|
-
|
|
4
|
-
# General file conventions
|
|
5
|
-
charset = utf-8
|
|
6
|
-
trim_trailing_whitespace = true
|
|
7
|
-
end_of_line = lf
|
|
8
|
-
insert_final_newline = true
|
|
9
|
-
max_line_length = 120
|
|
10
|
-
|
|
11
|
-
# JavaScript and TypeScript files
|
|
12
|
-
[*.{js,cjs,mjs,ts,cts,mts}]
|
|
13
|
-
indent_style = space
|
|
14
|
-
indent_size = 2
|
|
15
|
-
|
package/.gitmodules
DELETED
package/README.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Svelte Preprocessor for Org-mode Documents
|
|
2
|
-
|
|
3
|
-
[Svelte](https://svelte.dev/) preprocessor to import [Org mode](https://orgmode.org)
|
|
4
|
-
documents as a component, powered by [ox-svelte](https://github.com/RangHo/ox-svelte).
|
|
5
|
-
|
|
6
|
-
## Prerequisites
|
|
7
|
-
|
|
8
|
-
This package deliberately refrains from parsing Org mode documents.
|
|
9
|
-
These processes are delegated to an actual instance of Emacs.
|
|
10
|
-
|
|
11
|
-
Therefore, you need **Emacs 29** or newer installed on your system.
|
package/dist/emacs.d.ts
DELETED
package/dist/lisp/convert.el
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
;;; convert.el --- Read Org-mode files from stdin and write Svelte components to stdout.
|
|
2
|
-
|
|
3
|
-
;; Author: RangHo Lee <hello@rangho.me>
|
|
4
|
-
|
|
5
|
-
;;; Commentary:
|
|
6
|
-
|
|
7
|
-
;; This script accepts the content of an Org-mode file from stdin, converts it
|
|
8
|
-
;; to a Svelte component, and writes the result to stdout. This is an Emacs
|
|
9
|
-
;; Lisp script; that is, it needs to be run with Emacs in batch mode.
|
|
10
|
-
;;
|
|
11
|
-
;; It uses `ox-svelte' to perform the conversion. Make sure that `ox-svelte'
|
|
12
|
-
;; repository is checked out in the same directory, preferably as a git
|
|
13
|
-
;; submodule.
|
|
14
|
-
;;
|
|
15
|
-
;; This script accepts the following command line arguments:
|
|
16
|
-
;; --preface <elisp-code>
|
|
17
|
-
;; Evaluate the given Elisp code before processing.
|
|
18
|
-
;; --latex-environment-format <format>
|
|
19
|
-
;; Set the format of LaTeX environment to <format>. The format string
|
|
20
|
-
;; should contain a single `%s' with which the LaTeX environment content
|
|
21
|
-
;; will be replaced as a JavaScript raw string.
|
|
22
|
-
;; --latex-fragment-format <format>
|
|
23
|
-
;; Set the format of LaTeX fragment to <format>. The format string
|
|
24
|
-
;; should contain a single `%s' with which the LaTeX fragment content
|
|
25
|
-
;; will be replaced as a JavaScript raw string.
|
|
26
|
-
;; --src-block-format <format>
|
|
27
|
-
;; Set the format of source block to <format>. The format string should
|
|
28
|
-
;; contain two `%s' with which the language and the content of the src
|
|
29
|
-
;; block will be replaced as a JavaScript raw string.
|
|
30
|
-
;;
|
|
31
|
-
;; To allow more smooth preprocessor chaning, this script sets some arbitrary
|
|
32
|
-
;; options to Org-mode exporter engine. You can customize the behavior of the
|
|
33
|
-
;; exporter by setting command line arguments, or by providing preface S-exps.
|
|
34
|
-
|
|
35
|
-
;;; Code:
|
|
36
|
-
|
|
37
|
-
(require 'ox-svelte
|
|
38
|
-
(expand-file-name "ox-svelte/ox-svelte.el"
|
|
39
|
-
(file-name-directory load-file-name)))
|
|
40
|
-
|
|
41
|
-
;; Set default settings
|
|
42
|
-
(setq org-export-with-section-numbers nil)
|
|
43
|
-
|
|
44
|
-
;; Process command line arguments
|
|
45
|
-
(let ((i 0))
|
|
46
|
-
(while (elt argv i)
|
|
47
|
-
(cond
|
|
48
|
-
;; Evaluate the preface S-exp if provided
|
|
49
|
-
((string= (elt argv i) "--preface")
|
|
50
|
-
(eval (car (read-from-string (elt argv (1+ i)))))
|
|
51
|
-
(setq i (1+ i)))
|
|
52
|
-
|
|
53
|
-
;; Set the LaTeX environment format
|
|
54
|
-
((string= (elt argv i) "--latex-environment-format")
|
|
55
|
-
(setq org-svelte-latex-environment-format (elt argv (1+ i)))
|
|
56
|
-
(setq i (1+ i)))
|
|
57
|
-
|
|
58
|
-
;; Set the LaTeX fragment format
|
|
59
|
-
((string= (elt argv i) "--latex-fragment-format")
|
|
60
|
-
(setq org-svelte-latex-fragment-format (elt argv (1+ i)))
|
|
61
|
-
(setq i (1+ i)))
|
|
62
|
-
|
|
63
|
-
;; Set the source block format
|
|
64
|
-
((string= (elt argv i) "--src-block-format")
|
|
65
|
-
(setq org-svelte-src-block-format (elt argv (1+ i)))
|
|
66
|
-
(setq i (1+ i)))
|
|
67
|
-
|
|
68
|
-
;; No match found, warn the user and do nothing
|
|
69
|
-
(t
|
|
70
|
-
(warn (format "Unsupported argument: %s" (elt argv i)))))
|
|
71
|
-
|
|
72
|
-
(setq i (1+ i))))
|
|
73
|
-
|
|
74
|
-
;; Read the content of the Org-mode file from stdin and convert
|
|
75
|
-
(with-temp-buffer
|
|
76
|
-
(while (condition-case err
|
|
77
|
-
(setq line (read-from-minibuffer ""))
|
|
78
|
-
(error nil))
|
|
79
|
-
(insert line "\n"))
|
|
80
|
-
(org-svelte-export-as-svelte)
|
|
81
|
-
(princ (buffer-string)))
|
|
82
|
-
|
|
83
|
-
;; Exit Emacs after conversion to prevent unnecessary errors
|
|
84
|
-
(kill-emacs 0)
|
|
85
|
-
|
|
86
|
-
;;; convert.el ends here
|