@patternfly/quickstarts 2.4.2 → 2.4.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/dist/index.js CHANGED
@@ -13,7 +13,7 @@ var server = require('react-dom/server');
13
13
  var CopyIcon = require('@patternfly/react-icons/dist/js/icons/copy-icon');
14
14
  var LightbulbIcon = require('@patternfly/react-icons/dist/js/icons/lightbulb-icon');
15
15
  var FireIcon = require('@patternfly/react-icons/dist/js/icons/fire-icon');
16
- var showdown = require('showdown');
16
+ var marked = require('marked');
17
17
  var SyncAltIcon = require('@patternfly/react-icons/dist/js/icons/sync-alt-icon');
18
18
  var CheckCircleIcon = require('@patternfly/react-icons/dist/js/icons/check-circle-icon');
19
19
  var ExclamationCircleIcon = require('@patternfly/react-icons/dist/js/icons/exclamation-circle-icon');
@@ -1329,16 +1329,7 @@ const useMultilineCopyClipboardShowdownExtension = () => {
1329
1329
 
1330
1330
  // eslint-disable-next-line @typescript-eslint/no-require-imports
1331
1331
  const DOMPurify = require('dompurify');
1332
- const markdownConvert = (markdown, extensions) => {
1333
- const converter = new showdown.Converter({
1334
- tables: true,
1335
- openLinksInNewWindow: true,
1336
- strikethrough: true,
1337
- emoji: false,
1338
- });
1339
- if (extensions) {
1340
- converter.addExtension(extensions);
1341
- }
1332
+ const markdownConvert = (markdown, extensions) => tslib.__awaiter(void 0, void 0, void 0, function* () {
1342
1333
  DOMPurify.addHook('beforeSanitizeElements', function (node) {
1343
1334
  // nodeType 1 = element type
1344
1335
  // transform anchor tags
@@ -1365,20 +1356,38 @@ const markdownConvert = (markdown, extensions) => {
1365
1356
  node.setAttribute('xlink:show', 'new');
1366
1357
  }
1367
1358
  });
1368
- return DOMPurify.sanitize(converter.makeHtml(markdown), {
1369
- USE_PROFILES: {
1370
- html: true,
1371
- svg: true,
1372
- },
1373
- });
1374
- };
1359
+ // Replace code fences with non markdown formatting relates tokens so that marked doesn't try to parse them as code spans
1360
+ const markdownWithSubstitutedCodeFences = markdown.replace(/```/g, '@@@');
1361
+ const parsedMarkdown = yield marked.marked.parse(markdownWithSubstitutedCodeFences);
1362
+ // Swap the temporary tokens back to code fences before we run the extensions
1363
+ let md = parsedMarkdown.replace(/@@@/g, '```');
1364
+ if (extensions) {
1365
+ // Convert code spans back to md format before we run the custom extension regexes
1366
+ md = md.replace(/<code>(.*)<\/code>/g, '`$1`');
1367
+ extensions.forEach(({ regex, replace }) => {
1368
+ if (regex) {
1369
+ md = md.replace(regex, replace);
1370
+ }
1371
+ });
1372
+ // Convert any remaining backticks back into code spans
1373
+ md = md.replace(/`(.*)`/g, '<code>$1</code>');
1374
+ }
1375
+ return DOMPurify.sanitize(md);
1376
+ });
1375
1377
  const SyncMarkdownView = ({
1376
1378
  // truncateContent,
1377
1379
  content, emptyMsg, extensions, renderExtension, exactHeight, inline, className, }) => {
1378
1380
  const { getResource } = React__namespace.useContext(QuickStartContext);
1379
- const markup = React__namespace.useMemo(() => {
1380
- return markdownConvert(content || emptyMsg || getResource('Not available'), extensions);
1381
- }, [content, emptyMsg, extensions, getResource]);
1381
+ const [markup, setMarkup] = React__namespace.useState('');
1382
+ React__namespace.useEffect(() => {
1383
+ function getMd() {
1384
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1385
+ const md = yield markdownConvert(content || emptyMsg || getResource('Not available'), extensions);
1386
+ setMarkup(md);
1387
+ });
1388
+ }
1389
+ getMd();
1390
+ }, [content, emptyMsg, getResource, extensions]);
1382
1391
  const innerProps = {
1383
1392
  renderExtension: (extensions === null || extensions === void 0 ? void 0 : extensions.length) > 0 ? renderExtension : undefined,
1384
1393
  exactHeight,
@@ -2045,12 +2054,22 @@ const TaskIcon = ({ taskIndex, taskStatus }) => {
2045
2054
  };
2046
2055
  const QuickStartTaskHeader = ({ title, taskIndex, subtitle, taskStatus, size, isActiveTask, onTaskSelect, children, }) => {
2047
2056
  const titleRef = React__namespace.useRef(null);
2057
+ const [parsedTitle, setParsedTitle] = React__namespace.useState('');
2048
2058
  React__namespace.useEffect(() => {
2049
2059
  if (isActiveTask) {
2050
2060
  // Focus the WizardNavItem button element that contains the title
2051
2061
  titleRef.current.parentNode.focus();
2052
2062
  }
2053
2063
  }, [isActiveTask]);
2064
+ React__namespace.useEffect(() => {
2065
+ function getParsedTitle() {
2066
+ return tslib.__awaiter(this, void 0, void 0, function* () {
2067
+ const convertedMdTitle = yield markdownConvert(title);
2068
+ setParsedTitle(removeParagraphWrap(convertedMdTitle));
2069
+ });
2070
+ }
2071
+ getParsedTitle();
2072
+ }, [title]);
2054
2073
  const classNames = reactStyles.css('pfext-quick-start-task-header__title', {
2055
2074
  'pfext-quick-start-task-header__title-success': taskStatus === exports.QuickStartTaskStatus.SUCCESS,
2056
2075
  'pfext-quick-start-task-header__title-failed': taskStatus === (exports.QuickStartTaskStatus.FAILED || exports.QuickStartTaskStatus.VISITED),
@@ -2066,7 +2085,7 @@ const QuickStartTaskHeader = ({ title, taskIndex, subtitle, taskStatus, size, is
2066
2085
  const content = (React__namespace.createElement("div", { className: "pfext-quick-start-task-header", ref: titleRef },
2067
2086
  React__namespace.createElement(TaskIcon, { taskIndex: taskIndex, taskStatus: taskStatus }),
2068
2087
  React__namespace.createElement(reactCore.Title, { headingLevel: "h3", size: size, className: classNames },
2069
- React__namespace.createElement("span", { dangerouslySetInnerHTML: { __html: removeParagraphWrap(markdownConvert(title)) } }),
2088
+ React__namespace.createElement("span", { dangerouslySetInnerHTML: { __html: parsedTitle } }),
2070
2089
  isActiveTask && subtitle && (React__namespace.createElement("span", { className: "pfext-quick-start-task-header__subtitle", "data-test-id": "quick-start-task-subtitle" },
2071
2090
  ' ',
2072
2091
  subtitle))),
@@ -2273,6 +2292,7 @@ const QuickStartPanelContent = (_a) => {
2273
2292
  const titleRef = React__namespace.useRef(null);
2274
2293
  const { getResource, activeQuickStartState } = React__namespace.useContext(QuickStartContext);
2275
2294
  const [contentRef, setContentRef] = React__namespace.useState();
2295
+ const [displayName, setDisplayName] = React__namespace.useState('');
2276
2296
  const shadows = useScrollShadows(contentRef);
2277
2297
  const quickStart = quickStarts.find((qs) => qs.metadata.name === activeQuickStartID);
2278
2298
  const taskNumber = activeQuickStartState === null || activeQuickStartState === void 0 ? void 0 : activeQuickStartState.taskNumber;
@@ -2300,13 +2320,22 @@ const QuickStartPanelContent = (_a) => {
2300
2320
  titleRef.current.focus();
2301
2321
  }
2302
2322
  }, [quickStart]);
2323
+ React__namespace.useEffect(() => {
2324
+ function getDisplayName() {
2325
+ return tslib.__awaiter(this, void 0, void 0, function* () {
2326
+ const convertedMdDisplayName = yield markdownConvert(quickStart === null || quickStart === void 0 ? void 0 : quickStart.spec.displayName);
2327
+ setDisplayName(removeParagraphWrap(convertedMdDisplayName));
2328
+ });
2329
+ }
2330
+ getDisplayName();
2331
+ }, [quickStart]);
2303
2332
  const content = quickStart ? (React__namespace.createElement(reactCore.DrawerPanelContent, Object.assign({ isResizable: isResizable, className: "pfext-quick-start__base", "data-testid": `qs-drawer-${camelize(quickStart.spec.displayName)}`, "data-qs": `qs-step-${getStep()}`, "data-test": "quickstart drawer" }, props),
2304
2333
  React__namespace.createElement("div", { className: headerClasses },
2305
2334
  React__namespace.createElement(reactCore.DrawerHead, null,
2306
2335
  React__namespace.createElement("div", { className: "pfext-quick-start-panel-content__title", tabIndex: -1, ref: titleRef },
2307
2336
  React__namespace.createElement(reactCore.Title, { headingLevel: "h2", size: "xl", className: "pfext-quick-start-panel-content__name", style: { marginRight: 'var(--pf-global--spacer--md)' } },
2308
2337
  React__namespace.createElement("span", { dangerouslySetInnerHTML: {
2309
- __html: removeParagraphWrap(markdownConvert(quickStart === null || quickStart === void 0 ? void 0 : quickStart.spec.displayName)),
2338
+ __html: displayName,
2310
2339
  } }),
2311
2340
  ' ',
2312
2341
  React__namespace.createElement("small", { className: "pfext-quick-start-panel-content__duration" }, (quickStart === null || quickStart === void 0 ? void 0 : quickStart.spec.durationMinutes) ? getResource('{{type}} • {{duration, number}} minutes', quickStart === null || quickStart === void 0 ? void 0 : quickStart.spec.durationMinutes)