@patternfly/quickstarts 2.4.3 → 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.
@@ -5,7 +5,7 @@ declare type ShowdownExtension = {
5
5
  regex?: RegExp;
6
6
  replace?: (...args: any[]) => string;
7
7
  };
8
- export declare const markdownConvert: (markdown: any, extensions?: ShowdownExtension[]) => any;
8
+ export declare const markdownConvert: (markdown: string, extensions?: ShowdownExtension[]) => Promise<any>;
9
9
  declare type SyncMarkdownProps = {
10
10
  content?: string;
11
11
  emptyMsg?: string;
package/dist/index.es.js CHANGED
@@ -4,13 +4,13 @@ import { Card, CardHeader, CardActions, CardTitle, CardBody, CardFooter, Modal a
4
4
  import SearchIcon from '@patternfly/react-icons/dist/js/icons/search-icon';
5
5
  import { css } from '@patternfly/react-styles';
6
6
  import RocketIcon from '@patternfly/react-icons/dist/js/icons/rocket-icon';
7
- import { __rest } from 'tslib';
7
+ import { __rest, __awaiter } from 'tslib';
8
8
  import * as ReactDOM from 'react-dom';
9
9
  import { renderToStaticMarkup } from 'react-dom/server';
10
10
  import CopyIcon from '@patternfly/react-icons/dist/js/icons/copy-icon';
11
11
  import LightbulbIcon from '@patternfly/react-icons/dist/js/icons/lightbulb-icon';
12
12
  import FireIcon from '@patternfly/react-icons/dist/js/icons/fire-icon';
13
- import { Converter } from 'showdown';
13
+ import { marked } from 'marked';
14
14
  import SyncAltIcon from '@patternfly/react-icons/dist/js/icons/sync-alt-icon';
15
15
  import CheckCircleIcon from '@patternfly/react-icons/dist/js/icons/check-circle-icon';
16
16
  import ExclamationCircleIcon from '@patternfly/react-icons/dist/js/icons/exclamation-circle-icon';
@@ -1287,16 +1287,7 @@ const useMultilineCopyClipboardShowdownExtension = () => {
1287
1287
 
1288
1288
  // eslint-disable-next-line @typescript-eslint/no-require-imports
1289
1289
  const DOMPurify = require('dompurify');
1290
- const markdownConvert = (markdown, extensions) => {
1291
- const converter = new Converter({
1292
- tables: true,
1293
- openLinksInNewWindow: true,
1294
- strikethrough: true,
1295
- emoji: false,
1296
- });
1297
- if (extensions) {
1298
- converter.addExtension(extensions);
1299
- }
1290
+ const markdownConvert = (markdown, extensions) => __awaiter(void 0, void 0, void 0, function* () {
1300
1291
  DOMPurify.addHook('beforeSanitizeElements', function (node) {
1301
1292
  // nodeType 1 = element type
1302
1293
  // transform anchor tags
@@ -1323,20 +1314,38 @@ const markdownConvert = (markdown, extensions) => {
1323
1314
  node.setAttribute('xlink:show', 'new');
1324
1315
  }
1325
1316
  });
1326
- return DOMPurify.sanitize(converter.makeHtml(markdown), {
1327
- USE_PROFILES: {
1328
- html: true,
1329
- svg: true,
1330
- },
1331
- });
1332
- };
1317
+ // Replace code fences with non markdown formatting relates tokens so that marked doesn't try to parse them as code spans
1318
+ const markdownWithSubstitutedCodeFences = markdown.replace(/```/g, '@@@');
1319
+ const parsedMarkdown = yield marked.parse(markdownWithSubstitutedCodeFences);
1320
+ // Swap the temporary tokens back to code fences before we run the extensions
1321
+ let md = parsedMarkdown.replace(/@@@/g, '```');
1322
+ if (extensions) {
1323
+ // Convert code spans back to md format before we run the custom extension regexes
1324
+ md = md.replace(/<code>(.*)<\/code>/g, '`$1`');
1325
+ extensions.forEach(({ regex, replace }) => {
1326
+ if (regex) {
1327
+ md = md.replace(regex, replace);
1328
+ }
1329
+ });
1330
+ // Convert any remaining backticks back into code spans
1331
+ md = md.replace(/`(.*)`/g, '<code>$1</code>');
1332
+ }
1333
+ return DOMPurify.sanitize(md);
1334
+ });
1333
1335
  const SyncMarkdownView = ({
1334
1336
  // truncateContent,
1335
1337
  content, emptyMsg, extensions, renderExtension, exactHeight, inline, className, }) => {
1336
1338
  const { getResource } = React.useContext(QuickStartContext);
1337
- const markup = React.useMemo(() => {
1338
- return markdownConvert(content || emptyMsg || getResource('Not available'), extensions);
1339
- }, [content, emptyMsg, extensions, getResource]);
1339
+ const [markup, setMarkup] = React.useState('');
1340
+ React.useEffect(() => {
1341
+ function getMd() {
1342
+ return __awaiter(this, void 0, void 0, function* () {
1343
+ const md = yield markdownConvert(content || emptyMsg || getResource('Not available'), extensions);
1344
+ setMarkup(md);
1345
+ });
1346
+ }
1347
+ getMd();
1348
+ }, [content, emptyMsg, getResource, extensions]);
1340
1349
  const innerProps = {
1341
1350
  renderExtension: (extensions === null || extensions === void 0 ? void 0 : extensions.length) > 0 ? renderExtension : undefined,
1342
1351
  exactHeight,
@@ -2003,12 +2012,22 @@ const TaskIcon = ({ taskIndex, taskStatus }) => {
2003
2012
  };
2004
2013
  const QuickStartTaskHeader = ({ title, taskIndex, subtitle, taskStatus, size, isActiveTask, onTaskSelect, children, }) => {
2005
2014
  const titleRef = React.useRef(null);
2015
+ const [parsedTitle, setParsedTitle] = React.useState('');
2006
2016
  React.useEffect(() => {
2007
2017
  if (isActiveTask) {
2008
2018
  // Focus the WizardNavItem button element that contains the title
2009
2019
  titleRef.current.parentNode.focus();
2010
2020
  }
2011
2021
  }, [isActiveTask]);
2022
+ React.useEffect(() => {
2023
+ function getParsedTitle() {
2024
+ return __awaiter(this, void 0, void 0, function* () {
2025
+ const convertedMdTitle = yield markdownConvert(title);
2026
+ setParsedTitle(removeParagraphWrap(convertedMdTitle));
2027
+ });
2028
+ }
2029
+ getParsedTitle();
2030
+ }, [title]);
2012
2031
  const classNames = css('pfext-quick-start-task-header__title', {
2013
2032
  'pfext-quick-start-task-header__title-success': taskStatus === QuickStartTaskStatus.SUCCESS,
2014
2033
  'pfext-quick-start-task-header__title-failed': taskStatus === (QuickStartTaskStatus.FAILED || QuickStartTaskStatus.VISITED),
@@ -2024,7 +2043,7 @@ const QuickStartTaskHeader = ({ title, taskIndex, subtitle, taskStatus, size, is
2024
2043
  const content = (React.createElement("div", { className: "pfext-quick-start-task-header", ref: titleRef },
2025
2044
  React.createElement(TaskIcon, { taskIndex: taskIndex, taskStatus: taskStatus }),
2026
2045
  React.createElement(Title, { headingLevel: "h3", size: size, className: classNames },
2027
- React.createElement("span", { dangerouslySetInnerHTML: { __html: removeParagraphWrap(markdownConvert(title)) } }),
2046
+ React.createElement("span", { dangerouslySetInnerHTML: { __html: parsedTitle } }),
2028
2047
  isActiveTask && subtitle && (React.createElement("span", { className: "pfext-quick-start-task-header__subtitle", "data-test-id": "quick-start-task-subtitle" },
2029
2048
  ' ',
2030
2049
  subtitle))),
@@ -2231,6 +2250,7 @@ const QuickStartPanelContent = (_a) => {
2231
2250
  const titleRef = React.useRef(null);
2232
2251
  const { getResource, activeQuickStartState } = React.useContext(QuickStartContext);
2233
2252
  const [contentRef, setContentRef] = React.useState();
2253
+ const [displayName, setDisplayName] = React.useState('');
2234
2254
  const shadows = useScrollShadows(contentRef);
2235
2255
  const quickStart = quickStarts.find((qs) => qs.metadata.name === activeQuickStartID);
2236
2256
  const taskNumber = activeQuickStartState === null || activeQuickStartState === void 0 ? void 0 : activeQuickStartState.taskNumber;
@@ -2258,13 +2278,22 @@ const QuickStartPanelContent = (_a) => {
2258
2278
  titleRef.current.focus();
2259
2279
  }
2260
2280
  }, [quickStart]);
2281
+ React.useEffect(() => {
2282
+ function getDisplayName() {
2283
+ return __awaiter(this, void 0, void 0, function* () {
2284
+ const convertedMdDisplayName = yield markdownConvert(quickStart === null || quickStart === void 0 ? void 0 : quickStart.spec.displayName);
2285
+ setDisplayName(removeParagraphWrap(convertedMdDisplayName));
2286
+ });
2287
+ }
2288
+ getDisplayName();
2289
+ }, [quickStart]);
2261
2290
  const content = quickStart ? (React.createElement(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),
2262
2291
  React.createElement("div", { className: headerClasses },
2263
2292
  React.createElement(DrawerHead, null,
2264
2293
  React.createElement("div", { className: "pfext-quick-start-panel-content__title", tabIndex: -1, ref: titleRef },
2265
2294
  React.createElement(Title, { headingLevel: "h2", size: "xl", className: "pfext-quick-start-panel-content__name", style: { marginRight: 'var(--pf-global--spacer--md)' } },
2266
2295
  React.createElement("span", { dangerouslySetInnerHTML: {
2267
- __html: removeParagraphWrap(markdownConvert(quickStart === null || quickStart === void 0 ? void 0 : quickStart.spec.displayName)),
2296
+ __html: displayName,
2268
2297
  } }),
2269
2298
  ' ',
2270
2299
  React.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)