@tryghost/mg-buttondown 0.5.0 → 0.6.0
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/build/lib/process.d.ts +1 -1
- package/build/lib/process.js +35 -35
- package/build/lib/process.js.map +1 -1
- package/package.json +6 -6
package/build/lib/process.d.ts
CHANGED
package/build/lib/process.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
2
|
import MarkdownItFootnote from 'markdown-it-footnote';
|
|
3
|
-
import
|
|
3
|
+
import { domUtils } from '@tryghost/mg-utils';
|
|
4
|
+
const { serializeChildren, replaceWith, insertBefore, insertAfter, wrap, createElement } = domUtils;
|
|
4
5
|
const processHTML = ({ postData }) => {
|
|
5
6
|
const md = new MarkdownIt({
|
|
6
7
|
html: true
|
|
@@ -12,41 +13,40 @@ const processHTML = ({ postData }) => {
|
|
|
12
13
|
// Strip HTML comments
|
|
13
14
|
html = html.replace(/<!--(.*?)-->/gm, '');
|
|
14
15
|
let renderedHtml = md.render(html);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
let finalHtml = domUtils.processFragment(renderedHtml, (parsed) => {
|
|
17
|
+
// Handle embedded tweets
|
|
18
|
+
parsed.$('blockquote.twitter-tweet').forEach((el) => {
|
|
19
|
+
const figure = createElement(parsed.document, 'figure', { class: 'kg-card kg-embed-card' });
|
|
20
|
+
const script = createElement(parsed.document, 'script', { async: '', src: 'https://platform.twitter.com/widgets.js', charset: 'utf-8' });
|
|
21
|
+
wrap(el, figure);
|
|
22
|
+
figure.appendChild(script);
|
|
23
|
+
insertBefore(figure, '<!--kg-card-begin: embed-->');
|
|
24
|
+
insertAfter(figure, '<!--kg-card-end: embed-->');
|
|
25
|
+
});
|
|
26
|
+
// Move the .footnotes-sep HR so it's inside the .footnotes element
|
|
27
|
+
parsed.$('.footnotes-sep').forEach((el) => {
|
|
28
|
+
const footnotes = parsed.$('.footnotes')[0];
|
|
29
|
+
if (footnotes) {
|
|
30
|
+
footnotes.insertBefore(el, footnotes.firstChild);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Wrap footnotes in a HTML card
|
|
34
|
+
parsed.$('.footnotes').forEach((el) => {
|
|
35
|
+
insertBefore(el, '<!--kg-card-begin: html-->');
|
|
36
|
+
insertAfter(el, '<!--kg-card-end: html-->');
|
|
37
|
+
});
|
|
38
|
+
parsed.$('p').forEach((el) => {
|
|
39
|
+
if ((el.textContent || '').includes('{{ subscribe_form }}')) {
|
|
40
|
+
el.remove();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
parsed.$('p').forEach((el) => {
|
|
44
|
+
if ((el.textContent || '').trim().length === 0) {
|
|
45
|
+
el.remove();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return parsed.html();
|
|
20
49
|
});
|
|
21
|
-
// Handle embeded tweets
|
|
22
|
-
$('blockquote.twitter-tweet').each((i, el) => {
|
|
23
|
-
let $figure = $('<figure class="kg-card kg-embed-card"></figure>');
|
|
24
|
-
let $script = $('<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>');
|
|
25
|
-
$(el).wrap($figure);
|
|
26
|
-
$figure.append($script);
|
|
27
|
-
$figure.before('<!--kg-card-begin: embed-->');
|
|
28
|
-
$figure.after('<!--kg-card-end: embed-->');
|
|
29
|
-
});
|
|
30
|
-
// Move the .footnotes-sep HR so it's inside the .footnotes element
|
|
31
|
-
$('.footnotes-sep').each((i, el) => {
|
|
32
|
-
$(el).prependTo($('.footnotes'));
|
|
33
|
-
});
|
|
34
|
-
// Wrap footnotes in a HTML card
|
|
35
|
-
$('.footnotes').each((i, el) => {
|
|
36
|
-
$(el).before('<!--kg-card-begin: html-->');
|
|
37
|
-
$(el).after('<!--kg-card-end: html-->');
|
|
38
|
-
});
|
|
39
|
-
$('p').each((i, el) => {
|
|
40
|
-
if ($(el).text().includes('{{ subscribe_form }}')) {
|
|
41
|
-
$(el).remove();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
$('p').each((i, el) => {
|
|
45
|
-
if ($(el).text().trim().length === 0) {
|
|
46
|
-
$(el).remove();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
let finalHtml = $.root().html();
|
|
50
50
|
return finalHtml;
|
|
51
51
|
};
|
|
52
52
|
export { processHTML };
|
package/build/lib/process.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/lib/process.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/lib/process.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE5C,MAAM,EAAC,iBAAiB,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAC,GAAG,QAAQ,CAAC;AAElG,MAAM,WAAW,GAAG,CAAC,EAAC,QAAQ,EAAgC,EAAE,EAAE;IAC9D,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC;QACtB,IAAI,EAAE,IAAI;KACb,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAE3B,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;IAE9B,sBAAsB;IACtB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE1C,IAAI,YA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,WAAW,CAAC,EAAE,EAAE,0BAA0B,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YACzB,IAAI,CAAC,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;gBAC1D,EAAE,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YACzB,IAAI,CAAC,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC7C,EAAE,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,OAAO,EACH,WAAW,EACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-buttondown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/migrate.git",
|
|
@@ -24,22 +24,22 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/node": "24.12.
|
|
28
|
-
"@types/sinon": "21.0.
|
|
27
|
+
"@types/node": "24.12.2",
|
|
28
|
+
"@types/sinon": "21.0.1",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "8.58.0",
|
|
30
30
|
"@typescript-eslint/parser": "8.58.0",
|
|
31
31
|
"c8": "11.0.0",
|
|
32
|
-
"dotenv": "17.4.
|
|
32
|
+
"dotenv": "17.4.1",
|
|
33
33
|
"eslint": "8.57.1",
|
|
34
34
|
"sinon": "21.0.3",
|
|
35
35
|
"typescript": "6.0.2"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@tryghost/errors": "3.0.3",
|
|
39
|
-
"cheerio": "1.2.0",
|
|
40
39
|
"markdown-it": "14.1.1",
|
|
41
40
|
"markdown-it-footnote": "4.0.0",
|
|
42
|
-
"@tryghost/mg-fs-utils": "0.
|
|
41
|
+
"@tryghost/mg-fs-utils": "0.21.0",
|
|
42
|
+
"@tryghost/mg-utils": "0.6.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"dev": "echo \"Implement me!\"",
|