sommark 4.5.3 → 5.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/README.md +314 -178
- package/cli/cli.mjs +1 -1
- package/cli/commands/color.js +36 -14
- package/cli/commands/help.js +3 -0
- package/cli/commands/init.js +0 -2
- package/cli/constants.js +5 -2
- package/core/errors.js +5 -4
- package/core/evaluator.js +1 -2
- package/core/formats.js +7 -1
- package/core/helpers/config-loader.js +1 -3
- package/core/helpers/lib.js +1 -1
- package/core/labels.js +2 -15
- package/core/lexer.js +197 -313
- package/core/modules.js +13 -13
- package/core/parser.js +226 -535
- package/core/tokenTypes.js +6 -15
- package/core/transpiler.js +129 -110
- package/core/validator.js +6 -26
- package/dist/sommark.browser.js +1777 -2163
- package/dist/sommark.browser.lite.js +1775 -2160
- package/dist/sommark.lexer.js +392 -544
- package/dist/sommark.parser.js +604 -1200
- package/formatter/mark.js +34 -0
- package/formatter/tag.js +7 -33
- package/helpers/utils.js +15 -16
- package/index.js +9 -1
- package/index.shared.js +22 -12
- package/mappers/languages/csv.js +62 -0
- package/mappers/languages/html.js +12 -66
- package/mappers/languages/json.js +74 -156
- package/mappers/languages/jsonc.js +21 -63
- package/mappers/languages/markdown.js +159 -276
- package/mappers/languages/mdx.js +7 -62
- package/mappers/languages/text.js +2 -19
- package/mappers/languages/toml.js +231 -0
- package/mappers/languages/xml.js +25 -25
- package/mappers/languages/yaml.js +323 -0
- package/mappers/mapper.js +1 -22
- package/mappers/shared/index.js +3 -16
- package/package.json +5 -2
package/core/modules.js
CHANGED
|
@@ -70,11 +70,11 @@ const resolveAstVariables = (nodes, variables) => {
|
|
|
70
70
|
}
|
|
71
71
|
} else if (node.type === BLOCK) {
|
|
72
72
|
// Resolve any unresolved variables in block arguments
|
|
73
|
-
for (const [argKey, argVal] of Object.entries(node.
|
|
73
|
+
for (const [argKey, argVal] of Object.entries(node.props)) {
|
|
74
74
|
if (typeof argVal === "string" && argVal.startsWith(VAR_PREFIX) && argVal.endsWith(VAR_SUFFIX)) {
|
|
75
75
|
const varKey = argVal.slice(VAR_PREFIX.length, -VAR_SUFFIX.length);
|
|
76
76
|
if (variables[varKey] !== undefined) {
|
|
77
|
-
node.
|
|
77
|
+
node.props[argKey] = variables[varKey];
|
|
78
78
|
if (!variables.__consumed__) {
|
|
79
79
|
Object.defineProperty(variables, "__consumed__", {
|
|
80
80
|
value: new Set(),
|
|
@@ -114,8 +114,8 @@ const cloneAst = (nodes) => {
|
|
|
114
114
|
if (node.id !== undefined) nodeCopy.id = node.id;
|
|
115
115
|
if (node.code !== undefined) nodeCopy.code = node.code;
|
|
116
116
|
if (node.isSelfClosing !== undefined) nodeCopy.isSelfClosing = node.isSelfClosing;
|
|
117
|
-
if (node.
|
|
118
|
-
nodeCopy.
|
|
117
|
+
if (node.props !== undefined) {
|
|
118
|
+
nodeCopy.props = { ...node.props };
|
|
119
119
|
}
|
|
120
120
|
if (node.body !== undefined) {
|
|
121
121
|
nodeCopy.body = cloneAst(node.body);
|
|
@@ -225,8 +225,8 @@ export async function resolveModules(ast, context) {
|
|
|
225
225
|
runtimeError([`<$red:Module Placement Error:$> Imports must be declared at the top level before any content at line <$yellow:${node.range.start.line + 1}$>`]);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
const alias = Object.keys(node.
|
|
229
|
-
let filePath = alias ? node.
|
|
228
|
+
const alias = Object.keys(node.props).find(k => isNaN(k));
|
|
229
|
+
let filePath = alias ? node.props[alias] : node.props[0];
|
|
230
230
|
if (typeof filePath === "string") filePath = filePath.trim().replace(/^["']|["']$/g, "");
|
|
231
231
|
|
|
232
232
|
// 1a. Handle Aliases
|
|
@@ -269,7 +269,7 @@ export async function resolveModules(ast, context) {
|
|
|
269
269
|
// 2. Handle Usage Node: [$use-module = alias]
|
|
270
270
|
else if (node.type === USE_MODULE) {
|
|
271
271
|
hasContentStarted = true;
|
|
272
|
-
const alias = node.
|
|
272
|
+
const alias = node.props[0] || Object.values(node.props)[0];
|
|
273
273
|
if (!alias || !modules.has(alias)) {
|
|
274
274
|
runtimeError([`<$red:Module Usage Error:$> Undefined module alias <$magenta:${alias}$> at line <$yellow:${node.range.start.line + 1}$>`]);
|
|
275
275
|
}
|
|
@@ -320,7 +320,7 @@ export async function resolveModules(ast, context) {
|
|
|
320
320
|
const boundaryNode = {
|
|
321
321
|
type: BLOCK,
|
|
322
322
|
id: context.instance.moduleIdentityToken,
|
|
323
|
-
|
|
323
|
+
props: { filename: mod.path },
|
|
324
324
|
body: expandedNodes
|
|
325
325
|
};
|
|
326
326
|
nodes.splice(i, 1, boundaryNode);
|
|
@@ -376,28 +376,28 @@ export async function resolveModules(ast, context) {
|
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
// Dynamically resolve variable placeholders inside the cloned AST
|
|
379
|
-
resolveAstVariables(subAst, node.
|
|
379
|
+
resolveAstVariables(subAst, node.props);
|
|
380
380
|
|
|
381
381
|
await processNodes(node.body, currentBaseDir, false);
|
|
382
382
|
const expandedNodes = injectSlots(trimAst(subAst), trimAst(node.body));
|
|
383
383
|
const rootTag = expandedNodes.find(n => n.type === BLOCK);
|
|
384
384
|
if (rootTag) {
|
|
385
|
-
const consumed = node.
|
|
385
|
+
const consumed = node.props.__consumed__ || new Set();
|
|
386
386
|
|
|
387
387
|
const publicArgs = Object.fromEntries(
|
|
388
|
-
Object.entries(node.
|
|
388
|
+
Object.entries(node.props).filter(([key]) => {
|
|
389
389
|
if (key === "__consumed__") return false;
|
|
390
390
|
if (consumed.has(key)) return false; // THE FIX: Filter if hit by v{}
|
|
391
391
|
return true;
|
|
392
392
|
})
|
|
393
393
|
);
|
|
394
|
-
rootTag.
|
|
394
|
+
rootTag.props = { ...rootTag.props, ...publicArgs };
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
const boundaryNode = {
|
|
398
398
|
type: BLOCK,
|
|
399
399
|
id: context.instance.moduleIdentityToken,
|
|
400
|
-
|
|
400
|
+
props: { filename: mod.path },
|
|
401
401
|
body: expandedNodes
|
|
402
402
|
};
|
|
403
403
|
nodes.splice(i, 1, boundaryNode);
|