sommark 2.3.0 → 2.3.2
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/CHANGELOG.md +11 -0
- package/README.md +5 -5
- package/cli/commands/print.js +6 -1
- package/cli/constants.js +1 -1
- package/cli/helpers/transpile.js +3 -3
- package/core/parser.js +23 -18
- package/core/transpiler.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.3.2 (2026-03-07)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Fixed: [Cli] CLI Fails to Print JSON Output with --json Flag (Issue #8)
|
|
7
|
+
- Fixed: [Parser] Inline Value Tokenization Fails When Starting or Containing Escape Character (Issue #9)
|
|
8
|
+
|
|
9
|
+
## v2.3.1 (2026-03-02)
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
* Fixed MDX format issue
|
|
13
|
+
|
|
3
14
|
|
|
4
15
|
## v2.3.0 (2026-02-23)
|
|
5
16
|
|
package/README.md
CHANGED
|
@@ -98,9 +98,9 @@ console.log(await smark.transpile());
|
|
|
98
98
|
|
|
99
99
|
Detailed guides and API references are available in the `docs/` directory:
|
|
100
100
|
|
|
101
|
-
- **[Syntax Guide](docs/syntax.md)**: Master SomMark syntax (Blocks, Inline, At-Blocks).
|
|
102
|
-
- **[Core API](docs/core.md)**: Programmatic usage of the library (`transpile`, `lex`, `parse`).
|
|
103
|
-
- **[Mapper API](docs/mapper.md)**: Guide for creating custom mappers and rules.
|
|
104
|
-
- **[CLI Reference](docs/cli.md)**: Command line options and configurations.
|
|
101
|
+
- **[Syntax Guide](docs/03.syntax.md)**: Master SomMark syntax (Blocks, Inline, At-Blocks).
|
|
102
|
+
- **[Core API](docs/09.core.md)**: Programmatic usage of the library (`transpile`, `lex`, `parse`).
|
|
103
|
+
- **[Mapper API](docs/13.mapper.md)**: Guide for creating custom mappers and rules.
|
|
104
|
+
- **[CLI Reference](docs/11.cli.md)**: Command line options and configurations.
|
|
105
105
|
- **[API Quick Reference](docs/api)**: Fast lookup for all classes and functions.
|
|
106
|
-
- **[Configuration Reference](docs/config.md)**: Guide for creating custom configurations.
|
|
106
|
+
- **[Configuration Reference](docs/12.config.md)**: Guide for creating custom configurations.
|
package/cli/commands/print.js
CHANGED
|
@@ -9,9 +9,14 @@ import path from "node:path";
|
|
|
9
9
|
export async function printOutput(format, filePath) {
|
|
10
10
|
if (await isExist(filePath)) {
|
|
11
11
|
const fileName = path.basename(filePath);
|
|
12
|
-
console.log(formatMessage(`{line}
|
|
12
|
+
console.log(formatMessage(`{line}<$blue: Printing output for$> <$yellow:'${fileName}'$>{line}`));
|
|
13
13
|
let source_code = await readContent(filePath);
|
|
14
|
+
if (format ==="json") {
|
|
15
|
+
const output = await transpile({ src: source_code.toString(), format });
|
|
16
|
+
console.log(JSON.stringify(JSON.parse(output, null, 2), null, 2));
|
|
17
|
+
} else {
|
|
14
18
|
console.log(await transpile({ src: source_code.toString(), format }));
|
|
19
|
+
}
|
|
15
20
|
} else {
|
|
16
21
|
cliError([`{line}<$red:File$> <$blue:'${filePath}'$> <$red: is not found$>{line}`]);
|
|
17
22
|
}
|
package/cli/constants.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// CLI Constants //
|
|
3
3
|
// ========================================================================== //
|
|
4
4
|
|
|
5
|
-
export const options = ["-v", "--version", "-h", "--help", "--html", "--markdown", "--mdx", "json", "--text", "--print", "-p"];
|
|
5
|
+
export const options = ["-v", "--version", "-h", "--help", "--html", "--markdown", "--mdx", "--json", "--text", "--print", "-p"];
|
|
6
6
|
|
|
7
7
|
export const extensions = {
|
|
8
8
|
text: "txt",
|
package/cli/helpers/transpile.js
CHANGED
|
@@ -7,11 +7,12 @@ import transpiler from "../../core/transpiler.js";
|
|
|
7
7
|
import HTML from "../../mappers/languages/html.js";
|
|
8
8
|
import MARKDOWN from "../../mappers/languages/markdown.js";
|
|
9
9
|
import MDX from "../../mappers/languages/mdx.js";
|
|
10
|
+
import Json from "../../mappers/languages/json.js";
|
|
10
11
|
import { isExist } from "./file.js";
|
|
11
12
|
import { loadConfig } from "./config.js";
|
|
12
|
-
import { htmlFormat, markdownFormat, mdxFormat } from "../../core/formats.js";
|
|
13
|
+
import { htmlFormat, markdownFormat, mdxFormat, jsonFormat } from "../../core/formats.js";
|
|
13
14
|
|
|
14
|
-
const default_mapperFiles = { [htmlFormat]: HTML, [markdownFormat]: MARKDOWN, [mdxFormat]: MDX };
|
|
15
|
+
const default_mapperFiles = { [htmlFormat]: HTML, [markdownFormat]: MARKDOWN, [mdxFormat]: MDX, [jsonFormat]: Json};
|
|
15
16
|
|
|
16
17
|
// ========================================================================== //
|
|
17
18
|
// Transpile Function //
|
|
@@ -47,7 +48,6 @@ export async function transpile({ src, format, mappingFile = "" }) {
|
|
|
47
48
|
// Error: Mapper not found //
|
|
48
49
|
// ========================================================================== //
|
|
49
50
|
else {
|
|
50
|
-
console.log("here", JSON.stringify(mappingFile), format)
|
|
51
51
|
cliError([`{line}<$red:File$> <$blue:'${mappingFile}'$> <$red: is not found$>{line}`]);
|
|
52
52
|
}
|
|
53
53
|
}
|
package/core/parser.js
CHANGED
|
@@ -402,28 +402,33 @@ function parseInline(tokens, i) {
|
|
|
402
402
|
// ========================================================================== //
|
|
403
403
|
i++;
|
|
404
404
|
updateData(tokens, i);
|
|
405
|
-
if (
|
|
405
|
+
if (
|
|
406
|
+
!current_token(tokens, i) ||
|
|
407
|
+
(current_token(tokens, i) &&
|
|
408
|
+
current_token(tokens, i).type !== TOKEN_TYPES.VALUE &&
|
|
409
|
+
current_token(tokens, i).type !== TOKEN_TYPES.ESCAPE)
|
|
410
|
+
) {
|
|
406
411
|
parserError(errorMessage(tokens, i, inline_value, "("));
|
|
407
412
|
}
|
|
408
|
-
inlineNode.value = current_token(tokens, i).value;
|
|
409
413
|
inlineNode.depth = current_token(tokens, i).depth;
|
|
410
|
-
// ========================================================================== //
|
|
411
|
-
// consume Inline Value //
|
|
412
|
-
// ========================================================================== //
|
|
413
|
-
i++;
|
|
414
414
|
updateData(tokens, i);
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
415
|
+
while (i < tokens.length) {
|
|
416
|
+
if (current_token(tokens, i) && current_token(tokens, i).type === TOKEN_TYPES.VALUE) {
|
|
417
|
+
inlineNode.value += current_token(tokens, i).value;
|
|
418
|
+
// ========================================================================== //
|
|
419
|
+
// consume Inline Value //
|
|
420
|
+
// ========================================================================== //
|
|
421
|
+
i++;
|
|
422
|
+
continue;
|
|
423
|
+
} else if (current_token(tokens, i) && current_token(tokens, i).type === TOKEN_TYPES.ESCAPE) {
|
|
424
|
+
inlineNode.value += current_token(tokens, i).value.slice(1);
|
|
425
|
+
// ========================================================================== //
|
|
426
|
+
// consume Escape Character '\' //
|
|
427
|
+
// ========================================================================== //
|
|
428
|
+
i++;
|
|
429
|
+
continue;
|
|
430
|
+
} else {
|
|
431
|
+
break;
|
|
427
432
|
}
|
|
428
433
|
}
|
|
429
434
|
if (!current_token(tokens, i) || (current_token(tokens, i) && current_token(tokens, i).type !== TOKEN_TYPES.CLOSE_PAREN)) {
|
package/core/transpiler.js
CHANGED
|
@@ -119,7 +119,7 @@ async function generateOutput(ast, i, format, mapper_file) {
|
|
|
119
119
|
const block_formats = [htmlFormat, mdxFormat, jsonFormat];
|
|
120
120
|
if (target) {
|
|
121
121
|
validateRules(target, node.args, "", node.type);
|
|
122
|
-
const placeholder = format === mdxFormat && node.body.length >
|
|
122
|
+
const placeholder = format === mdxFormat && node.body.length > 0 ? "\n<%smark>\n" : "<%smark>";
|
|
123
123
|
result += block_formats.includes(format)
|
|
124
124
|
? `${format === mdxFormat ? "\n" : ""}${target.render({ args: node.args, content: placeholder, ast: expose_for_fmts.includes(format) ? ast[i] : null }) + (format === mdxFormat ? "\n" : "")}`
|
|
125
125
|
: target.render({ args: node.args, content: "" }) + (format === mdxFormat ? "\n" : "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sommark",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "SomMark is a structural markup language for writing structured documents and converting them into HTML or Markdown or MDX(only ready components).",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|