@galacticquasar/mdview 0.1.0 → 0.1.1
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/README.md +2 -0
- package/package.json +1 -1
- package/render.mjs +24 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# mdview
|
|
2
2
|
|
|
3
|
+
[](https://github.com/GalacticQuasar/mdview/actions/workflows/ci.yml)
|
|
4
|
+
|
|
3
5
|
**A Markdown viewer you launch from the terminal.** `mdview README.md` opens the file, rendered the
|
|
4
6
|
way GitHub renders it, in its own minimal window. You navigate with vim keys, and the window reloads
|
|
5
7
|
whenever you save. It uses the Chrome or Edge you already have, so there's no Electron and nothing
|
package/package.json
CHANGED
package/render.mjs
CHANGED
|
@@ -36,6 +36,30 @@ md.core.ruler.push('heading_ids', (state) => {
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
// GitHub-style task lists: a list item starting with "[ ] " or "[x] " gets a disabled
|
|
40
|
+
// checkbox, with GitHub's classes, which github-markdown-css already styles.
|
|
41
|
+
md.core.ruler.push('task_lists', (state) => {
|
|
42
|
+
const tokens = state.tokens;
|
|
43
|
+
tokens.forEach((tok, i) => {
|
|
44
|
+
if (tok.type !== 'list_item_open' || tokens[i + 2]?.type !== 'inline') return;
|
|
45
|
+
const first = tokens[i + 2].children[0];
|
|
46
|
+
const m = first?.type === 'text' && /^\[([ xX])\][ \t]+/.exec(first.content);
|
|
47
|
+
if (!m) return;
|
|
48
|
+
first.content = first.content.slice(m[0].length);
|
|
49
|
+
const box = new state.Token('html_inline', '', 0);
|
|
50
|
+
box.content = `<input type="checkbox" class="task-list-item-checkbox" disabled${m[1] === ' ' ? '' : ' checked'}> `;
|
|
51
|
+
tokens[i + 2].children.unshift(box);
|
|
52
|
+
tok.attrJoin('class', 'task-list-item');
|
|
53
|
+
// The list this item belongs to is the nearest earlier list opening one level up.
|
|
54
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
55
|
+
if (tokens[j].level === tok.level - 1 && /^(bullet|ordered)_list_open$/.test(tokens[j].type)) {
|
|
56
|
+
if (!tokens[j].attrGet('class')?.includes('contains-task-list')) tokens[j].attrJoin('class', 'contains-task-list');
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
39
63
|
// GitHub-style math, rendered with KaTeX: $inline$, $`inline`$, $$display$$ and ```math blocks.
|
|
40
64
|
const tex = (src, displayMode) => katex.renderToString(src, { displayMode, throwOnError: false });
|
|
41
65
|
|