Skip to content
This repository was archived by the owner on Sep 8, 2023. It is now read-only.

Commit 3782dc4

Browse files
committed
Add temporary patched version of remark-disable-tokenizers
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 1ab49dc commit 3782dc4

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"vue": "^2.6.11"
3636
},
3737
"dependencies": {
38+
"clone": "^2.1.2",
3839
"core-js": "^3.6.4",
3940
"property-information": "^5.5.0",
4041
"rehype-add-classes": "^1.0.0",

src/RichText.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import markdown from 'remark-parse'
2727
import breaks from 'remark-breaks'
2828
import remark2rehype from 'remark-rehype'
2929
import rehype2react from 'rehype-react'
30-
import remarkDisableBlocks from 'remark-disable-tokenizers'
30+
// import remarkDisableBlocks from 'remark-disable-tokenizers'
31+
import remarkDisableBlocks from './remarkDisableBlocks'
3132
import remarkExternalLinks from 'remark-external-links'
3233
import rehypeAddClasses from 'rehype-add-classes'
3334

src/remarkDisableBlocks.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) Zeste de Savoir (https://zestedesavoir.com)
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
/**
27+
* Patched version of https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-disable-tokenizers
28+
* to avoid newline issues described in https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-disable-tokenizers
29+
*/
30+
31+
import clone from 'clone'
32+
33+
const noop = () => false
34+
35+
const throwing = (msg) =>
36+
() => {
37+
throw new Error(msg)
38+
}
39+
40+
function ignore({ block = [], inline = [] } = {}) {
41+
if (block.length) {
42+
block
43+
.filter((key) => {
44+
if (Array.isArray(key)) return block.map(xs => xs[0]).includes(key[0])
45+
return block.includes(key)
46+
})
47+
.forEach((key) => {
48+
if (Array.isArray(key) && key.length === 2) {
49+
this.Parser.prototype.blockTokenizers[key[0]] = throwing(key[1])
50+
} else {
51+
this.Parser.prototype.blockTokenizers[key] = noop
52+
}
53+
})
54+
}
55+
56+
if (inline.length) {
57+
inline
58+
.filter((key) => {
59+
if (Array.isArray(key)) return inline.map(xs => xs[0]).includes(key[0])
60+
return inline.includes(key)
61+
})
62+
.forEach((key) => {
63+
let tokenizerName
64+
let replacer
65+
if (Array.isArray(key) && key.length === 2) {
66+
tokenizerName = key[0]
67+
replacer = throwing(key[1])
68+
} else {
69+
tokenizerName = key
70+
replacer = clone(noop)
71+
}
72+
if (this.Parser.prototype.inlineTokenizers[tokenizerName]) {
73+
Object
74+
.keys(this.Parser.prototype.inlineTokenizers[tokenizerName])
75+
.forEach((prop) => {
76+
replacer[prop] = this.Parser.prototype.inlineTokenizers[tokenizerName][prop]
77+
})
78+
}
79+
this.Parser.prototype.inlineTokenizers[tokenizerName] = replacer
80+
})
81+
}
82+
}
83+
84+
export default ignore

0 commit comments

Comments
 (0)