@tryghost/mg-shortcodes 0.1.1 → 0.1.3
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 -4
- package/lib/Shortcodes.js +4 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Shortcodes
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Unhandled shortcodes are returned without modification.
|
|
3
|
+
A barebones shortcode parser that handles edge cases.
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
@@ -20,7 +18,7 @@ or
|
|
|
20
18
|
import Shortcodes from '@tryghost/mg-shortcodes';
|
|
21
19
|
|
|
22
20
|
// Create a new instance
|
|
23
|
-
const
|
|
21
|
+
const shortcodes = new Shortcodes();
|
|
24
22
|
|
|
25
23
|
// Handle [link] shortcodes
|
|
26
24
|
shortcodes.add('link', ({attrs, content}) => {
|
package/lib/Shortcodes.js
CHANGED
|
@@ -15,7 +15,7 @@ class Shortcodes {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
unwrapFromQuotes(string) {
|
|
18
|
-
const chars = ['’', '”', '“', '‘', '"'];
|
|
18
|
+
const chars = ['’', '”', '“', '‘', '"', '"'];
|
|
19
19
|
const quoteRegExp = new RegExp(`^(${chars.join('|')})|(${chars.join('|')})$`, 'gm');
|
|
20
20
|
return string.replace(quoteRegExp, '');
|
|
21
21
|
}
|
|
@@ -30,11 +30,11 @@ class Shortcodes {
|
|
|
30
30
|
tagAttrMatches.forEach((item) => {
|
|
31
31
|
let theKey;
|
|
32
32
|
let theValue;
|
|
33
|
-
if (item[1] && item[2]) {
|
|
33
|
+
if (item[1] && item[2] !== 'undefined') {
|
|
34
34
|
// Quoted key="value" pairs
|
|
35
35
|
theKey = item[1];
|
|
36
36
|
theValue = this.typeCast(item[2]);
|
|
37
|
-
} else if (item[5] && item[6]) {
|
|
37
|
+
} else if (item[5] && item[6] !== 'undefined') {
|
|
38
38
|
// Unquoted key=value pairs
|
|
39
39
|
theKey = item[5];
|
|
40
40
|
theValue = this.typeCast(item[6]);
|
|
@@ -158,6 +158,7 @@ class Shortcodes {
|
|
|
158
158
|
let knownShortcode = this.hasKnownShortcode(text);
|
|
159
159
|
|
|
160
160
|
if (knownShortcode) {
|
|
161
|
+
// console.log({knownShortcode});
|
|
161
162
|
const theCall = this.getCallback(knownShortcode.name);
|
|
162
163
|
const attrs = this.parseAttributes(knownShortcode.match.groups.attrs);
|
|
163
164
|
const content = knownShortcode.match.groups.content;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-shortcodes",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-shortcodes",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.31.0",
|
|
24
24
|
"jest": "29.3.1",
|
|
25
|
-
"jest-extended": "3.2.
|
|
25
|
+
"jest-extended": "3.2.2"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "ac01636f55ec4bcf15b1fed2e5efe58327009d0a"
|
|
28
28
|
}
|