@orgajs/orgx 1.0.7 → 2.0.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/LICENSE.org +22 -0
- package/dist/index.d.ts +11 -5
- package/dist/lib/compile.d.ts +45 -0
- package/dist/lib/condition.browser.d.ts +1 -0
- package/dist/lib/condition.d.ts +1 -0
- package/dist/lib/core.d.ts +57 -0
- package/dist/lib/evaluate.d.ts +27 -0
- package/dist/lib/plugin/recma-document.d.ts +63 -0
- package/dist/lib/plugin/recma-jsx-build.d.ts +14 -0
- package/dist/lib/plugin/recma-jsx-rewrite.d.ts +50 -0
- package/dist/lib/plugin/recma-stringify.d.ts +13 -0
- package/dist/lib/plugin/rehype-recma.d.ts +49 -0
- package/dist/lib/run.d.ts +26 -0
- package/dist/lib/util/estree-util-create.d.ts +13 -0
- package/dist/lib/util/estree-util-declaration-to-expression.d.ts +19 -0
- package/dist/lib/util/estree-util-is-declaration.d.ts +15 -0
- package/dist/lib/util/estree-util-specifiers-to-declarations.d.ts +14 -0
- package/dist/lib/util/estree-util-to-binary-addition.d.ts +8 -0
- package/dist/lib/util/estree-util-to-id-or-member-expression.d.ts +11 -0
- package/dist/lib/util/render-error.d.ts +2 -0
- package/dist/lib/util/resolve-evaluate-options.d.ts +66 -0
- package/dist/lib/util/resolve-file-and-options.d.ts +16 -0
- package/index.js +14 -0
- package/lib/compile.js +54 -0
- package/lib/condition.browser.js +1 -0
- package/lib/condition.js +3 -0
- package/lib/core.js +100 -0
- package/lib/evaluate.js +41 -0
- package/lib/plugin/recma-document.js +607 -0
- package/lib/plugin/recma-jsx-build.js +53 -0
- package/lib/plugin/recma-jsx-rewrite.js +616 -0
- package/lib/plugin/recma-stringify.js +42 -0
- package/lib/plugin/rehype-recma.js +218 -0
- package/lib/run.js +31 -0
- package/lib/types.d.ts +46 -0
- package/lib/util/estree-util-create.js +27 -0
- package/lib/util/estree-util-declaration-to-expression.js +32 -0
- package/lib/util/estree-util-is-declaration.js +20 -0
- package/lib/util/estree-util-specifiers-to-declarations.js +90 -0
- package/lib/util/estree-util-to-binary-addition.js +23 -0
- package/lib/util/estree-util-to-id-or-member-expression.js +108 -0
- package/lib/util/render-error.js +91 -0
- package/lib/util/resolve-evaluate-options.js +64 -0
- package/lib/util/resolve-file-and-options.js +40 -0
- package/package.json +36 -29
- package/CHANGELOG.md +0 -71
- package/dist/compile.d.ts +0 -6
- package/dist/compile.d.ts.map +0 -1
- package/dist/compile.js +0 -12
- package/dist/compile.js.map +0 -1
- package/dist/estree/create.d.ts +0 -2
- package/dist/estree/create.d.ts.map +0 -1
- package/dist/estree/create.js +0 -14
- package/dist/estree/create.js.map +0 -1
- package/dist/estree/declaration-to-expression.d.ts +0 -3
- package/dist/estree/declaration-to-expression.d.ts.map +0 -1
- package/dist/estree/declaration-to-expression.js +0 -12
- package/dist/estree/declaration-to-expression.js.map +0 -1
- package/dist/estree/error.d.ts +0 -61
- package/dist/estree/error.d.ts.map +0 -1
- package/dist/estree/error.js +0 -87
- package/dist/estree/error.js.map +0 -1
- package/dist/estree/is-declaration.d.ts +0 -3
- package/dist/estree/is-declaration.d.ts.map +0 -1
- package/dist/estree/is-declaration.js +0 -9
- package/dist/estree/is-declaration.js.map +0 -1
- package/dist/estree/position-from-estree.d.ts +0 -13
- package/dist/estree/position-from-estree.d.ts.map +0 -1
- package/dist/estree/position-from-estree.js +0 -34
- package/dist/estree/position-from-estree.js.map +0 -1
- package/dist/estree/specifiers-to-object-pattern.d.ts +0 -5
- package/dist/estree/specifiers-to-object-pattern.d.ts.map +0 -1
- package/dist/estree/specifiers-to-object-pattern.js +0 -33
- package/dist/estree/specifiers-to-object-pattern.js.map +0 -1
- package/dist/evaluate.d.ts +0 -22
- package/dist/evaluate.d.ts.map +0 -1
- package/dist/evaluate.js +0 -27
- package/dist/evaluate.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -11
- package/dist/index.js.map +0 -1
- package/dist/plugin/estree-jsx-build.d.ts +0 -6
- package/dist/plugin/estree-jsx-build.d.ts.map +0 -1
- package/dist/plugin/estree-jsx-build.js +0 -38
- package/dist/plugin/estree-jsx-build.js.map +0 -1
- package/dist/plugin/estree-jsx-rewrite.d.ts +0 -6
- package/dist/plugin/estree-jsx-rewrite.d.ts.map +0 -1
- package/dist/plugin/estree-jsx-rewrite.js +0 -214
- package/dist/plugin/estree-jsx-rewrite.js.map +0 -1
- package/dist/plugin/estree-stringify.d.ts +0 -2
- package/dist/plugin/estree-stringify.d.ts.map +0 -1
- package/dist/plugin/estree-stringify.js +0 -127
- package/dist/plugin/estree-stringify.js.map +0 -1
- package/dist/plugin/estree-wrap-in-content.d.ts +0 -18
- package/dist/plugin/estree-wrap-in-content.d.ts.map +0 -1
- package/dist/plugin/estree-wrap-in-content.js +0 -375
- package/dist/plugin/estree-wrap-in-content.js.map +0 -1
- package/dist/plugin/rehype-estree.d.ts +0 -12
- package/dist/plugin/rehype-estree.d.ts.map +0 -1
- package/dist/plugin/rehype-estree.js +0 -122
- package/dist/plugin/rehype-estree.js.map +0 -1
- package/dist/plugin/rehype-set-layout.d.ts +0 -6
- package/dist/plugin/rehype-set-layout.d.ts.map +0 -1
- package/dist/plugin/rehype-set-layout.js +0 -30
- package/dist/plugin/rehype-set-layout.js.map +0 -1
- package/dist/processor.d.ts +0 -14
- package/dist/processor.d.ts.map +0 -1
- package/dist/processor.js +0 -52
- package/dist/processor.js.map +0 -1
- package/dist/utils/remove-quotes.d.ts +0 -3
- package/dist/utils/remove-quotes.d.ts.map +0 -1
- package/dist/utils/remove-quotes.js +0 -6
- package/dist/utils/remove-quotes.js.map +0 -1
package/lib/core.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('unified').PluggableList} PluggableList
|
|
3
|
+
* @typedef {import('unified').Processor} Processor
|
|
4
|
+
* @typedef {import('./plugin/rehype-recma.js').Options} RehypeRecmaOptions
|
|
5
|
+
* @typedef {import('./plugin/recma-document.js').RecmaDocumentOptions} RecmaDocumentOptions
|
|
6
|
+
* @typedef {import('./plugin/recma-stringify.js').RecmaStringifyOptions} RecmaStringifyOptions
|
|
7
|
+
* @typedef {import('./plugin/recma-jsx-rewrite.js').RecmaJsxRewriteOptions} RecmaJsxRewriteOptions
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef BaseProcessorOptions
|
|
12
|
+
* Base configuration.
|
|
13
|
+
* @property {boolean | null | undefined} [jsx=false]
|
|
14
|
+
* Whether to keep JSX.
|
|
15
|
+
* Format of the files to be processed.
|
|
16
|
+
* @property {'function-body' | 'program'} [outputFormat='program']
|
|
17
|
+
* Whether to compile to a whole program or a function body..
|
|
18
|
+
* @property {PluggableList | null | undefined} [recmaPlugins]
|
|
19
|
+
* List of recma (esast, JavaScript) plugins.
|
|
20
|
+
* @property {PluggableList | null | undefined} [reorgPlugins]
|
|
21
|
+
* List of remark (mdast, markdown) plugins.
|
|
22
|
+
* @property {PluggableList | null | undefined} [rehypePlugins]
|
|
23
|
+
* List of rehype (hast, HTML) plugins.
|
|
24
|
+
* @property {import('@orgajs/reorg-rehype').Options | null | undefined} [reorgRehypeOptions]
|
|
25
|
+
* Options to pass through to `reorg-rehype`.
|
|
26
|
+
*
|
|
27
|
+
* @typedef {Omit<RehypeRecmaOptions & RecmaDocumentOptions & RecmaStringifyOptions & RecmaJsxRewriteOptions, 'outputFormat'>} PluginOptions
|
|
28
|
+
* Configuration for internal plugins.
|
|
29
|
+
*
|
|
30
|
+
* @typedef {BaseProcessorOptions & PluginOptions} ProcessorOptions
|
|
31
|
+
* Configuration for processor.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { unified } from 'unified'
|
|
35
|
+
import reorgParse from '@orgajs/reorg-parse'
|
|
36
|
+
import reorgRehype from '@orgajs/reorg-rehype'
|
|
37
|
+
import { recmaJsxBuild } from './plugin/recma-jsx-build.js'
|
|
38
|
+
import { recmaDocument } from './plugin/recma-document.js'
|
|
39
|
+
import { recmaJsxRewrite } from './plugin/recma-jsx-rewrite.js'
|
|
40
|
+
import { recmaStringify } from './plugin/recma-stringify.js'
|
|
41
|
+
import { rehypeRecma } from './plugin/rehype-recma.js'
|
|
42
|
+
// import { remarkMarkAndUnravel } from './plugin/remark-mark-and-unravel.js'
|
|
43
|
+
import { development as defaultDevelopment } from './condition.js'
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Pipeline to:
|
|
47
|
+
*
|
|
48
|
+
* 1. Parse org-mode
|
|
49
|
+
* 2. Transform through reorg (oast), rehype (hast), and recma (esast)
|
|
50
|
+
* 3. Serialize as JavaScript
|
|
51
|
+
*
|
|
52
|
+
* @param {ProcessorOptions | null | undefined} [options]
|
|
53
|
+
* Configuration.
|
|
54
|
+
* @return {Processor}
|
|
55
|
+
* Processor.
|
|
56
|
+
*/
|
|
57
|
+
export function createProcessor(options) {
|
|
58
|
+
const {
|
|
59
|
+
development,
|
|
60
|
+
jsx,
|
|
61
|
+
outputFormat,
|
|
62
|
+
providerImportSource,
|
|
63
|
+
recmaPlugins,
|
|
64
|
+
rehypePlugins,
|
|
65
|
+
reorgPlugins,
|
|
66
|
+
reorgRehypeOptions,
|
|
67
|
+
elementAttributeNameCase,
|
|
68
|
+
stylePropertyNameCase,
|
|
69
|
+
SourceMapGenerator,
|
|
70
|
+
...rest
|
|
71
|
+
} = options || {}
|
|
72
|
+
const dev =
|
|
73
|
+
development === null || development === undefined
|
|
74
|
+
? defaultDevelopment
|
|
75
|
+
: development
|
|
76
|
+
|
|
77
|
+
const pipeline = unified()
|
|
78
|
+
.use(reorgParse)
|
|
79
|
+
.use(reorgPlugins || [])
|
|
80
|
+
.use(reorgRehype, {
|
|
81
|
+
...reorgRehypeOptions,
|
|
82
|
+
allowDangerousHtml: true,
|
|
83
|
+
})
|
|
84
|
+
.use(rehypePlugins || [])
|
|
85
|
+
.use(rehypeRecma, { elementAttributeNameCase, stylePropertyNameCase })
|
|
86
|
+
.use(recmaDocument, { ...rest, outputFormat })
|
|
87
|
+
.use(recmaJsxRewrite, {
|
|
88
|
+
development: dev,
|
|
89
|
+
providerImportSource,
|
|
90
|
+
outputFormat,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
if (!jsx) {
|
|
94
|
+
pipeline.use(recmaJsxBuild, { development: dev, outputFormat })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
pipeline.use(recmaStringify, { SourceMapGenerator }).use(recmaPlugins || [])
|
|
98
|
+
|
|
99
|
+
return pipeline
|
|
100
|
+
}
|
package/lib/evaluate.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./types.js').OrgModule} ExportMap
|
|
3
|
+
* @typedef {import('vfile').VFileCompatible} VFileCompatible
|
|
4
|
+
* @typedef {import('./util/resolve-evaluate-options.js').EvaluateOptions} EvaluateOptions
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { compile, compileSync } from './compile.js'
|
|
8
|
+
import { run, runSync } from './run.js'
|
|
9
|
+
import { resolveEvaluateOptions } from './util/resolve-evaluate-options.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Evaluate MDX.
|
|
13
|
+
*
|
|
14
|
+
* @param {VFileCompatible} vfileCompatible
|
|
15
|
+
* MDX document to parse (`string`, `Buffer`, `vfile`, anything that can be
|
|
16
|
+
* given to `vfile`).
|
|
17
|
+
* @param {EvaluateOptions} evaluateOptions
|
|
18
|
+
* Configuration for evaluation.
|
|
19
|
+
* @return {Promise<ExportMap>}
|
|
20
|
+
* Export map.
|
|
21
|
+
*/
|
|
22
|
+
export async function evaluate(vfileCompatible, evaluateOptions) {
|
|
23
|
+
const { compiletime, runtime } = resolveEvaluateOptions(evaluateOptions)
|
|
24
|
+
return run(await compile(vfileCompatible, compiletime), runtime)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Synchronously evaluate MDX.
|
|
29
|
+
*
|
|
30
|
+
* @param {VFileCompatible} vfileCompatible
|
|
31
|
+
* MDX document to parse (`string`, `Buffer`, `vfile`, anything that can be
|
|
32
|
+
* given to `vfile`).
|
|
33
|
+
* @param {EvaluateOptions} evaluateOptions
|
|
34
|
+
* Configuration for evaluation.
|
|
35
|
+
* @return {ExportMap}
|
|
36
|
+
* Export map.
|
|
37
|
+
*/
|
|
38
|
+
export function evaluateSync(vfileCompatible, evaluateOptions) {
|
|
39
|
+
const { compiletime, runtime } = resolveEvaluateOptions(evaluateOptions)
|
|
40
|
+
return runSync(compileSync(vfileCompatible, compiletime), runtime)
|
|
41
|
+
}
|