sommark 3.3.2 → 3.3.3

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.
@@ -56,11 +56,12 @@ async function generateOutput(ast, i, format, mapper_file) {
56
56
  // ========================================================================== //
57
57
  // Always use placeholders for blocks to support wrapping //
58
58
  // ========================================================================== //
59
- const placeholder = format === mdxFormat && node.body.length > 0 ? `\n${BODY_PLACEHOLDER}\n` : BODY_PLACEHOLDER;
59
+ const isParentBlock = format === mdxFormat && node.body.length > 1;
60
+ const placeholder = isParentBlock ? `\n${BODY_PLACEHOLDER}\n` : BODY_PLACEHOLDER;
60
61
  const textContent = getNodeText(node);
61
62
 
62
63
  result += target.render.call(mapper_file, { args: node.args, content: placeholder, textContent, ast: node });
63
- if (format === mdxFormat) result = "\n" + result + "\n";
64
+ if (isParentBlock) result = "\n" + result + "\n";
64
65
 
65
66
  // ========================================================================== //
66
67
  // Process body nodes recursively //
@@ -112,7 +113,12 @@ async function generateOutput(ast, i, format, mapper_file) {
112
113
 
113
114
  case BLOCK:
114
115
  const blockOutput = await generateOutput(body_node, i, format, mapper_file);
115
- context = context.trim() ? context.trimEnd() + "\n" + blockOutput : context + blockOutput;
116
+ const blockIsParent = format === mdxFormat && body_node.body.length > 1;
117
+ if (format === mdxFormat && !blockIsParent) {
118
+ context += blockOutput;
119
+ } else {
120
+ context = context.trim() ? context.trimEnd() + "\n" + blockOutput : context + blockOutput;
121
+ }
116
122
  break;
117
123
  }
118
124
  }
@@ -138,7 +144,8 @@ async function generateOutput(ast, i, format, mapper_file) {
138
144
  `<$yellow:Identifier$> <$blue:'${node.id}'$> <$yellow: is not found in mapping outputs$>{line}`
139
145
  ]);
140
146
  }
141
- return result.trimEnd() + "\n";
147
+ const newline = (format === mdxFormat && node.body.length <= 1) ? "" : "\n";
148
+ return result.trimEnd() + newline;
142
149
  }
143
150
 
144
151
  // ========================================================================== //
@@ -147,7 +147,7 @@ HTML.register(
147
147
 
148
148
  return this.tag("pre").body(code_element.body(code));
149
149
  },
150
- { escape: false, type: "AtBlock" }
150
+ { escape: false, type: ["AtBlock", "Block"] }
151
151
  );
152
152
  // List
153
153
  HTML.register(
@@ -74,7 +74,7 @@ MARKDOWN.register(
74
74
  },
75
75
  {
76
76
  escape: false,
77
- type: "AtBlock"
77
+ type: ["AtBlock", "Block"]
78
78
  }
79
79
  );
80
80
  // Link
@@ -90,7 +90,7 @@ const { tag } = MDX;
90
90
  MDX.inherit(MARKDOWN);
91
91
 
92
92
  // Block for raw MDX content (ESM, etc.)
93
- MDX.register("mdx", ({ content }) => content, { escape: false, type: "Block" });
93
+ MDX.register("mdx", ({ content }) => content, { escape: false, type: ["AtBlock", "Block"] });
94
94
 
95
95
  // Re-register HTML tags to use jsxProps
96
96
  HTML_TAGS.forEach(tagName => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sommark",
3
- "version": "3.3.2",
3
+ "version": "3.3.3",
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": {