Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade markmap to 0.14.x #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ Note: On some machines the `.obsidian` folder may be hidden. On MacOS you should
## For developers
Pull requests are both welcome and appreciated. 😀

- Use the version of node that matches what is in `.github/workflows/release.yml`. (If using nvm: `nvm install lts/fermium`, `nvm use lts/fermium`).
- Get set up with `npm install --verbose`, and then `npm run dev`.
- Use a test vault with either the `test-vault/` in this repo, or manually install this to another test vault. (You may do so by symlinking, e.g. `ln -s <path to obsidian-mind-map/ <your vault>/.obsidian/plugins/.`, and then symlinking the built artifact to the root git dir `ln -s dist/main.js .`)
- Since Obsidian desktop is an Electron app, you can use the Chromium developer tools to view an in-app console. `Cmd + Opt + I` on macOS or `Ctrl + Shift + I` on Windows/Linux.

If you would like to contribute to the development of this plugin, please follow the guidelines provided in [CONTRIBUTING.md](CONTRIBUTING.md).

## Donating
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "obsidian-mind-map",
"name": "Mind Map",
"version": "1.1.0",
"version": "1.1.1",
"description": "A plugin to preview notes as Markmap mind maps",
"isDesktopOnly": false,
"js": "main.js"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"typescript": "^4.1.2"
},
"dependencies": {
"markmap-lib": "^0.10.2",
"markmap-view": "^0.1.2"
"markmap-lib": "^0.14.3",
"markmap-view": "^0.14.3",
"markmap-common": "^0.14.2"
}
}
28 changes: 14 additions & 14 deletions src/mindmap-view.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { EventRef, ItemView, Menu, Vault, Workspace, WorkspaceLeaf } from 'obsidian';
import { transform } from 'markmap-lib';
import { Transformer } from 'markmap-lib';
import { Markmap } from 'markmap-view';
import { INode } from 'markmap-common';
import { FRONT_MATTER_REGEX, MD_VIEW_TYPE, MM_VIEW_TYPE } from './constants';
import ObsidianMarkmap from './obsidian-markmap-plugin';
import { createSVG, getComputedCss, removeExistingSVG } from './markmap-svg';
import { createSVG, removeExistingSVG } from './markmap-svg';
import { copyImageToClipboard } from './copy-image';
import { MindMapSettings } from './settings';
import { IMarkmapOptions } from 'markmap-view/types/types';

export default class MindmapView extends ItemView {
filePath: string;
Expand Down Expand Up @@ -67,8 +66,8 @@ export default class MindmapView extends ItemView {
async onOpen() {
this.obsMarkmap = new ObsidianMarkmap(this.vault);
this.registerActiveLeafUpdate();
this.workspace.onLayoutReady(() => this.update()),
this.listeners = [
this.workspace.on('layout-ready', () => this.update()),
this.workspace.on('resize', () => this.update()),
this.workspace.on('css-change', () => this.update()),
this.leaf.on('group-change', (group) => this.updateLinkedLeaf(group, this))
Expand Down Expand Up @@ -169,21 +168,22 @@ export default class MindmapView extends ItemView {
}

async transformMarkdown() {
const { root, features } = transform(this.currentMd);
const { root, features } = new Transformer().transform(this.currentMd);
this.obsMarkmap.updateInternalLinks(root);
return { root, features };
}

async renderMarkmap(root: INode, svg: SVGElement) {
const { font } = getComputedCss(this.containerEl);
const options: IMarkmapOptions = {
autoFit: false,
duration: 10,
nodeFont: font,
nodeMinHeight: this.settings.nodeMinHeight ?? 16,
spacingVertical: this.settings.spacingVertical ?? 5,
spacingHorizontal: this.settings.spacingHorizontal ?? 80,
paddingX: this.settings.paddingX ?? 8
const options = {
...Markmap.defaultOptions,
...{
autoFit: false,
duration: 10,
nodeMinHeight: this.settings.nodeMinHeight ?? 16,
spacingVertical: this.settings.spacingVertical ?? 5,
spacingHorizontal: this.settings.spacingHorizontal ?? 80,
paddingX: this.settings.paddingX ?? 8
}
};
try {
const markmapSVG = Markmap.create(svg, options, root);
Expand Down
8 changes: 4 additions & 4 deletions src/obsidian-markmap-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export default class ObsidianMarkmap {

updateInternalLinks(node: INode) {
this.replaceInternalLinks(node);
if(node.c){
node.c.forEach(n => this.updateInternalLinks(n));
if(node.children){
node.children.forEach(n => this.updateInternalLinks(n));
}
}

private replaceInternalLinks(node: INode){
const matches = this.parseValue(node.v);
const matches = this.parseValue(node.content);
for (let i = 0; i < matches.length; i++) {
const match = matches[i];
const isWikiLink = match.groups['wikitext'];
Expand All @@ -28,7 +28,7 @@ export default class ObsidianMarkmap {
}
const url = `obsidian://open?vault=${this.vaultName}&file=${isWikiLink ? encodeURI(getLinkpath(linkPath)) : linkPath}`;
const link = `<a href=\"${url}\">${linkText}</a>`;
node.v = node.v.replace(match[0], link);
node.content = node.content.replace(match[0], link);
}
}

Expand Down