hypermd-uplift 0.4.0 → 0.4.2
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/features/fold.d.ts +2 -1
- package/dist/features/styling.d.ts +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +121 -66
- package/dist/index.umd.cjs +1 -1
- package/package.json +5 -5
package/dist/features/fold.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
|
|
2
2
|
import { Extension } from '@codemirror/state';
|
|
3
|
+
import { SyntaxNodeRef } from '@lezer/common';
|
|
3
4
|
|
|
4
5
|
export type NodeDecorator = (node: {
|
|
5
6
|
name: string;
|
|
6
7
|
from: number;
|
|
7
8
|
to: number;
|
|
8
|
-
node:
|
|
9
|
+
node: SyntaxNodeRef;
|
|
9
10
|
}, view: EditorView) => Decoration | null;
|
|
10
11
|
export declare function createDecorationPlugin(decorators: NodeDecorator[]): ViewPlugin<{
|
|
11
12
|
decorations: DecorationSet;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { hypermdStyling } from './features/styling';
|
|
2
3
|
import { hypermdFold } from './features/fold';
|
|
3
4
|
import { hypermdMath } from './features/math';
|
|
4
5
|
import { hypermdMedia } from './features/media';
|
|
@@ -8,4 +9,4 @@ import { hypermdTable } from './features/table';
|
|
|
8
9
|
export interface HyperMDConfig {
|
|
9
10
|
}
|
|
10
11
|
export declare function hypermd(_config?: HyperMDConfig): Extension;
|
|
11
|
-
export { hypermdFold, hypermdMath, hypermdMedia, hypermdInteraction, hypermdTable };
|
|
12
|
+
export { hypermdStyling, hypermdFold, hypermdMath, hypermdMedia, hypermdInteraction, hypermdTable };
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,96 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var x = (e, t, r) => t in e ? b(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var c = (e, t, r) => (x(e, typeof t != "symbol" ? t + "" : t, r), r);
|
|
4
4
|
import { markdown as w } from "@codemirror/lang-markdown";
|
|
5
|
-
import { EditorView as
|
|
6
|
-
import { syntaxTree as
|
|
7
|
-
import
|
|
8
|
-
const
|
|
9
|
-
"
|
|
5
|
+
import { EditorView as d, ViewPlugin as l, Decoration as s, WidgetType as m, MatchDecorator as D } from "@codemirror/view";
|
|
6
|
+
import { syntaxTree as h } from "@codemirror/language";
|
|
7
|
+
import C from "katex";
|
|
8
|
+
const M = d.theme({
|
|
9
|
+
".cm-content": {
|
|
10
10
|
fontFamily: "var(--hypermd-font-family, system-ui, sans-serif)",
|
|
11
11
|
lineHeight: "1.6"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
// Headings
|
|
14
|
+
".cm-line .cm-header-1": { fontSize: "2em", fontWeight: "bold" },
|
|
15
|
+
".cm-line .cm-header-2": { fontSize: "1.5em", fontWeight: "bold" },
|
|
16
|
+
".cm-line .cm-header-3": { fontSize: "1.25em", fontWeight: "bold" },
|
|
17
|
+
".cm-line .cm-header-4": { fontSize: "1.1em", fontWeight: "bold" },
|
|
18
|
+
// Lists (We will hide the marker and replace with a widget, but basic styling here)
|
|
19
|
+
".cm-line .cm-list": { paddingLeft: "5px" },
|
|
20
|
+
".cm-line .cm-quote": { borderLeft: "4px solid #ccc", paddingLeft: "10px", color: "#666" }
|
|
13
21
|
});
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
class W extends m {
|
|
23
|
+
toDOM() {
|
|
24
|
+
const t = document.createElement("span");
|
|
25
|
+
return t.textContent = "•", t.style.fontWeight = "bold", t.style.marginRight = "5px", t;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class v extends m {
|
|
29
|
+
toDOM() {
|
|
30
|
+
return document.createElement("span");
|
|
31
|
+
}
|
|
32
|
+
// Empty span
|
|
33
|
+
}
|
|
34
|
+
function u(e) {
|
|
35
|
+
const t = [];
|
|
36
|
+
for (const { from: r, to: n } of e.visibleRanges)
|
|
37
|
+
h(e.state).iterate({
|
|
38
|
+
from: r,
|
|
39
|
+
to: n,
|
|
40
|
+
enter: (o) => {
|
|
41
|
+
const a = o.name;
|
|
42
|
+
if (a.startsWith("HeaderMark") && t.push(s.replace({
|
|
43
|
+
widget: new v()
|
|
44
|
+
}).range(o.from, o.to)), a === "ListMark") {
|
|
45
|
+
const i = e.state.sliceDoc(o.from, o.to);
|
|
46
|
+
["-", "*", "+"].includes(i.trim()) && t.push(s.replace({
|
|
47
|
+
widget: new W()
|
|
48
|
+
}).range(o.from, o.to));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return s.set(t);
|
|
53
|
+
}
|
|
54
|
+
function E() {
|
|
55
|
+
return [
|
|
56
|
+
M,
|
|
57
|
+
l.fromClass(class {
|
|
58
|
+
constructor(e) {
|
|
59
|
+
c(this, "decorations");
|
|
60
|
+
this.decorations = u(e);
|
|
61
|
+
}
|
|
62
|
+
update(e) {
|
|
63
|
+
(e.docChanged || e.viewportChanged) && (this.decorations = u(e.view));
|
|
64
|
+
}
|
|
65
|
+
}, { decorations: (e) => e.decorations })
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
function p(e) {
|
|
69
|
+
return l.fromClass(
|
|
16
70
|
class {
|
|
17
71
|
constructor(t) {
|
|
18
|
-
|
|
72
|
+
c(this, "decorations");
|
|
19
73
|
this.decorations = this.buildDecorations(t);
|
|
20
74
|
}
|
|
21
75
|
update(t) {
|
|
22
76
|
(t.docChanged || t.viewportChanged || t.selectionSet) && (this.decorations = this.buildDecorations(t.view));
|
|
23
77
|
}
|
|
24
78
|
buildDecorations(t) {
|
|
25
|
-
const r = [],
|
|
26
|
-
for (const { from:
|
|
27
|
-
|
|
28
|
-
from:
|
|
29
|
-
to:
|
|
30
|
-
enter: (
|
|
31
|
-
if (!(
|
|
32
|
-
for (const
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
return r.push(
|
|
79
|
+
const r = [], n = t.state.selection.main;
|
|
80
|
+
for (const { from: o, to: a } of t.visibleRanges)
|
|
81
|
+
h(t.state).iterate({
|
|
82
|
+
from: o,
|
|
83
|
+
to: a,
|
|
84
|
+
enter: (i) => {
|
|
85
|
+
if (!(n.from >= i.from && n.to <= i.to))
|
|
86
|
+
for (const y of e) {
|
|
87
|
+
const f = y({ name: i.name, from: i.from, to: i.to, node: i }, t);
|
|
88
|
+
if (f)
|
|
89
|
+
return r.push(f.range(i.from, i.to)), !1;
|
|
36
90
|
}
|
|
37
91
|
}
|
|
38
92
|
});
|
|
39
|
-
return
|
|
93
|
+
return s.set(r);
|
|
40
94
|
}
|
|
41
95
|
},
|
|
42
96
|
{
|
|
@@ -44,10 +98,10 @@ function f(e) {
|
|
|
44
98
|
}
|
|
45
99
|
);
|
|
46
100
|
}
|
|
47
|
-
function
|
|
48
|
-
return e.length === 0 ? [] :
|
|
101
|
+
function $(e = []) {
|
|
102
|
+
return e.length === 0 ? [] : p(e);
|
|
49
103
|
}
|
|
50
|
-
class
|
|
104
|
+
class k extends m {
|
|
51
105
|
constructor(t, r) {
|
|
52
106
|
super(), this.code = t, this.display = r;
|
|
53
107
|
}
|
|
@@ -58,7 +112,7 @@ class M extends d {
|
|
|
58
112
|
const t = document.createElement("span");
|
|
59
113
|
t.className = "hypermd-math";
|
|
60
114
|
try {
|
|
61
|
-
|
|
115
|
+
C.render(this.code, t, { displayMode: this.display, throwOnError: !1 });
|
|
62
116
|
} catch {
|
|
63
117
|
t.textContent = this.code;
|
|
64
118
|
}
|
|
@@ -68,33 +122,33 @@ class M extends d {
|
|
|
68
122
|
return !1;
|
|
69
123
|
}
|
|
70
124
|
}
|
|
71
|
-
const
|
|
125
|
+
const g = new D({
|
|
72
126
|
regexp: /\$\$([\s\S]+?)\$\$|\$([^$\n]+)\$/g,
|
|
73
127
|
decoration: (e) => {
|
|
74
128
|
const t = !!e[1], r = t ? e[1] : e[2];
|
|
75
|
-
return
|
|
76
|
-
widget: new
|
|
129
|
+
return s.replace({
|
|
130
|
+
widget: new k(r, t)
|
|
77
131
|
});
|
|
78
132
|
}
|
|
79
133
|
});
|
|
80
|
-
function
|
|
81
|
-
return
|
|
134
|
+
function S() {
|
|
135
|
+
return l.fromClass(class {
|
|
82
136
|
constructor(e) {
|
|
83
|
-
|
|
84
|
-
this.math =
|
|
137
|
+
c(this, "math");
|
|
138
|
+
this.math = g.createDeco(e);
|
|
85
139
|
}
|
|
86
140
|
update(e) {
|
|
87
|
-
this.math =
|
|
141
|
+
this.math = g.updateDeco(e, this.math);
|
|
88
142
|
}
|
|
89
143
|
}, {
|
|
90
144
|
decorations: (e) => e.math,
|
|
91
|
-
provide: (e) =>
|
|
145
|
+
provide: (e) => d.atomicRanges.of((t) => {
|
|
92
146
|
var r;
|
|
93
|
-
return ((r = t.plugin(e)) == null ? void 0 : r.math) ||
|
|
147
|
+
return ((r = t.plugin(e)) == null ? void 0 : r.math) || s.none;
|
|
94
148
|
})
|
|
95
149
|
});
|
|
96
150
|
}
|
|
97
|
-
class
|
|
151
|
+
class O extends m {
|
|
98
152
|
constructor(t, r) {
|
|
99
153
|
super(), this.url = t, this.title = r;
|
|
100
154
|
}
|
|
@@ -106,14 +160,14 @@ class E extends d {
|
|
|
106
160
|
return t.src = this.url, t.alt = this.title, t.title = this.title, t.className = "hypermd-image", t.style.maxWidth = "100%", t;
|
|
107
161
|
}
|
|
108
162
|
}
|
|
109
|
-
function
|
|
110
|
-
return
|
|
163
|
+
function R() {
|
|
164
|
+
return p([
|
|
111
165
|
(e, t) => {
|
|
112
166
|
if (e.name === "Image") {
|
|
113
|
-
const r = t.state.sliceDoc(e.from, e.to),
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
116
|
-
widget: new
|
|
167
|
+
const r = t.state.sliceDoc(e.from, e.to), n = /^!\[(.*?)\]\((.*?)\)$/.exec(r);
|
|
168
|
+
if (n)
|
|
169
|
+
return s.replace({
|
|
170
|
+
widget: new O(n[2], n[1])
|
|
117
171
|
});
|
|
118
172
|
}
|
|
119
173
|
return null;
|
|
@@ -121,15 +175,15 @@ function k() {
|
|
|
121
175
|
]);
|
|
122
176
|
}
|
|
123
177
|
function T() {
|
|
124
|
-
return
|
|
178
|
+
return d.domEventHandlers({
|
|
125
179
|
click: (e, t) => {
|
|
126
180
|
}
|
|
127
181
|
});
|
|
128
182
|
}
|
|
129
|
-
function
|
|
130
|
-
return
|
|
183
|
+
function z() {
|
|
184
|
+
return l.fromClass(class {
|
|
131
185
|
constructor(e) {
|
|
132
|
-
|
|
186
|
+
c(this, "decorations");
|
|
133
187
|
this.decorations = this.buildDecorations(e);
|
|
134
188
|
}
|
|
135
189
|
update(e) {
|
|
@@ -137,38 +191,39 @@ function W() {
|
|
|
137
191
|
}
|
|
138
192
|
buildDecorations(e) {
|
|
139
193
|
const t = [];
|
|
140
|
-
for (const { from: r, to:
|
|
141
|
-
|
|
194
|
+
for (const { from: r, to: n } of e.visibleRanges)
|
|
195
|
+
h(e.state).iterate({
|
|
142
196
|
from: r,
|
|
143
|
-
to:
|
|
144
|
-
enter: (
|
|
145
|
-
|
|
197
|
+
to: n,
|
|
198
|
+
enter: (o) => {
|
|
199
|
+
o.name === "Table" && t.push(s.mark({
|
|
146
200
|
class: "hypermd-table"
|
|
147
|
-
}).range(
|
|
201
|
+
}).range(o.from, o.to));
|
|
148
202
|
}
|
|
149
203
|
});
|
|
150
|
-
return
|
|
204
|
+
return s.set(t);
|
|
151
205
|
}
|
|
152
206
|
}, {
|
|
153
207
|
decorations: (e) => e.decorations
|
|
154
208
|
});
|
|
155
209
|
}
|
|
156
|
-
function
|
|
210
|
+
function P(e = {}) {
|
|
157
211
|
return [
|
|
158
|
-
v,
|
|
159
212
|
w(),
|
|
160
|
-
|
|
213
|
+
E(),
|
|
161
214
|
$(),
|
|
162
|
-
|
|
215
|
+
S(),
|
|
216
|
+
R(),
|
|
163
217
|
T(),
|
|
164
|
-
|
|
218
|
+
z()
|
|
165
219
|
];
|
|
166
220
|
}
|
|
167
221
|
export {
|
|
168
|
-
|
|
169
|
-
|
|
222
|
+
P as hypermd,
|
|
223
|
+
$ as hypermdFold,
|
|
170
224
|
T as hypermdInteraction,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
225
|
+
S as hypermdMath,
|
|
226
|
+
R as hypermdMedia,
|
|
227
|
+
E as hypermdStyling,
|
|
228
|
+
z as hypermdTable
|
|
174
229
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@codemirror/lang-markdown"),require("@codemirror/view"),require("@codemirror/language"),require("katex")):typeof define=="function"&&define.amd?define(["exports","@codemirror/lang-markdown","@codemirror/view","@codemirror/language","katex"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["HyperMD-uplift"]={},o.CM.lang.markdown,o.CM.view,o.CM.language,o.katex))})(this,function(o,i,r,l,C){"use strict";var P=Object.defineProperty;var V=(o,i,r)=>i in o?P(o,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[i]=r;var d=(o,i,r)=>(V(o,typeof i!="symbol"?i+"":i,r),r);const W=r.EditorView.theme({".cm-content":{fontFamily:"var(--hypermd-font-family, system-ui, sans-serif)",lineHeight:"1.6"},".cm-line .cm-header-1":{fontSize:"2em",fontWeight:"bold"},".cm-line .cm-header-2":{fontSize:"1.5em",fontWeight:"bold"},".cm-line .cm-header-3":{fontSize:"1.25em",fontWeight:"bold"},".cm-line .cm-header-4":{fontSize:"1.1em",fontWeight:"bold"},".cm-line .cm-list":{paddingLeft:"5px"},".cm-line .cm-quote":{borderLeft:"4px solid #ccc",paddingLeft:"10px",color:"#666"}});class T extends r.WidgetType{toDOM(){const e=document.createElement("span");return e.textContent="•",e.style.fontWeight="bold",e.style.marginRight="5px",e}}class k extends r.WidgetType{toDOM(){return document.createElement("span")}}function h(t){const e=[];for(const{from:n,to:c}of t.visibleRanges)l.syntaxTree(t.state).iterate({from:n,to:c,enter:s=>{const m=s.name;if(m.startsWith("HeaderMark")&&e.push(r.Decoration.replace({widget:new k}).range(s.from,s.to)),m==="ListMark"){const a=t.state.sliceDoc(s.from,s.to);["-","*","+"].includes(a.trim())&&e.push(r.Decoration.replace({widget:new T}).range(s.from,s.to))}}});return r.Decoration.set(e)}function u(){return[W,r.ViewPlugin.fromClass(class{constructor(t){d(this,"decorations");this.decorations=h(t)}update(t){(t.docChanged||t.viewportChanged)&&(this.decorations=h(t.view))}},{decorations:t=>t.decorations})]}function f(t){return r.ViewPlugin.fromClass(class{constructor(e){d(this,"decorations");this.decorations=this.buildDecorations(e)}update(e){(e.docChanged||e.viewportChanged||e.selectionSet)&&(this.decorations=this.buildDecorations(e.view))}buildDecorations(e){const n=[],c=e.state.selection.main;for(const{from:s,to:m}of e.visibleRanges)l.syntaxTree(e.state).iterate({from:s,to:m,enter:a=>{if(!(c.from>=a.from&&c.to<=a.to))for(const q of t){const x=q({name:a.name,from:a.from,to:a.to,node:a},e);if(x)return n.push(x.range(a.from,a.to)),!1}}});return r.Decoration.set(n)}},{decorations:e=>e.decorations})}function g(t=[]){return t.length===0?[]:f(t)}class E extends r.WidgetType{constructor(e,n){super(),this.code=e,this.display=n}eq(e){return e.code==this.code&&e.display==this.display}toDOM(){const e=document.createElement("span");e.className="hypermd-math";try{C.render(this.code,e,{displayMode:this.display,throwOnError:!1})}catch{e.textContent=this.code}return e}ignoreEvent(){return!1}}const p=new r.MatchDecorator({regexp:/\$\$([\s\S]+?)\$\$|\$([^$\n]+)\$/g,decoration:t=>{const e=!!t[1],n=e?t[1]:t[2];return r.Decoration.replace({widget:new E(n,e)})}});function y(){return r.ViewPlugin.fromClass(class{constructor(t){d(this,"math");this.math=p.createDeco(t)}update(t){this.math=p.updateDeco(t,this.math)}},{decorations:t=>t.math,provide:t=>r.EditorView.atomicRanges.of(e=>{var n;return((n=e.plugin(t))==null?void 0:n.math)||r.Decoration.none})})}class S extends r.WidgetType{constructor(e,n){super(),this.url=e,this.title=n}eq(e){return this.url===e.url&&this.title===e.title}toDOM(){const e=document.createElement("img");return e.src=this.url,e.alt=this.title,e.title=this.title,e.className="hypermd-image",e.style.maxWidth="100%",e}}function D(){return f([(t,e)=>{if(t.name==="Image"){const n=e.state.sliceDoc(t.from,t.to),c=/^!\[(.*?)\]\((.*?)\)$/.exec(n);if(c)return r.Decoration.replace({widget:new S(c[2],c[1])})}return null}])}function M(){return r.EditorView.domEventHandlers({click:(t,e)=>{}})}function b(){return r.ViewPlugin.fromClass(class{constructor(t){d(this,"decorations");this.decorations=this.buildDecorations(t)}update(t){(t.docChanged||t.viewportChanged)&&(this.decorations=this.buildDecorations(t.view))}buildDecorations(t){const e=[];for(const{from:n,to:c}of t.visibleRanges)l.syntaxTree(t.state).iterate({from:n,to:c,enter:s=>{s.name==="Table"&&e.push(r.Decoration.mark({class:"hypermd-table"}).range(s.from,s.to))}});return r.Decoration.set(e)}},{decorations:t=>t.decorations})}function w(t={}){return[i.markdown(),u(),g(),y(),D(),M(),b()]}o.hypermd=w,o.hypermdFold=g,o.hypermdInteraction=M,o.hypermdMath=y,o.hypermdMedia=D,o.hypermdStyling=u,o.hypermdTable=b,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "hypermd-uplift",
|
|
3
|
-
"version": "0.4.
|
|
2
|
+
"name": "hypermd-uplift",
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "A full-featured Markdown editor, breaks the wall between writing and preview.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.js",
|
|
@@ -39,13 +39,12 @@
|
|
|
39
39
|
"url": "https://github.com/Keshav-writes-code/HyperMD-uplift.git"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
+
"@codemirror/lang-markdown": "^6.0.0",
|
|
43
|
+
"@codemirror/language": "^6.0.0",
|
|
42
44
|
"@codemirror/state": "^6.0.0",
|
|
43
45
|
"@codemirror/view": "^6.0.0",
|
|
44
|
-
"@codemirror/language": "^6.0.0",
|
|
45
|
-
"@codemirror/lang-markdown": "^6.0.0",
|
|
46
46
|
"katex": "^0.16.0"
|
|
47
47
|
},
|
|
48
|
-
"dependencies": {},
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@codemirror/autocomplete": "^6.0.0",
|
|
51
50
|
"@codemirror/commands": "^6.0.0",
|
|
@@ -55,6 +54,7 @@
|
|
|
55
54
|
"@codemirror/search": "^6.0.0",
|
|
56
55
|
"@codemirror/state": "^6.0.0",
|
|
57
56
|
"@codemirror/view": "^6.0.0",
|
|
57
|
+
"@lezer/common": "^1.5.0",
|
|
58
58
|
"@types/node": "^18.0.0",
|
|
59
59
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
60
60
|
"@typescript-eslint/parser": "^6.0.0",
|