sommark 3.3.0 → 3.3.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.
@@ -54,6 +54,11 @@ export default {
54
54
  // ========================================================================== //
55
55
  // 2. Formatting Logic //
56
56
  // ========================================================================== //
57
+ const shouldQuote = (val) => {
58
+ if (typeof val !== "string") return false;
59
+ return /[ \t\n\r,:[\]()@#]/.test(val);
60
+ };
61
+
57
62
  const formatArgs = (args, type) => {
58
63
  if (!args || args.length === 0) return "";
59
64
  let usedKeys = new Set();
@@ -73,8 +78,15 @@ export default {
73
78
  }
74
79
 
75
80
  let escapedVal = escapeArg(val, type);
81
+ if (shouldQuote(val)) {
82
+ const quotedVal = String(val)
83
+ .replace(/\\/g, "\\\\")
84
+ .replace(/"/g, '\\"');
85
+ escapedVal = `"${quotedVal}"`;
86
+ }
87
+
76
88
  if (matchedKey) {
77
- formattedArgs.push(`${matchedKey}:${escapedVal}`);
89
+ formattedArgs.push(`${matchedKey}: ${escapedVal}`);
78
90
  } else {
79
91
  formattedArgs.push(escapedVal);
80
92
  }
@@ -183,7 +195,8 @@ export default {
183
195
  result += `${innerIndentStr}[end]\n`;
184
196
  } else if (child.type === "AtBlock") {
185
197
  const argsStr = formatArgs(child.args, "AtBlock");
186
- result += `${innerIndentStr}@_${child.id}_@${argsStr}\n`;
198
+ const atHeader = argsStr ? `@_${child.id}_@${argsStr}` : `@_${child.id}_@;`;
199
+ result += `${innerIndentStr}${atHeader}\n`;
187
200
  if (child.content) {
188
201
  // ========================================================================== //
189
202
  // Remove leading spaces from messy text block and re-indent //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sommark",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "SomMark is a declarative, extensible markup language for structured content that can be converted to HTML, Markdown, MDX, JSON, and more.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -0,0 +1,42 @@
1
+ import SomMark from './index.js';
2
+
3
+ async function test() {
4
+ const text = '[Block = attr: "val with space"]\n Content\n[end]\n';
5
+ const sm = new SomMark({
6
+ src: text,
7
+ format: 'html',
8
+ plugins: ['sommark-format']
9
+ });
10
+ await sm.parse();
11
+ const formatPlugin = sm.plugins.find(p => p.name === 'sommark-format');
12
+ const formatted = formatPlugin.formattedSource;
13
+ console.log("Original:\n", text);
14
+ console.log("Formatted:\n", formatted);
15
+
16
+ if (formatted.includes('"val with space"')) {
17
+ console.log("PASS: Quotes preserved for space-containing value.");
18
+ } else {
19
+ console.error("FAIL: Quotes LOST!");
20
+ process.exit(1);
21
+ }
22
+
23
+ const text2 = 'Text at top level\n(inline)->(bold)\n@_AtBlock_@;\n content\n@_end_@\n';
24
+ const sm2 = new SomMark({
25
+ src: text2,
26
+ format: 'html',
27
+ plugins: ['sommark-format']
28
+ });
29
+ await sm2.parse();
30
+ const formatted2 = sm2.plugins.find(p => p.name === 'sommark-format').formattedSource;
31
+ console.log("Top-level Original:\n", text2);
32
+ console.log("Top-level Formatted:\n", formatted2);
33
+
34
+ if (formatted2.includes('Text at top level') && formatted2.includes('(inline)->(bold)')) {
35
+ console.log("PASS: Top-level content preserved.");
36
+ } else {
37
+ console.error("FAIL: Top-level content LOST or corrupted!");
38
+ process.exit(1);
39
+ }
40
+ }
41
+
42
+ test();