Skip to content

Commit 7300b5d

Browse files
committed
Initial commit
1 parent f5109c4 commit 7300b5d

File tree

9 files changed

+239
-0
lines changed

9 files changed

+239
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Obsidian LogSeq plugin
2+
3+
A simple plugin to make Obsidian's preview of LogSeq markdown a bit more pleasant.

main.js

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
MarkdownPostProcessor,
3+
MarkdownPostProcessorContext,
4+
MarkdownPreviewRenderer,
5+
Plugin,
6+
} from "obsidian";
7+
8+
export default class LogSeqPlugin extends Plugin {
9+
static postprocessor: MarkdownPostProcessor = (
10+
el: HTMLElement,
11+
ctx: MarkdownPostProcessorContext
12+
) => {
13+
const entries = el.querySelectorAll("li[data-line]");
14+
15+
entries.forEach((entry) => {
16+
const contents = entry.textContent;
17+
if (contents.startsWith("DONE")) {
18+
const replacedHTML = entry.innerHTML
19+
.replace("DONE", "")
20+
.replace(/doing:: (?:\d{13})/, "")
21+
.replace(/done:: (?:\d{13})/, "")
22+
.replace(/todo:: (?:\d{13})/, "")
23+
.replace("<br>", "");
24+
entry.innerHTML = `<span class="logseq-done-task"><input type="checkbox" checked> ${replacedHTML}</span>`;
25+
} else if (contents.startsWith("TODO")) {
26+
const replacedHTML = entry.innerHTML
27+
.replace("TODO", "")
28+
.replace(/todo:: (?:\d{13})/, "");
29+
30+
entry.innerHTML = `<input type="checkbox"> <span class="logseq-status-task">TODO</span> ${replacedHTML}`;
31+
} else if (contents.startsWith("DOING")) {
32+
const replacedHTML = entry.innerHTML
33+
.replace("DOING", "")
34+
.replace(/doing:: (?:\d{13})/, "")
35+
.replace(/todo:: (?:\d{13})/, "");
36+
37+
entry.innerHTML = `<input type="checkbox"> <span class="logseq-status-task">DOING</span> ${replacedHTML}`;
38+
} else if (contents.startsWith("LATER")) {
39+
const replacedHTML = entry.innerHTML.replace("LATER", "");
40+
41+
entry.innerHTML = `<input type="checkbox"> <span class="logseq-status-task">LATER</span> ${replacedHTML}`;
42+
}
43+
});
44+
};
45+
46+
onload() {
47+
console.log("loading LogSeq plugin");
48+
MarkdownPreviewRenderer.registerPostProcessor(LogSeqPlugin.postprocessor);
49+
}
50+
51+
onunload() {
52+
console.log("unloading LogSeq plugin");
53+
MarkdownPreviewRenderer.unregisterPostProcessor(LogSeqPlugin.postprocessor);
54+
}
55+
}

manifest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "logseq-format",
3+
"name": "LogSeq markdown formatting",
4+
"version": "0.0.1",
5+
"minAppVersion": "0.9.15",
6+
"description": "Render LogSeq-specific markdown",
7+
"author": "Rui Vieira",
8+
"authorUrl": "https://github.com/ruivieira/obsidian-plugin-logseq",
9+
"isDesktopOnly": false,
10+
"css": "style.css"
11+
}

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "obsidian-plugin-logseq",
3+
"version": "0.0.1",
4+
"description": "Render LogSeq-specific markdown.",
5+
"main": "main.js",
6+
"scripts": {
7+
"dev": "rollup --config rollup.config.js -w",
8+
"build": "rollup --config rollup.config.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "MIT",
13+
"devDependencies": {
14+
"@rollup/plugin-commonjs": "^15.1.0",
15+
"@rollup/plugin-node-resolve": "^9.0.0",
16+
"@rollup/plugin-typescript": "^6.0.0",
17+
"@types/node": "^14.14.2",
18+
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
19+
"rollup": "^2.32.1",
20+
"tslib": "^2.0.3",
21+
"typescript": "^4.0.3"
22+
}
23+
}

rollup.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
import {nodeResolve} from '@rollup/plugin-node-resolve';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
5+
export default {
6+
input: 'main.ts',
7+
output: {
8+
dir: '.',
9+
sourcemap: 'inline',
10+
format: 'cjs',
11+
exports: 'default'
12+
},
13+
external: ['obsidian'],
14+
plugins: [
15+
typescript(),
16+
nodeResolve({browser: true}),
17+
commonjs(),
18+
]
19+
};

styles.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.logseq-done-task {
2+
text-decoration: line-through;
3+
opacity: 0.5;
4+
}
5+
6+
.logseq-status-task {
7+
font-weight: bold;
8+
font-size: 0.9rem;
9+
color: var(--text-a);
10+
}
11+
12+
a[href="#A"],a[href="#B"],a[href="#C"],a[href="#D"] {
13+
color: var(--faded-blue) !important;
14+
}

tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"inlineSourceMap": true,
5+
"inlineSources": true,
6+
"module": "ESNext",
7+
"target": "es5",
8+
"allowJs": true,
9+
"noImplicitAny": true,
10+
"moduleResolution": "node",
11+
"importHelpers": true,
12+
"lib": [
13+
"dom",
14+
"es5",
15+
"scripthost",
16+
"es2015"
17+
],
18+
"typeRoots": [
19+
"node_modules/@types"
20+
]
21+
},
22+
"include": [
23+
"**/*.ts"
24+
]
25+
}

versions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"1.0.0": "0.9.15",
3+
"1.0.1": "0.9.15",
4+
"1.0.2": "0.9.15",
5+
"1.0.3": "0.9.15"
6+
}

0 commit comments

Comments
 (0)