Skip to content

Commit 0c21b89

Browse files
authored
upgrade remark and parse wiki links (#265)
* add tests for reference links - in preparation for parsing (but not resolving) wikilinks, add test cases for link references. * update remark and co; clean-up tests; add ofm fork * pass basic slate tests; unwrapImages; re-name legacy functions - update the markdown functions to use the new routines; re-name all the old ones *Legacy - make basic Slate tests pass, requires re-writing unwrapImages (trivial - this was a package before?) - update consuming code to use new interfaces; it does not quite work yet * more tests, configuration, clean-up - add full markdown test; use it to slowly isolate edge cases - clean-up and organize tests (continued) - discover mdast-util-to-string configuration options, use them, update tests - figure out some markdown escape rules, document and accept the behavior * remove several remark packages, refactor types - kick out all the legacy remark packages - refactor types: drop ts-mdast, prefer types from mdast, refactor base Slate node import to customized Slate node * fix image / paragraph wrapping + test * slate-transformer cleanup * strip wikilinks and fix a few tests - add wikilink handling at the mdast->slate level, converting them to plain text. This results in them being ignored in slate and escaped when serialized back to markdown - fix a few tests and remove some redundant (wikilink related) ones Plan here is to support wikilinks on initial parsing so importer pathway can convert to markdown links / image embeddings, but then to ignore them thereafter. Future work can consider supporting them directly * remove rehype * also remove remark
1 parent 149b64c commit 0c21b89

File tree

30 files changed

+2048
-1793
lines changed

30 files changed

+2048
-1793
lines changed

.prettierignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
build
33
dist
44
node_modules
5-
packaged
5+
packaged
6+
7+
# Some of the changes prettier makes to md files differs from what
8+
# mdast-util-to-string does, making it unusable as a snapshot.
9+
src/markdown/test-docs/*

package.json

+5-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"postinstall": "yarn run electron-rebuild",
1212
"prestart": "tailwindcss -i ./src/index.css -o ./src/index-compiled.css",
1313
"prebuild": "yarn run lint && tailwindcss -i ./src/index.css -o ./src/index-compiled.css",
14-
"start": "node ./scripts/dev.js",
14+
"start": "node ./scripts/dev.mjs",
1515
"pretest": "node ./scripts/test.mjs",
1616
"test": "mocha 'src/**/*.test.bundle.js'"
1717
},
@@ -47,7 +47,6 @@
4747
"@types/mocha": "^7.0.2",
4848
"@types/react": "^18.2.48",
4949
"@types/react-dom": "^18.2.18",
50-
"@types/rehype-react": "^4.0.0",
5150
"@udecode/cn": "^29.0.1",
5251
"@udecode/plate": "^34.1.0",
5352
"chai": "^5.0.3",
@@ -61,6 +60,10 @@
6160
"lodash": "^4.17.21",
6261
"lucide-react": "^0.314.0",
6362
"luxon": "^2.4.0",
63+
"mdast-util-from-markdown": "^2.0.2",
64+
"mdast-util-gfm": "^3.0.0",
65+
"mdast-util-to-markdown": "^2.1.2",
66+
"micromark-extension-gfm": "^3.0.0",
6467
"mobx": "^5.15.4",
6568
"mobx-react-lite": "^2.0.7",
6669
"mocha": "^10.2.0",
@@ -71,13 +74,6 @@
7174
"react-day-picker": "^8.10.0",
7275
"react-dom": "^18.2.0",
7376
"react-router-dom": "^6.3.0",
74-
"rehype-react": "^7.0.3",
75-
"remark": "^14.0.1",
76-
"remark-gfm": "^4.0.0",
77-
"remark-parse": "^8.0.3",
78-
"remark-rehype": "^10.0.0",
79-
"remark-stringify": "^8.1.1",
80-
"remark-unwrap-images": "^3.0.0",
8177
"slate": "^0.101.5",
8278
"slate-history": "^0.100.0",
8379
"slate-hyperscript": "^0.100.0",
@@ -86,9 +82,7 @@
8682
"tailwind-merge": "^2.2.1",
8783
"tailwindcss": "^3.4.1",
8884
"tailwindcss-animate": "^1.0.7",
89-
"ts-mdast": "^1.0.0",
9085
"typescript": "^5.3.3",
91-
"unified": "^10.1.0",
9286
"yaml": "^2.5.1"
9387
}
9488
}

scripts/dev.js scripts/dev.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const esbuild = require("esbuild");
2-
const cp = require("child_process");
3-
const electron = require("electron");
4-
const lodash = require("lodash");
1+
import cp from "child_process";
2+
import electron from "electron";
3+
import esbuild from "esbuild";
4+
import lodash from "lodash";
55

66
// Builds and watches the application for development
77
// Bundles the renderer, preload, and main processes, and

src/markdown/remark-slate-transformer/README.md src/markdown/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# remark-slate-transformer
2+
13
This is a partial fork of https://github.com/inokawa/remark-slate-transformer
24

35
I did this to quickly modify some of the output node types when converting mdast to slate.
@@ -7,3 +9,7 @@ If it works, consider formally forking, or opening a PR to the original repo and
79
https://github.com/inokawa/remark-slate-transformer/issues/37
810
https://github.com/inokawa/remark-slate-transformer/issues/31
911
https://github.com/inokawa/remark-slate-transformer/issues/67
12+
13+
# mdast-util-ofm
14+
15+
Partial fork of https://github.com/MoritzRS/obsidian-ext initially because of ESM import issues. I need no immediate modifications of this project and if / once this project completes esm updates may be preferable to move this back to a dependency.

0 commit comments

Comments
 (0)