4
4
* extends the basic schemas provided by ProseMirror
5
5
*/
6
6
7
- import { schema as schemaBasic } from 'prosemirror-schema-basic' ;
8
- import { tableNodes } from 'prosemirror-tables' ;
9
- import { bulletList , listItem , orderedList } from 'prosemirror-schema-list' ;
7
+ import { schema as schemaBasic } from 'prosemirror-schema-basic' ;
8
+ import { tableNodes } from 'prosemirror-tables' ;
9
+ import { bulletList , listItem , orderedList } from 'prosemirror-schema-list' ;
10
10
11
11
export default function getSpec ( ) {
12
- let { nodes, marks } = schemaBasic . spec ;
12
+ let { nodes, marks} = schemaBasic . spec ;
13
13
14
14
const doc = nodes . get ( 'doc' ) ;
15
15
doc . content = '(block | baseonly | container | protected_block | substitution_block)+' ;
16
16
doc . attrs = {
17
- nocache : { default : false } ,
18
- notoc : { default : false } ,
17
+ nocache : { default : false } ,
18
+ notoc : { default : false } ,
19
19
} ;
20
20
nodes = nodes . update ( 'doc' , doc ) ;
21
21
@@ -58,7 +58,7 @@ export default function getSpec() {
58
58
59
59
const tableNode = nodes . get ( 'table' ) ;
60
60
tableNode . toDOM = function toDOM ( ) {
61
- return [ 'div' , { class : 'table' } , [ 'table' , { class : 'inline' } , [ 'tbody' , 0 ] ] ] ;
61
+ return [ 'div' , { class : 'table' } , [ 'table' , { class : 'inline' } , [ 'tbody' , 0 ] ] ] ;
62
62
} ;
63
63
nodes . update ( 'table' , tableNode ) ;
64
64
@@ -69,15 +69,15 @@ export default function getSpec() {
69
69
group : 'protected_block' ,
70
70
code : true ,
71
71
toDOM ( ) {
72
- return [ 'pre' , { class : 'code' } , 0 ] ;
72
+ return [ 'pre' , { class : 'code' } , 0 ] ;
73
73
} ,
74
74
} ) ;
75
75
76
76
const codeBlock = nodes . get ( 'code_block' ) ;
77
77
codeBlock . attrs = {
78
- class : { default : 'code' } ,
79
- 'data-filename' : { default : '' } ,
80
- 'data-language' : { default : '' } ,
78
+ class : { default : 'code' } ,
79
+ 'data-filename' : { default : '' } ,
80
+ 'data-language' : { default : '' } ,
81
81
} ;
82
82
codeBlock . toDOM = function toDOM ( node ) {
83
83
return [ 'pre' , node . attrs , 0 ] ;
@@ -88,16 +88,16 @@ export default function getSpec() {
88
88
const quote = nodes . get ( 'blockquote' ) ;
89
89
quote . content = '(block | blockquote | protected_block)+' ;
90
90
quote . group = 'container' ;
91
- quote . toDom = ( ) => [ 'blockquote' , { } , [ 'div' , { class : 'no' } , 0 ] ] ;
91
+ quote . toDom = ( ) => [ 'blockquote' , { } , [ 'div' , { class : 'no' } , 0 ] ] ;
92
92
nodes . update ( 'blockquote' , quote ) ;
93
93
94
94
const imageNode = nodes . get ( 'image' ) ;
95
- imageNode . attrs . width = { default : '' } ;
96
- imageNode . attrs . height = { default : '' } ;
97
- imageNode . attrs . align = { default : '' } ;
98
- imageNode . attrs . linking = { default : '' } ;
99
- imageNode . attrs . cache = { default : '' } ;
100
- imageNode . attrs [ 'data-resolvedHtml' ] = { default : '' } ;
95
+ imageNode . attrs . width = { default : '' } ;
96
+ imageNode . attrs . height = { default : '' } ;
97
+ imageNode . attrs . align = { default : '' } ;
98
+ imageNode . attrs . linking = { default : '' } ;
99
+ imageNode . attrs . cache = { default : '' } ;
100
+ imageNode . attrs [ 'data-resolvedHtml' ] = { default : '' } ;
101
101
imageNode . attrs . id = { } ;
102
102
delete imageNode . attrs . src ;
103
103
imageNode . parseDOM = [
@@ -106,16 +106,24 @@ export default function getSpec() {
106
106
getAttrs : function getAttrs ( dom ) {
107
107
const src = dom . getAttribute ( 'src' ) ;
108
108
const dokuWikiFetch = `${ DOKU_BASE } lib/exe/fetch.php` ;
109
- if ( ! src . includes ( dokuWikiFetch ) ) {
109
+ const dokuWikiMedia = `${ DOKU_BASE } _media/` ;
110
+
111
+ let id = '' ;
112
+ let url ;
113
+ try {
114
+ url = new URL ( src , window . location . href ) ;
115
+ } catch ( e ) {
110
116
return undefined ; // let another rule handle this case
111
117
}
112
- const [ , query ] = src . split ( '?' ) ;
113
- const attrs = query . split ( '&' )
114
- . map ( item => item . split ( '=' ) )
115
- . reduce ( ( acc , [ key , value ] ) => {
116
- acc [ key ] = decodeURIComponent ( value ) ;
117
- return acc ;
118
- } , { } ) ;
118
+
119
+ if ( src . includes ( dokuWikiFetch ) ) {
120
+ id = url . searchParams . get ( 'media' ) ;
121
+ } else if ( src . includes ( dokuWikiMedia ) ) {
122
+ id = url . pathname . split ( '/' ) . pop ( ) ;
123
+ id = id . replaceAll ( ';' , ':' ) ; // on windows, semicolons might be used as namespace separator
124
+ }
125
+ if ( ! id ) return undefined ; // let another rule handle this case
126
+
119
127
let align = '' ;
120
128
if ( dom . classList . contains ( 'medialeft' ) ) {
121
129
align = 'left' ;
@@ -124,12 +132,13 @@ export default function getSpec() {
124
132
} else if ( dom . classList . contains ( 'mediacenter' ) ) {
125
133
align = 'center' ;
126
134
}
135
+
127
136
return {
128
137
// a relative ID might be preferred (see imgpaste plugin)
129
- id : dom . dataset . relID || attrs . media ,
138
+ id : dom . dataset . relid || id ,
130
139
title : dom . getAttribute ( 'alt' ) ,
131
- width : attrs . w ,
132
- height : attrs . h ,
140
+ width : url . searchParams . get ( 'w' ) ,
141
+ height : url . searchParams . get ( 'h' ) ,
133
142
align,
134
143
'data-resolvedHtml' : dom . outerHTML ,
135
144
} ;
@@ -153,7 +162,7 @@ export default function getSpec() {
153
162
154
163
const imageAttrs = { } ;
155
164
Object . keys ( imageNode . attrs ) . forEach ( ( key ) => {
156
- imageAttrs [ `image-${ key } ` ] = { default : null } ;
165
+ imageAttrs [ `image-${ key } ` ] = { default : null } ;
157
166
} ) ;
158
167
159
168
nodes = nodes . addToEnd ( 'link' , {
@@ -162,13 +171,13 @@ export default function getSpec() {
162
171
attrs : {
163
172
'data-type' : { } ,
164
173
'data-inner' : { } ,
165
- 'data-name' : { default : null } ,
166
- 'data-resolvedID' : { default : null } ,
167
- 'data-resolvedUrl' : { default : null } ,
168
- 'data-resolvedName' : { default : null } ,
169
- 'data-resolvedClass' : { default : null } ,
170
- 'data-resolvedTitle' : { default : null } ,
171
- 'data-resolvedImage' : { default : '' } ,
174
+ 'data-name' : { default : null } ,
175
+ 'data-resolvedID' : { default : null } ,
176
+ 'data-resolvedUrl' : { default : null } ,
177
+ 'data-resolvedName' : { default : null } ,
178
+ 'data-resolvedClass' : { default : null } ,
179
+ 'data-resolvedTitle' : { default : null } ,
180
+ 'data-resolvedImage' : { default : '' } ,
172
181
...imageAttrs ,
173
182
} ,
174
183
toDOM ( node ) {
@@ -180,7 +189,7 @@ export default function getSpec() {
180
189
content : '' ,
181
190
marks : '' ,
182
191
attrs : {
183
- contentJSON : { default : '' } ,
192
+ contentJSON : { default : '' } ,
184
193
} ,
185
194
group : 'inline' ,
186
195
inline : true ,
@@ -209,7 +218,7 @@ export default function getSpec() {
209
218
return false ;
210
219
}
211
220
const syntax = dom . getAttribute ( 'alt' ) ;
212
- return { icon, syntax } ;
221
+ return { icon, syntax} ;
213
222
} ,
214
223
} ] ,
215
224
} ) ;
@@ -218,24 +227,24 @@ export default function getSpec() {
218
227
group : 'substitution_block' ,
219
228
atom : true ,
220
229
attrs : {
221
- class : { default : 'rss' } ,
230
+ class : { default : 'rss' } ,
222
231
url : { } ,
223
- max : { default : 8 } ,
224
- reverse : { default : null } ,
225
- author : { default : null } ,
226
- date : { default : null } ,
227
- details : { default : null } ,
228
- refresh : { default : '' } ,
229
- renderedHTML : { default : null } ,
232
+ max : { default : 8 } ,
233
+ reverse : { default : null } ,
234
+ author : { default : null } ,
235
+ date : { default : null } ,
236
+ details : { default : null } ,
237
+ refresh : { default : '' } ,
238
+ renderedHTML : { default : null } ,
230
239
} ,
231
240
} ) ;
232
241
233
242
nodes = nodes . addToEnd ( 'dwplugin_block' , {
234
243
content : 'text*' ,
235
244
marks : '' ,
236
245
attrs : {
237
- class : { default : 'dwplugin' } ,
238
- 'data-pluginname' : { default : ' ' } ,
246
+ class : { default : 'dwplugin' } ,
247
+ 'data-pluginname' : { default : ' ' } ,
239
248
} ,
240
249
draggable : true ,
241
250
inline : false ,
@@ -252,8 +261,8 @@ export default function getSpec() {
252
261
nodes = nodes . addToEnd ( 'dwplugin_inline' , {
253
262
content : 'text*' ,
254
263
attrs : {
255
- class : { default : 'dwplugin' } ,
256
- 'data-pluginname' : { default : ' ' } ,
264
+ class : { default : 'dwplugin' } ,
265
+ 'data-pluginname' : { default : ' ' } ,
257
266
} ,
258
267
marks : '' ,
259
268
draggable : true ,
@@ -275,7 +284,7 @@ export default function getSpec() {
275
284
276
285
marks = marks . addToEnd ( 'deleted' , {
277
286
parseDOM : [
278
- { tag : 'del' } ,
287
+ { tag : 'del' } ,
279
288
{
280
289
style : 'text-decoration' ,
281
290
// https://discuss.prosemirror.net/t/dom-parsing-and-getattrs/612
@@ -289,7 +298,7 @@ export default function getSpec() {
289
298
290
299
marks = marks . addToEnd ( 'underline' , {
291
300
parseDOM : [
292
- { tag : 'u' } ,
301
+ { tag : 'u' } ,
293
302
{
294
303
style : 'text-decoration' ,
295
304
getAttrs : value => value === 'underline' && null ,
@@ -302,7 +311,7 @@ export default function getSpec() {
302
311
303
312
marks = marks . addToEnd ( 'subscript' , {
304
313
parseDOM : [
305
- { tag : 'sub' } ,
314
+ { tag : 'sub' } ,
306
315
{
307
316
style : 'vertical-align' ,
308
317
getAttrs : value => value === 'sub' && null ,
@@ -315,7 +324,7 @@ export default function getSpec() {
315
324
316
325
marks = marks . addToEnd ( 'superscript' , {
317
326
parseDOM : [
318
- { tag : 'sup' } ,
327
+ { tag : 'sup' } ,
319
328
{
320
329
style : 'vertical-align' ,
321
330
getAttrs : value => value === 'super' && null ,
@@ -329,15 +338,15 @@ export default function getSpec() {
329
338
marks = marks . addToEnd ( 'unformatted' , {
330
339
excludes : '_' ,
331
340
toDOM ( ) {
332
- return [ 'span' , { class : 'unformatted' } ] ;
341
+ return [ 'span' , { class : 'unformatted' } ] ;
333
342
} ,
334
343
} ) ;
335
344
336
345
if ( window . Prosemirror && window . Prosemirror . pluginSchemas ) {
337
346
window . Prosemirror . pluginSchemas . forEach ( ( addSchema ) => {
338
- ( { nodes, marks } = addSchema ( nodes , marks ) ) ;
347
+ ( { nodes, marks} = addSchema ( nodes , marks ) ) ;
339
348
} ) ;
340
349
}
341
350
342
- return { nodes, marks } ;
351
+ return { nodes, marks} ;
343
352
}
0 commit comments