@remigius42/morg 0.5.0 → 0.6.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/dist/core/bracedScripts.d.ts +12 -0
- package/dist/core/bracedScripts.js +159 -0
- package/dist/core/footnoteReferences.d.ts +10 -0
- package/dist/core/footnoteReferences.js +24 -0
- package/dist/core/lineSyntax.d.ts +12 -0
- package/dist/core/lineSyntax.js +206 -0
- package/dist/core/markupBoundary.d.ts +12 -0
- package/dist/core/markupBoundary.js +195 -0
- package/dist/core/mdastToUniorg/index.js +9 -1
- package/dist/core/mdastToUniorg/lists.d.ts +1 -1
- package/dist/core/mdastToUniorg/lists.js +21 -2
- package/dist/core/mdastToUniorg/phrasing.js +145 -12
- package/dist/core/orgPath.d.ts +9 -0
- package/dist/core/orgPath.js +24 -0
- package/dist/core/render.d.ts +33 -0
- package/dist/core/render.js +101 -0
- package/dist/core/tablePipes.d.ts +8 -0
- package/dist/core/tablePipes.js +14 -0
- package/dist/core/underscoreBullets.d.ts +10 -0
- package/dist/core/underscoreBullets.js +32 -0
- package/dist/core/uniorgToMdast/lists.js +11 -0
- package/dist/core/uniorgToMdast/objects.js +38 -6
- package/dist/core/uniorgToMdast/tables.js +12 -6
- package/dist/markdownToOrg.js +18 -0
- package/dist/orgToMarkdown.js +28 -4
- package/package.json +4 -1
package/dist/orgToMarkdown.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { unified } from "unified";
|
|
2
|
-
import uniorgParse from "uniorg-parse";
|
|
3
2
|
import remarkStringify from "remark-stringify";
|
|
4
3
|
import remarkGfm from "remark-gfm";
|
|
5
4
|
import remarkFrontmatter from "remark-frontmatter";
|
|
6
5
|
import remarkMath from "remark-math";
|
|
7
6
|
import { transformUniorgAstToMdast } from "./core/uniorgToMdast/index.js";
|
|
8
7
|
import { takeRecordedStyle } from "./core/markdownStyle.js";
|
|
8
|
+
import { unescapeOrgMarkup } from "./core/markupBoundary.js";
|
|
9
|
+
import { unescapeLineSyntax } from "./core/lineSyntax.js";
|
|
10
|
+
import { unescapeFootnoteReferences } from "./core/footnoteReferences.js";
|
|
11
|
+
import { parseOrg } from "./core/bracedScripts.js";
|
|
12
|
+
import { dropUnderscoreBulletGuards, guardUnderscoreBullets } from "./core/underscoreBullets.js";
|
|
13
|
+
// a list item's paragraph after its nested list needs a blank line, or
|
|
14
|
+
// md reads it as a lazy continuation of the nested list's last item
|
|
15
|
+
function separateTextAfterNestedList(left, right, parent) {
|
|
16
|
+
return parent.type === "listItem" &&
|
|
17
|
+
left.type === "list" &&
|
|
18
|
+
right.type === "paragraph"
|
|
19
|
+
? 1
|
|
20
|
+
: undefined;
|
|
21
|
+
}
|
|
9
22
|
/**
|
|
10
23
|
* Converts an Org-mode string to a Markdown string.
|
|
11
24
|
* @param org The Org-mode string to convert.
|
|
@@ -14,10 +27,17 @@ import { takeRecordedStyle } from "./core/markdownStyle.js";
|
|
|
14
27
|
*/
|
|
15
28
|
export function convertOrgToMarkdown(org, options = {}) {
|
|
16
29
|
// Phase 1: Parse Org-mode to uniorg-ast
|
|
17
|
-
|
|
30
|
+
// md text has no scripts, so ^:{} is implied there and consumed here
|
|
31
|
+
// (see markdownToOrg); uniorg misreads `_.` lines (see underscoreBullets)
|
|
32
|
+
let uniorgAst = parseOrg(guardUnderscoreBullets(org));
|
|
33
|
+
dropUnderscoreBulletGuards(uniorgAst);
|
|
18
34
|
// Phase 1b: a recorded style is morg's own (ADR 0004), so consume it so
|
|
19
35
|
// it does not travel on as frontmatter; explicit options still win
|
|
20
36
|
const recordedStyle = takeRecordedStyle(uniorgAst);
|
|
37
|
+
// Phase 1c: markdown needs no zero-width space escapes (inverse of md→org)
|
|
38
|
+
unescapeOrgMarkup(uniorgAst);
|
|
39
|
+
unescapeLineSyntax(uniorgAst);
|
|
40
|
+
unescapeFootnoteReferences(uniorgAst);
|
|
21
41
|
// Phase 2: Extract dialect preset conventions, if any
|
|
22
42
|
if (options.preset?.extractFromUniorg) {
|
|
23
43
|
uniorgAst = options.preset.extractFromUniorg(uniorgAst);
|
|
@@ -46,11 +66,15 @@ export function convertOrgToMarkdown(org, options = {}) {
|
|
|
46
66
|
rule: "-",
|
|
47
67
|
...recordedStyle,
|
|
48
68
|
...options.markdownStyle,
|
|
69
|
+
join: [separateTextAfterNestedList],
|
|
49
70
|
handlers: {
|
|
50
71
|
// key:: value blocks and preset inline passthroughs (e.g.
|
|
51
|
-
// wikilinks) are emitted verbatim, unescaped
|
|
72
|
+
// wikilinks) are emitted verbatim, unescaped; only a pipe inside
|
|
73
|
+
// a table cell is escaped, or it would split the cell
|
|
52
74
|
keyValue: (node) => node.value,
|
|
53
|
-
verbatimInline: (node) =>
|
|
75
|
+
verbatimInline: (node, _parent, state) => state.stack.includes("tableCell")
|
|
76
|
+
? node.value.replaceAll("|", "\\|")
|
|
77
|
+
: node.value
|
|
54
78
|
}
|
|
55
79
|
})
|
|
56
80
|
.use(remarkGfm)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remigius42/morg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Bidirectional Markdown ↔ Org-mode converter with round-trip convergence",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"org-mode",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"prepare": "husky",
|
|
47
47
|
"prepack": "npm run build",
|
|
48
48
|
"version": "node scripts/release-changelog.mjs && git add CHANGELOG.md",
|
|
49
|
+
"postversion": "printf '\\nNext:\\n git push origin v%s\\n wait for the Release run to pass\\n git push\\n' \"$npm_package_version\"",
|
|
49
50
|
"build": "tsc -p tsconfig.build.json",
|
|
50
51
|
"build:web": "vite build web",
|
|
51
52
|
"dev:web": "vite web",
|
|
@@ -61,6 +62,8 @@
|
|
|
61
62
|
"lint:fix": "npm run lint:fix:prettier && npm run lint:fix:eslint",
|
|
62
63
|
"lint:fix:prettier": "prettier --write '**/*'",
|
|
63
64
|
"lint:fix:eslint": "eslint --fix '**/*.{ts,mts,js}'",
|
|
65
|
+
"perf": "npm run build && node scripts/perf/perf.mjs",
|
|
66
|
+
"perf:record": "node scripts/perf/perf.mjs --record",
|
|
64
67
|
"test:unit": "vitest",
|
|
65
68
|
"test:unit:ci": "vitest run --reporter default --coverage",
|
|
66
69
|
"test:coverage": "vitest run --coverage",
|