@tryghost/mg-shortcodes 0.12.2 → 0.12.4
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 -2
- package/lib/Shortcodes.js +17 -8
- package/package.json +3 -7
package/README.md
CHANGED
|
@@ -58,8 +58,8 @@ Follow the instructions for the top-level repo.
|
|
|
58
58
|
|
|
59
59
|
## Test
|
|
60
60
|
|
|
61
|
-
- `pnpm
|
|
62
|
-
-
|
|
61
|
+
- `pnpm test` runs the package tests
|
|
62
|
+
- Linting and formatting are run from the repo root (`pnpm lint`, `pnpm format`)
|
|
63
63
|
- `pnpm benchmark` run benchmarks
|
|
64
64
|
|
|
65
65
|
|
package/lib/Shortcodes.js
CHANGED
|
@@ -13,9 +13,12 @@ export default class Shortcodes {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
unwrap(name) {
|
|
16
|
-
this.shortcodes.push({
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
this.shortcodes.push({
|
|
17
|
+
name,
|
|
18
|
+
callback: ({content}) => {
|
|
19
|
+
return `${content} `;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
unwrapFromQuotes(string = '') {
|
|
@@ -25,13 +28,16 @@ export default class Shortcodes {
|
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
parseAttributes(attributesString) {
|
|
28
|
-
const tagAttrRegExp = new RegExp(
|
|
31
|
+
const tagAttrRegExp = new RegExp(
|
|
32
|
+
`([\\w-]+)\\s*=\\s*"([^"]*)"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'"]+)(?:\\s|$)|"([^"]*)"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)`,
|
|
33
|
+
'gmi'
|
|
34
|
+
);
|
|
29
35
|
|
|
30
36
|
const tagAttrMatches = [...RegExp.prototype[Symbol.matchAll].call(tagAttrRegExp, attributesString)];
|
|
31
37
|
|
|
32
38
|
let attributes = {};
|
|
33
39
|
|
|
34
|
-
tagAttrMatches.forEach(
|
|
40
|
+
tagAttrMatches.forEach(item => {
|
|
35
41
|
let theKey;
|
|
36
42
|
let theValue;
|
|
37
43
|
if (item[1] && item[2] !== 'undefined') {
|
|
@@ -118,14 +124,17 @@ export default class Shortcodes {
|
|
|
118
124
|
|
|
119
125
|
let result = false;
|
|
120
126
|
|
|
121
|
-
this.shortcodes.forEach(
|
|
127
|
+
this.shortcodes.forEach(shortcode => {
|
|
122
128
|
if (result && result.length) {
|
|
123
129
|
return result;
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
let shortcodeName = shortcode.name;
|
|
127
133
|
|
|
128
|
-
let shortcodeRegExp = new RegExp(
|
|
134
|
+
let shortcodeRegExp = new RegExp(
|
|
135
|
+
`\\[${shortcodeName}(?<attrs>\\s[\\s\\S]*?)?\\](?:(?<content>(?!\\\\s*?(?:\\[${shortcodeName}|\\[\\/(?!${shortcodeName})))[\\s\\S]*?)(\\[\\/${shortcodeName}\\]))?`,
|
|
136
|
+
'm'
|
|
137
|
+
);
|
|
129
138
|
|
|
130
139
|
let match = text.match(shortcodeRegExp);
|
|
131
140
|
|
|
@@ -146,7 +155,7 @@ export default class Shortcodes {
|
|
|
146
155
|
}
|
|
147
156
|
});
|
|
148
157
|
|
|
149
|
-
return
|
|
158
|
+
return result ? result : false;
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
getShortcode(name) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-shortcodes",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/migrate.git",
|
|
@@ -17,13 +17,9 @@
|
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"eslint": "8.57.1"
|
|
22
|
-
},
|
|
20
|
+
"devDependencies": {},
|
|
23
21
|
"scripts": {
|
|
24
22
|
"dev": "echo \"Implement me!\"",
|
|
25
|
-
"test": "node --test 'test/**/*.test.js'"
|
|
26
|
-
"posttest": "pnpm lint",
|
|
27
|
-
"lint": "eslint . --ext .js --cache"
|
|
23
|
+
"test": "node --test 'test/**/*.test.js'"
|
|
28
24
|
}
|
|
29
25
|
}
|