sommark 4.5.3 → 5.0.1

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.
Files changed (41) hide show
  1. package/README.md +315 -179
  2. package/cli/cli.mjs +1 -1
  3. package/cli/commands/color.js +36 -14
  4. package/cli/commands/help.js +3 -0
  5. package/cli/commands/init.js +1 -3
  6. package/cli/constants.js +5 -2
  7. package/constants/html_props.js +0 -5
  8. package/core/errors.js +5 -4
  9. package/core/evaluator.js +1 -2
  10. package/core/formats.js +7 -1
  11. package/core/helpers/config-loader.js +2 -4
  12. package/core/helpers/lib.js +1 -1
  13. package/core/labels.js +2 -15
  14. package/core/lexer.js +197 -313
  15. package/core/modules.js +13 -13
  16. package/core/parser.js +226 -535
  17. package/core/tokenTypes.js +6 -15
  18. package/core/transpiler.js +129 -110
  19. package/core/validator.js +6 -26
  20. package/dist/sommark.browser.js +1781 -2172
  21. package/dist/sommark.browser.lite.js +1779 -2169
  22. package/dist/sommark.lexer.js +392 -544
  23. package/dist/sommark.parser.js +604 -1200
  24. package/formatter/mark.js +34 -0
  25. package/formatter/tag.js +7 -33
  26. package/helpers/utils.js +15 -16
  27. package/index.js +9 -1
  28. package/index.shared.js +26 -16
  29. package/mappers/languages/csv.js +62 -0
  30. package/mappers/languages/html.js +12 -66
  31. package/mappers/languages/json.js +74 -156
  32. package/mappers/languages/jsonc.js +21 -63
  33. package/mappers/languages/markdown.js +159 -276
  34. package/mappers/languages/mdx.js +7 -62
  35. package/mappers/languages/text.js +2 -19
  36. package/mappers/languages/toml.js +231 -0
  37. package/mappers/languages/xml.js +25 -25
  38. package/mappers/languages/yaml.js +323 -0
  39. package/mappers/mapper.js +1 -22
  40. package/mappers/shared/index.js +3 -16
  41. 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.args)) {
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.args[argKey] = variables[varKey];
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.args !== undefined) {
118
- nodeCopy.args = { ...node.args };
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.args).find(k => isNaN(k));
229
- let filePath = alias ? node.args[alias] : node.args[0];
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.args[0] || Object.values(node.args)[0];
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
- args: { filename: mod.path },
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.args);
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.args.__consumed__ || new Set();
385
+ const consumed = node.props.__consumed__ || new Set();
386
386
 
387
387
  const publicArgs = Object.fromEntries(
388
- Object.entries(node.args).filter(([key]) => {
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.args = { ...rootTag.args, ...publicArgs };
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
- args: { filename: mod.path },
400
+ props: { filename: mod.path },
401
401
  body: expandedNodes
402
402
  };
403
403
  nodes.splice(i, 1, boundaryNode);