@readme/markdown 6.75.0-beta.64 → 6.75.0-beta.66

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.
@@ -16,7 +16,7 @@ interface ImageProps {
16
16
 
17
17
  const Image = (Props: ImageProps) => {
18
18
  const {
19
- align = '',
19
+ align = 'center',
20
20
  alt = '',
21
21
  border = false,
22
22
  caption,
@@ -25,7 +25,7 @@ const Image = (Props: ImageProps) => {
25
25
  src,
26
26
  title = '',
27
27
  width = 'auto',
28
- lazy = false,
28
+ lazy = true,
29
29
  children,
30
30
  } = Props;
31
31
 
@@ -60,55 +60,53 @@ const Image = (Props: ImageProps) => {
60
60
 
61
61
  if (caption) {
62
62
  return (
63
- <span
64
- aria-label={alt}
65
- className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
66
- onClick={toggle}
67
- onKeyDown={handleKeyDown}
68
- role={'button'}
69
- tabIndex={0}
70
- >
71
- <span className="lightbox-inner">
72
- <figure>
63
+ <figure>
64
+ <span
65
+ aria-label={alt}
66
+ className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
67
+ onClick={toggle}
68
+ onKeyDown={handleKeyDown}
69
+ role={'button'}
70
+ tabIndex={0}
71
+ >
72
+ <span className="lightbox-inner">
73
73
  <img
74
74
  src={src}
75
75
  width={width}
76
76
  height={height}
77
77
  title={title}
78
- className={`img img-align-center ${border ? 'border' : ''}`}
78
+ className={`img img-align-center${border ? ' border' : ''}`}
79
79
  alt={alt}
80
80
  loading={lazy ? 'lazy' : 'eager'}
81
81
  />
82
82
  <figcaption>{children || caption}</figcaption>
83
- </figure>
83
+ </span>
84
84
  </span>
85
- </span>
85
+ </figure>
86
86
  );
87
87
  }
88
88
 
89
89
  return (
90
- <p>
91
- <span
92
- aria-label={alt}
93
- className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
94
- onClick={toggle}
95
- onKeyDown={handleKeyDown}
96
- role={'button'}
97
- tabIndex={0}
98
- >
99
- <span className="lightbox-inner">
100
- <img
101
- src={src}
102
- width={width}
103
- height={height}
104
- title={title}
105
- className={`img img-align-${align} ${border ? 'border' : ''}`}
106
- alt={alt}
107
- loading={lazy ? 'lazy' : 'eager'}
108
- />
109
- </span>
90
+ <span
91
+ aria-label={alt}
92
+ className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
93
+ onClick={toggle}
94
+ onKeyDown={handleKeyDown}
95
+ role={'button'}
96
+ tabIndex={0}
97
+ >
98
+ <span className="lightbox-inner">
99
+ <img
100
+ src={src}
101
+ width={width}
102
+ height={height}
103
+ title={title}
104
+ className={`img img-align-${align}${border ? ' border' : ''}`}
105
+ alt={alt}
106
+ loading={lazy ? 'lazy' : 'eager'}
107
+ />
110
108
  </span>
111
- </p>
109
+ </span>
112
110
  );
113
111
  };
114
112
 
package/dist/main.js CHANGED
@@ -14444,7 +14444,7 @@ const CreateHeading = (depth) => (props) => external_amd_react_commonjs_react_co
14444
14444
  ;// CONCATENATED MODULE: ./components/Image/index.tsx
14445
14445
 
14446
14446
  const Image = (Props) => {
14447
- const { align = '', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = false, children, } = Props;
14447
+ const { align = 'center', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = true, children, } = Props;
14448
14448
  const [lightbox, setLightbox] = external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useState(false);
14449
14449
  if (className === 'emoji') {
14450
14450
  return external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, alt: alt, loading: lazy ? 'lazy' : 'eager' });
@@ -14472,16 +14472,15 @@ const Image = (Props) => {
14472
14472
  setLightbox(!lightbox);
14473
14473
  };
14474
14474
  if (caption) {
14475
- return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14476
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14477
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figure", null,
14478
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-center ${border ? 'border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }),
14475
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figure", null,
14476
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14477
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14478
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-center${border ? ' border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }),
14479
14479
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figcaption", null, children || caption)))));
14480
14480
  }
14481
- return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("p", null,
14482
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14483
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14484
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-${align} ${border ? 'border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' })))));
14481
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14482
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14483
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-${align}${border ? ' border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }))));
14485
14484
  };
14486
14485
  /* harmony default export */ const components_Image = (Image);
14487
14486
 
@@ -48562,8 +48561,17 @@ const embedTransformer = () => {
48562
48561
  */
48563
48562
  const formatHProps = (node) => {
48564
48563
  const hProps = getHProps(node);
48565
- const hPropKeys = getHPropKeys(node);
48566
- return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
48564
+ return formatProps(hProps);
48565
+ };
48566
+ /**
48567
+ * Formats an object of props as a string.
48568
+ *
48569
+ * @param {Object} props
48570
+ * @returns {string}
48571
+ */
48572
+ const formatProps = (props) => {
48573
+ const keys = Object.keys(props);
48574
+ return keys.map(key => `${key}="${props[key]}"`).join(' ');
48567
48575
  };
48568
48576
  /**
48569
48577
  * Returns the hProperties of a node.
@@ -94389,6 +94397,19 @@ function toXml(tree, options) {
94389
94397
  }
94390
94398
 
94391
94399
  ;// CONCATENATED MODULE: ./processor/compile/compatibility.ts
94400
+ var compatibility_rest = (undefined && undefined.__rest) || function (s, e) {
94401
+ var t = {};
94402
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
94403
+ t[p] = s[p];
94404
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
94405
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
94406
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
94407
+ t[p[i]] = s[p[i]];
94408
+ }
94409
+ return t;
94410
+ };
94411
+
94412
+
94392
94413
 
94393
94414
 
94394
94415
 
@@ -94407,6 +94428,24 @@ const compatibility_html = (node) => {
94407
94428
  const xml = toXml(xast, { closeEmptyElements: true });
94408
94429
  return xml.replace(/<html.*<body>(.*)<\/body><\/html>/ms, '$1');
94409
94430
  };
94431
+ const figureToImageBlock = (node) => {
94432
+ const _a = node.children.find((child) => child.type === 'image'), { align, width, src, url, alt, title } = _a, image = compatibility_rest(_a, ["align", "width", "src", "url", "alt", "title"]);
94433
+ const { className } = image.data.hProperties;
94434
+ const figcaption = node.children.find((child) => child.type === 'figcaption');
94435
+ const caption = figcaption
94436
+ ? toMarkdown({
94437
+ type: 'paragraph',
94438
+ children: figcaption.children,
94439
+ }).trim()
94440
+ : null;
94441
+ const attributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (align && { align })), (alt && { alt })), (className && { border: className === 'border' })), (caption && { caption })), (title && { title })), (width && { width })), { src: src || url });
94442
+ return `<Image ${formatProps(attributes)} />`;
94443
+ };
94444
+ const embedToEmbedBlock = (node) => {
94445
+ const _a = node.data.hProperties, { html } = _a, embed = compatibility_rest(_a, ["html"]);
94446
+ const attributes = Object.assign(Object.assign({}, embed), (html && { html: encodeURIComponent(html) }));
94447
+ return `<Embed ${formatProps(attributes)} />`;
94448
+ };
94410
94449
  const compatibility = (node) => {
94411
94450
  var _a, _b;
94412
94451
  switch (node.type) {
@@ -94420,6 +94459,10 @@ const compatibility = (node) => {
94420
94459
  return compatibility_html(node);
94421
94460
  case 'escape':
94422
94461
  return `\\${node.value}`;
94462
+ case 'figure':
94463
+ return figureToImageBlock(node);
94464
+ case 'embed':
94465
+ return embedToEmbedBlock(node);
94423
94466
  default:
94424
94467
  throw new Error('Unhandled node type!');
94425
94468
  }
@@ -94453,7 +94496,9 @@ function compilers() {
94453
94496
  [NodeTypes.imageBlock]: compile_image,
94454
94497
  [NodeTypes.reusableContent]: compile_compatibility,
94455
94498
  [NodeTypes.variable]: compile_variable,
94499
+ embed: compile_compatibility,
94456
94500
  escape: compile_compatibility,
94501
+ figure: compile_compatibility,
94457
94502
  html: compile_compatibility,
94458
94503
  };
94459
94504
  toMarkdownExtensions.push({ extensions: [{ handlers }] });
package/dist/main.node.js CHANGED
@@ -14334,7 +14334,7 @@ const CreateHeading = (depth) => (props) => external_amd_react_commonjs_react_co
14334
14334
  ;// CONCATENATED MODULE: ./components/Image/index.tsx
14335
14335
 
14336
14336
  const Image = (Props) => {
14337
- const { align = '', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = false, children, } = Props;
14337
+ const { align = 'center', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = true, children, } = Props;
14338
14338
  const [lightbox, setLightbox] = external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useState(false);
14339
14339
  if (className === 'emoji') {
14340
14340
  return external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, alt: alt, loading: lazy ? 'lazy' : 'eager' });
@@ -14362,16 +14362,15 @@ const Image = (Props) => {
14362
14362
  setLightbox(!lightbox);
14363
14363
  };
14364
14364
  if (caption) {
14365
- return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14366
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14367
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figure", null,
14368
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-center ${border ? 'border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }),
14365
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figure", null,
14366
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14367
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14368
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-center${border ? ' border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }),
14369
14369
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figcaption", null, children || caption)))));
14370
14370
  }
14371
- return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("p", null,
14372
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14373
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14374
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-${align} ${border ? 'border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' })))));
14371
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
14372
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14373
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-${align}${border ? ' border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }))));
14375
14374
  };
14376
14375
  /* harmony default export */ const components_Image = (Image);
14377
14376
 
@@ -50015,8 +50014,17 @@ const embedTransformer = () => {
50015
50014
  */
50016
50015
  const formatHProps = (node) => {
50017
50016
  const hProps = getHProps(node);
50018
- const hPropKeys = getHPropKeys(node);
50019
- return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
50017
+ return formatProps(hProps);
50018
+ };
50019
+ /**
50020
+ * Formats an object of props as a string.
50021
+ *
50022
+ * @param {Object} props
50023
+ * @returns {string}
50024
+ */
50025
+ const formatProps = (props) => {
50026
+ const keys = Object.keys(props);
50027
+ return keys.map(key => `${key}="${props[key]}"`).join(' ');
50020
50028
  };
50021
50029
  /**
50022
50030
  * Returns the hProperties of a node.
@@ -95842,6 +95850,19 @@ function toXml(tree, options) {
95842
95850
  }
95843
95851
 
95844
95852
  ;// CONCATENATED MODULE: ./processor/compile/compatibility.ts
95853
+ var compatibility_rest = (undefined && undefined.__rest) || function (s, e) {
95854
+ var t = {};
95855
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
95856
+ t[p] = s[p];
95857
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
95858
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
95859
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
95860
+ t[p[i]] = s[p[i]];
95861
+ }
95862
+ return t;
95863
+ };
95864
+
95865
+
95845
95866
 
95846
95867
 
95847
95868
 
@@ -95860,6 +95881,24 @@ const compatibility_html = (node) => {
95860
95881
  const xml = toXml(xast, { closeEmptyElements: true });
95861
95882
  return xml.replace(/<html.*<body>(.*)<\/body><\/html>/ms, '$1');
95862
95883
  };
95884
+ const figureToImageBlock = (node) => {
95885
+ const _a = node.children.find((child) => child.type === 'image'), { align, width, src, url, alt, title } = _a, image = compatibility_rest(_a, ["align", "width", "src", "url", "alt", "title"]);
95886
+ const { className } = image.data.hProperties;
95887
+ const figcaption = node.children.find((child) => child.type === 'figcaption');
95888
+ const caption = figcaption
95889
+ ? toMarkdown({
95890
+ type: 'paragraph',
95891
+ children: figcaption.children,
95892
+ }).trim()
95893
+ : null;
95894
+ const attributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (align && { align })), (alt && { alt })), (className && { border: className === 'border' })), (caption && { caption })), (title && { title })), (width && { width })), { src: src || url });
95895
+ return `<Image ${formatProps(attributes)} />`;
95896
+ };
95897
+ const embedToEmbedBlock = (node) => {
95898
+ const _a = node.data.hProperties, { html } = _a, embed = compatibility_rest(_a, ["html"]);
95899
+ const attributes = Object.assign(Object.assign({}, embed), (html && { html: encodeURIComponent(html) }));
95900
+ return `<Embed ${formatProps(attributes)} />`;
95901
+ };
95863
95902
  const compatibility = (node) => {
95864
95903
  var _a, _b;
95865
95904
  switch (node.type) {
@@ -95873,6 +95912,10 @@ const compatibility = (node) => {
95873
95912
  return compatibility_html(node);
95874
95913
  case 'escape':
95875
95914
  return `\\${node.value}`;
95915
+ case 'figure':
95916
+ return figureToImageBlock(node);
95917
+ case 'embed':
95918
+ return embedToEmbedBlock(node);
95876
95919
  default:
95877
95920
  throw new Error('Unhandled node type!');
95878
95921
  }
@@ -95906,7 +95949,9 @@ function compilers() {
95906
95949
  [NodeTypes.imageBlock]: compile_image,
95907
95950
  [NodeTypes.reusableContent]: compile_compatibility,
95908
95951
  [NodeTypes.variable]: compile_variable,
95952
+ embed: compile_compatibility,
95909
95953
  escape: compile_compatibility,
95954
+ figure: compile_compatibility,
95910
95955
  html: compile_compatibility,
95911
95956
  };
95912
95957
  toMarkdownExtensions.push({ extensions: [{ handlers }] });
@@ -1,4 +1,4 @@
1
- import { Html } from 'mdast';
1
+ import { Html, Image } from 'mdast';
2
2
  import { NodeTypes } from '../../enums';
3
3
  type CompatNodes = {
4
4
  type: NodeTypes.glossary;
@@ -19,9 +19,25 @@ type CompatNodes = {
19
19
  } | {
20
20
  type: NodeTypes.reusableContent;
21
21
  tag: string;
22
+ } | {
23
+ type: 'embed';
24
+ data: {
25
+ hProperties: {
26
+ [key: string]: string;
27
+ };
28
+ };
22
29
  } | {
23
30
  type: 'escape';
24
31
  value: string;
32
+ } | {
33
+ type: 'figure';
34
+ children: [Image, {
35
+ type: 'figcaption';
36
+ children: [{
37
+ type: 'text';
38
+ value: string;
39
+ }];
40
+ }];
25
41
  } | Html;
26
42
  declare const compatibility: (node: CompatNodes) => string;
27
43
  export default compatibility;
@@ -10,6 +10,13 @@ import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
10
10
  * @returns {string} formatted hProperties as JSX attributes
11
11
  */
12
12
  export declare const formatHProps: <T>(node: Node) => string;
13
+ /**
14
+ * Formats an object of props as a string.
15
+ *
16
+ * @param {Object} props
17
+ * @returns {string}
18
+ */
19
+ export declare const formatProps: (props: Object) => string;
13
20
  /**
14
21
  * Returns the hProperties of a node.
15
22
  *
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@readme/markdown",
3
3
  "description": "ReadMe's React-based Markdown parser",
4
4
  "author": "Rafe Goldberg <rafe@readme.io>",
5
- "version": "6.75.0-beta.64",
5
+ "version": "6.75.0-beta.66",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",