@takeshape/util 11.25.1 → 11.28.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/dist/draftjs-templates.d.ts +1 -1
- package/dist/draftjs-templates.d.ts.map +1 -1
- package/dist/draftjs.d.ts.map +1 -1
- package/dist/draftjs.js +41 -22
- package/es/draftjs.js +42 -22
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draftjs-templates.d.ts","sourceRoot":"","sources":["../../src/draftjs-templates.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,oBAAoB,EAAC,MAAM,UAAU,CAAC;AAGnD,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,oBAAoB,CAAC;IACnC,QAAQ,EAAE,GAAG,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"draftjs-templates.d.ts","sourceRoot":"","sources":["../../src/draftjs-templates.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,oBAAoB,EAAC,MAAM,UAAU,CAAC;AAGnD,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,oBAAoB,CAAC;IACnC,QAAQ,EAAE,GAAG,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,kBAAkB,KAAG,qBAAqB,GAAG,SAmEpF,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,mBAAmB,WAAY,sBAAsB,KAAG,qBAcpE,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAY,mBAAmB,KAAG,qBAsD9D,CAAC"}
|
package/dist/draftjs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draftjs.d.ts","sourceRoot":"","sources":["../../src/draftjs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,oBAAoB,EAA6B,KAAK,MAAM,EAAsB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"draftjs.d.ts","sourceRoot":"","sources":["../../src/draftjs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,oBAAoB,EAA6B,KAAK,MAAM,EAAsB,MAAM,UAAU,CAAC;AAoBhH,MAAM,MAAM,OAAO,GAAG;IACpB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;AAE/C,KAAK,mBAAmB,GAAG;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,GAAG,MAAM,CAAC;AA2BX,KAAK,2BAA2B,GAAG,MAAM,CACvC,MAAM,EACN;IACE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,mBAAmB,KAAK,MAAM,CAAC;IAC/C,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,mBAAmB,KAAK,MAAM,CAAC;CACjD,CACF,CAAC;AAiCF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY;YAEb,MAAM;YACN,MAAM;uBAIT,MAAM,UACL,MAAM;;;IAOf,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YAAa,oBAAoB,KAAG,oBA2BlE,CAAC;AAEF,wBAAgB,WAAW,CACzB,OAAO,EAAE,oBAAoB,EAC7B,UAAU,CAAC,EAAE,2BAA2B,EACxC,WAAW,CAAC,EAAE,2BAA2B,GACxC,MAAM,CAwER;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CA0DvG;AAmBD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EACpC,MAAM,8BAAqB,GAC1B,MAAM,CAyDR;AAwND,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAgD7D;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AA0OD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkB5D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CA0G9D"}
|
package/dist/draftjs.js
CHANGED
|
@@ -31,9 +31,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
31
31
|
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
// With @types/htmlparser2 it says parseDOM is not exported; excluding types for now
|
|
35
|
-
// @ts-expect-error Untyped
|
|
36
|
-
|
|
37
34
|
const SUPERSCRIPT_MARKER = 'TEMPORARY_SUPERSCRIPT_MARKER_TLfDNyf7VYKDduyL';
|
|
38
35
|
const SUBSCRIPT_MARKER = 'TEMPORARY_SUBSCRIPT_MARKER_K5VrdPEzyQyy2RcY';
|
|
39
36
|
const INSERT_MARKER = 'TEMPORARY_INSERT_MARKER_FSYdr8m8CS7YLb8y';
|
|
@@ -360,31 +357,31 @@ function parseFigureClass(className) {
|
|
|
360
357
|
// eslint-disable-next-line complexity
|
|
361
358
|
function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
|
|
362
359
|
for (const figure of dom) {
|
|
363
|
-
if (figure.type ===
|
|
360
|
+
if (figure.type === _htmlparser.ElementType.Tag && figure.name === 'figure') {
|
|
364
361
|
let link;
|
|
365
362
|
const figureChildOne = figure.children?.[0];
|
|
366
363
|
const figureChildTwo = figure.children?.[1];
|
|
367
|
-
if (figureChildOne?.type ===
|
|
364
|
+
if (figureChildOne?.type === _htmlparser.ElementType.Tag && figureChildOne?.name === 'a') {
|
|
368
365
|
link = figureChildOne;
|
|
369
366
|
}
|
|
370
367
|
let figcaption;
|
|
371
|
-
if (figureChildOne?.type ===
|
|
368
|
+
if (figureChildOne?.type === _htmlparser.ElementType.Tag && figureChildOne?.name === 'figcaption') {
|
|
372
369
|
figcaption = figureChildOne;
|
|
373
|
-
} else if (figureChildTwo?.type ===
|
|
370
|
+
} else if (figureChildTwo?.type === _htmlparser.ElementType.Tag && figureChildTwo?.name === 'figcaption') {
|
|
374
371
|
figcaption = figure.children[1];
|
|
375
372
|
}
|
|
376
373
|
const img = link ? link.children[0] : figure.children[0];
|
|
377
|
-
if (img?.type !==
|
|
374
|
+
if (img?.type !== _htmlparser.ElementType.Tag || img?.name !== 'img') {
|
|
378
375
|
return;
|
|
379
376
|
}
|
|
380
|
-
const figcaptionChild = figcaption?.children[0];
|
|
377
|
+
const figcaptionChild = figcaption?.type === _htmlparser.ElementType.Tag ? figcaption?.children[0] : undefined;
|
|
381
378
|
let caption;
|
|
382
|
-
if (figcaptionChild?.type ===
|
|
379
|
+
if (figcaptionChild?.type === _htmlparser.ElementType.Tag && figcaptionChild?.name === 'span' && figcaptionChild?.attribs.class === 'caption') {
|
|
383
380
|
caption = figcaptionChild;
|
|
384
381
|
}
|
|
385
|
-
const captionChildThree = figcaption?.children[2];
|
|
382
|
+
const captionChildThree = figcaption?.type === _htmlparser.ElementType.Tag ? figcaption?.children[2] : undefined;
|
|
386
383
|
let credit;
|
|
387
|
-
if (captionChildThree?.type ===
|
|
384
|
+
if (captionChildThree?.type === _htmlparser.ElementType.Tag && captionChildThree?.name === 'span' && captionChildThree?.attribs.class === 'credit') {
|
|
388
385
|
credit = captionChildThree;
|
|
389
386
|
}
|
|
390
387
|
const {
|
|
@@ -392,8 +389,8 @@ function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
|
|
|
392
389
|
size
|
|
393
390
|
} = parseFigureClass(figure.attribs.class);
|
|
394
391
|
return (0, _draftjsTemplates.getDraftjsImage)({
|
|
395
|
-
captionText: caption?.children[0].data ?? '',
|
|
396
|
-
creditText: credit?.children[0].data ?? '',
|
|
392
|
+
captionText: caption?.children[0].type === _htmlparser.ElementType.Text ? caption.children[0].data ?? '' : '',
|
|
393
|
+
creditText: credit?.children[0].type === _htmlparser.ElementType.Text ? credit?.children[0].data ?? '' : '',
|
|
397
394
|
alignment,
|
|
398
395
|
size,
|
|
399
396
|
assetId: getAssetIdFromImageSrc(img.attribs.src),
|
|
@@ -408,9 +405,9 @@ function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
|
|
|
408
405
|
}
|
|
409
406
|
function htmlDomToOembed(dom, item, entityKeyGenerator) {
|
|
410
407
|
for (const oembedDiv of dom) {
|
|
411
|
-
if (oembedDiv.type ===
|
|
408
|
+
if (oembedDiv.type === _htmlparser.ElementType.Tag && oembedDiv.name === 'div' && oembedDiv.attribs.class === 'oembed') {
|
|
412
409
|
const blockquote = oembedDiv.children[0];
|
|
413
|
-
if (blockquote?.type !==
|
|
410
|
+
if (blockquote?.type !== _htmlparser.ElementType.Tag || blockquote?.name !== 'blockquote') {
|
|
414
411
|
return;
|
|
415
412
|
}
|
|
416
413
|
const script = oembedDiv.children[2];
|
|
@@ -427,7 +424,12 @@ function htmlDomToOembed(dom, item, entityKeyGenerator) {
|
|
|
427
424
|
}
|
|
428
425
|
function mdxToDraftjsOembed(item, entityKeyGenerator) {
|
|
429
426
|
if (item.content.startsWith(`<${mdxShortcodePrefix('Oembed')}`)) {
|
|
430
|
-
const dom = (0, _htmlparser.parseDOM)(item.content
|
|
427
|
+
const dom = (0, _htmlparser.parseDOM)(item.content, {
|
|
428
|
+
decodeEntities: true
|
|
429
|
+
})[0];
|
|
430
|
+
if (dom.type !== _htmlparser.ElementType.Tag) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
431
433
|
return (0, _draftjsTemplates.getDraftjsOembed)({
|
|
432
434
|
html: (0, _unescape.default)(dom.attribs.html),
|
|
433
435
|
width: dom.attribs.width ? Number(dom.attribs.width) : undefined,
|
|
@@ -447,7 +449,7 @@ function mdxToDraftjsOembed(item, entityKeyGenerator) {
|
|
|
447
449
|
}
|
|
448
450
|
function htmlDomToPullquote(dom, item) {
|
|
449
451
|
for (const pullquote of dom) {
|
|
450
|
-
if (pullquote.type ===
|
|
452
|
+
if (pullquote.type === _htmlparser.ElementType.Tag && pullquote.name === 'aside' && pullquote.attribs.style === pullquoteStyle) {
|
|
451
453
|
const text = pullquote.children[0];
|
|
452
454
|
if (text?.type !== 'text') {
|
|
453
455
|
return;
|
|
@@ -520,7 +522,9 @@ function mdToDraftjs(mdx) {
|
|
|
520
522
|
if (item === undefined) {
|
|
521
523
|
return getDraftjsEmpty();
|
|
522
524
|
}
|
|
523
|
-
const dom = (0, _htmlparser.parseDOM)(item.content
|
|
525
|
+
const dom = (0, _htmlparser.parseDOM)(item.content, {
|
|
526
|
+
decodeEntities: false
|
|
527
|
+
});
|
|
524
528
|
const image = htmlDomToDraftjsImage(dom, item, entityKeyGenerator);
|
|
525
529
|
if (image) {
|
|
526
530
|
Object.assign(entities, image.entities);
|
|
@@ -562,7 +566,12 @@ function mdxToBr(item) {
|
|
|
562
566
|
}
|
|
563
567
|
function mdxToLinkData(item) {
|
|
564
568
|
if (item.content.startsWith('<TSExternalLink')) {
|
|
565
|
-
const dom = (0, _htmlparser.parseDOM)(item.content
|
|
569
|
+
const dom = (0, _htmlparser.parseDOM)(item.content, {
|
|
570
|
+
decodeEntities: false
|
|
571
|
+
})[0];
|
|
572
|
+
if (dom.type !== _htmlparser.ElementType.Tag) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
566
575
|
return {
|
|
567
576
|
url: dom.attribs.href,
|
|
568
577
|
target: '_blank',
|
|
@@ -572,7 +581,12 @@ function mdxToLinkData(item) {
|
|
|
572
581
|
}
|
|
573
582
|
function mdxToDraftjsImage(item, entityKeyGenerator) {
|
|
574
583
|
if (item.content.startsWith(`<${mdxShortcodePrefix('Image')}`)) {
|
|
575
|
-
const dom = (0, _htmlparser.parseDOM)(item.content
|
|
584
|
+
const dom = (0, _htmlparser.parseDOM)(item.content, {
|
|
585
|
+
decodeEntities: false
|
|
586
|
+
})[0];
|
|
587
|
+
if (dom.type !== _htmlparser.ElementType.Tag) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
576
590
|
return (0, _draftjsTemplates.getDraftjsImage)({
|
|
577
591
|
captionText: (0, _unescape.default)(dom.attribs.caption).replace(/<\/?p>/g, ''),
|
|
578
592
|
creditText: (0, _unescape.default)(dom.attribs.credit).replace(/<\/?p>/g, ''),
|
|
@@ -589,7 +603,12 @@ function mdxToDraftjsImage(item, entityKeyGenerator) {
|
|
|
589
603
|
}
|
|
590
604
|
function mdxToDraftjsPullquote(item) {
|
|
591
605
|
if (item.content.startsWith(`<${mdxShortcodePrefix('Pullquote')}`)) {
|
|
592
|
-
const dom = (0, _htmlparser.parseDOM)(item.content
|
|
606
|
+
const dom = (0, _htmlparser.parseDOM)(item.content, {
|
|
607
|
+
decodeEntities: false
|
|
608
|
+
})[0];
|
|
609
|
+
if (dom.type !== _htmlparser.ElementType.Tag) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
593
612
|
return (0, _draftjsTemplates.getDraftjsPullquote)({
|
|
594
613
|
text: (0, _unescape.default)(dom.attribs.text),
|
|
595
614
|
depth: item.level
|
package/es/draftjs.js
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { draftToMarkdown, markdownToDraft } from 'markdown-draft-js';
|
|
7
|
-
|
|
8
|
-
// @ts-expect-error Untyped
|
|
9
|
-
import { parseDOM } from 'htmlparser2';
|
|
7
|
+
import { ElementType, parseDOM } from 'htmlparser2';
|
|
10
8
|
import Url from 'url-parse';
|
|
11
9
|
import render from 'dom-serializer';
|
|
12
10
|
import shortid from 'shortid';
|
|
@@ -342,31 +340,31 @@ function parseFigureClass(className) {
|
|
|
342
340
|
// eslint-disable-next-line complexity
|
|
343
341
|
function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
|
|
344
342
|
for (const figure of dom) {
|
|
345
|
-
if (figure.type ===
|
|
343
|
+
if (figure.type === ElementType.Tag && figure.name === 'figure') {
|
|
346
344
|
let link;
|
|
347
345
|
const figureChildOne = figure.children?.[0];
|
|
348
346
|
const figureChildTwo = figure.children?.[1];
|
|
349
|
-
if (figureChildOne?.type ===
|
|
347
|
+
if (figureChildOne?.type === ElementType.Tag && figureChildOne?.name === 'a') {
|
|
350
348
|
link = figureChildOne;
|
|
351
349
|
}
|
|
352
350
|
let figcaption;
|
|
353
|
-
if (figureChildOne?.type ===
|
|
351
|
+
if (figureChildOne?.type === ElementType.Tag && figureChildOne?.name === 'figcaption') {
|
|
354
352
|
figcaption = figureChildOne;
|
|
355
|
-
} else if (figureChildTwo?.type ===
|
|
353
|
+
} else if (figureChildTwo?.type === ElementType.Tag && figureChildTwo?.name === 'figcaption') {
|
|
356
354
|
figcaption = figure.children[1];
|
|
357
355
|
}
|
|
358
356
|
const img = link ? link.children[0] : figure.children[0];
|
|
359
|
-
if (img?.type !==
|
|
357
|
+
if (img?.type !== ElementType.Tag || img?.name !== 'img') {
|
|
360
358
|
return;
|
|
361
359
|
}
|
|
362
|
-
const figcaptionChild = figcaption?.children[0];
|
|
360
|
+
const figcaptionChild = figcaption?.type === ElementType.Tag ? figcaption?.children[0] : undefined;
|
|
363
361
|
let caption;
|
|
364
|
-
if (figcaptionChild?.type ===
|
|
362
|
+
if (figcaptionChild?.type === ElementType.Tag && figcaptionChild?.name === 'span' && figcaptionChild?.attribs.class === 'caption') {
|
|
365
363
|
caption = figcaptionChild;
|
|
366
364
|
}
|
|
367
|
-
const captionChildThree = figcaption?.children[2];
|
|
365
|
+
const captionChildThree = figcaption?.type === ElementType.Tag ? figcaption?.children[2] : undefined;
|
|
368
366
|
let credit;
|
|
369
|
-
if (captionChildThree?.type ===
|
|
367
|
+
if (captionChildThree?.type === ElementType.Tag && captionChildThree?.name === 'span' && captionChildThree?.attribs.class === 'credit') {
|
|
370
368
|
credit = captionChildThree;
|
|
371
369
|
}
|
|
372
370
|
const {
|
|
@@ -374,8 +372,8 @@ function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
|
|
|
374
372
|
size
|
|
375
373
|
} = parseFigureClass(figure.attribs.class);
|
|
376
374
|
return getDraftjsImage({
|
|
377
|
-
captionText: caption?.children[0].data ?? '',
|
|
378
|
-
creditText: credit?.children[0].data ?? '',
|
|
375
|
+
captionText: caption?.children[0].type === ElementType.Text ? caption.children[0].data ?? '' : '',
|
|
376
|
+
creditText: credit?.children[0].type === ElementType.Text ? credit?.children[0].data ?? '' : '',
|
|
379
377
|
alignment,
|
|
380
378
|
size,
|
|
381
379
|
assetId: getAssetIdFromImageSrc(img.attribs.src),
|
|
@@ -390,9 +388,9 @@ function htmlDomToDraftjsImage(dom, item, entityKeyGenerator) {
|
|
|
390
388
|
}
|
|
391
389
|
function htmlDomToOembed(dom, item, entityKeyGenerator) {
|
|
392
390
|
for (const oembedDiv of dom) {
|
|
393
|
-
if (oembedDiv.type ===
|
|
391
|
+
if (oembedDiv.type === ElementType.Tag && oembedDiv.name === 'div' && oembedDiv.attribs.class === 'oembed') {
|
|
394
392
|
const blockquote = oembedDiv.children[0];
|
|
395
|
-
if (blockquote?.type !==
|
|
393
|
+
if (blockquote?.type !== ElementType.Tag || blockquote?.name !== 'blockquote') {
|
|
396
394
|
return;
|
|
397
395
|
}
|
|
398
396
|
const script = oembedDiv.children[2];
|
|
@@ -409,7 +407,12 @@ function htmlDomToOembed(dom, item, entityKeyGenerator) {
|
|
|
409
407
|
}
|
|
410
408
|
function mdxToDraftjsOembed(item, entityKeyGenerator) {
|
|
411
409
|
if (item.content.startsWith(`<${mdxShortcodePrefix('Oembed')}`)) {
|
|
412
|
-
const dom = parseDOM(item.content
|
|
410
|
+
const dom = parseDOM(item.content, {
|
|
411
|
+
decodeEntities: true
|
|
412
|
+
})[0];
|
|
413
|
+
if (dom.type !== ElementType.Tag) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
413
416
|
return getDraftjsOembed({
|
|
414
417
|
html: unescape(dom.attribs.html),
|
|
415
418
|
width: dom.attribs.width ? Number(dom.attribs.width) : undefined,
|
|
@@ -429,7 +432,7 @@ function mdxToDraftjsOembed(item, entityKeyGenerator) {
|
|
|
429
432
|
}
|
|
430
433
|
function htmlDomToPullquote(dom, item) {
|
|
431
434
|
for (const pullquote of dom) {
|
|
432
|
-
if (pullquote.type ===
|
|
435
|
+
if (pullquote.type === ElementType.Tag && pullquote.name === 'aside' && pullquote.attribs.style === pullquoteStyle) {
|
|
433
436
|
const text = pullquote.children[0];
|
|
434
437
|
if (text?.type !== 'text') {
|
|
435
438
|
return;
|
|
@@ -502,7 +505,9 @@ export function mdToDraftjs(mdx) {
|
|
|
502
505
|
if (item === undefined) {
|
|
503
506
|
return getDraftjsEmpty();
|
|
504
507
|
}
|
|
505
|
-
const dom = parseDOM(item.content
|
|
508
|
+
const dom = parseDOM(item.content, {
|
|
509
|
+
decodeEntities: false
|
|
510
|
+
});
|
|
506
511
|
const image = htmlDomToDraftjsImage(dom, item, entityKeyGenerator);
|
|
507
512
|
if (image) {
|
|
508
513
|
Object.assign(entities, image.entities);
|
|
@@ -544,7 +549,12 @@ function mdxToBr(item) {
|
|
|
544
549
|
}
|
|
545
550
|
function mdxToLinkData(item) {
|
|
546
551
|
if (item.content.startsWith('<TSExternalLink')) {
|
|
547
|
-
const dom = parseDOM(item.content
|
|
552
|
+
const dom = parseDOM(item.content, {
|
|
553
|
+
decodeEntities: false
|
|
554
|
+
})[0];
|
|
555
|
+
if (dom.type !== ElementType.Tag) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
548
558
|
return {
|
|
549
559
|
url: dom.attribs.href,
|
|
550
560
|
target: '_blank',
|
|
@@ -554,7 +564,12 @@ function mdxToLinkData(item) {
|
|
|
554
564
|
}
|
|
555
565
|
function mdxToDraftjsImage(item, entityKeyGenerator) {
|
|
556
566
|
if (item.content.startsWith(`<${mdxShortcodePrefix('Image')}`)) {
|
|
557
|
-
const dom = parseDOM(item.content
|
|
567
|
+
const dom = parseDOM(item.content, {
|
|
568
|
+
decodeEntities: false
|
|
569
|
+
})[0];
|
|
570
|
+
if (dom.type !== ElementType.Tag) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
558
573
|
return getDraftjsImage({
|
|
559
574
|
captionText: unescape(dom.attribs.caption).replace(/<\/?p>/g, ''),
|
|
560
575
|
creditText: unescape(dom.attribs.credit).replace(/<\/?p>/g, ''),
|
|
@@ -571,7 +586,12 @@ function mdxToDraftjsImage(item, entityKeyGenerator) {
|
|
|
571
586
|
}
|
|
572
587
|
function mdxToDraftjsPullquote(item) {
|
|
573
588
|
if (item.content.startsWith(`<${mdxShortcodePrefix('Pullquote')}`)) {
|
|
574
|
-
const dom = parseDOM(item.content
|
|
589
|
+
const dom = parseDOM(item.content, {
|
|
590
|
+
decodeEntities: false
|
|
591
|
+
})[0];
|
|
592
|
+
if (dom.type !== ElementType.Tag) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
575
595
|
return getDraftjsPullquote({
|
|
576
596
|
text: unescape(dom.attribs.text),
|
|
577
597
|
depth: item.level
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.28.0",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dom-serializer": "0.2.2",
|
|
26
26
|
"draft-js": "^0.11.7",
|
|
27
27
|
"he": "^1.2.0",
|
|
28
|
-
"htmlparser2": "^
|
|
28
|
+
"htmlparser2": "^9.1.0",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
30
|
"markdown-draft-js": "github:incompl/markdown-draft-js#deterministic-entity-keys-with-lib",
|
|
31
31
|
"mime-types": "^2.1.27",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"shortid": "^2.2.16",
|
|
34
34
|
"tiny-invariant": "^1.2.0",
|
|
35
35
|
"url-parse": "^1.5.3",
|
|
36
|
-
"@takeshape/routing": "11.
|
|
36
|
+
"@takeshape/routing": "11.28.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/classnames": "^2.2.9",
|