@patternfly/quickstarts 6.2.0-prerelease.4 → 6.2.0-prerelease.6

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
@@ -14,7 +14,7 @@ var server = require('react-dom/server');
14
14
  var CopyIcon = require('@patternfly/react-icons/dist/js/icons/copy-icon');
15
15
  var LightbulbIcon = require('@patternfly/react-icons/dist/js/icons/lightbulb-icon');
16
16
  var FireIcon = require('@patternfly/react-icons/dist/js/icons/fire-icon');
17
- var showdown = require('showdown');
17
+ var marked = require('marked');
18
18
  var SyncAltIcon = require('@patternfly/react-icons/dist/js/icons/sync-alt-icon');
19
19
  var CheckCircleIcon = require('@patternfly/react-icons/dist/js/icons/check-circle-icon');
20
20
  require('@patternfly/react-icons/dist/js/icons/exclamation-circle-icon');
@@ -1208,16 +1208,7 @@ const useMultilineCopyClipboardShowdownExtension = () => {
1208
1208
 
1209
1209
  // eslint-disable-next-line @typescript-eslint/no-require-imports
1210
1210
  const DOMPurify = require('dompurify');
1211
- const markdownConvert = (markdown, extensions) => {
1212
- const converter = new showdown.Converter({
1213
- tables: true,
1214
- openLinksInNewWindow: true,
1215
- strikethrough: true,
1216
- emoji: false,
1217
- });
1218
- if (extensions) {
1219
- converter.addExtension(extensions);
1220
- }
1211
+ const markdownConvert = (markdown, extensions) => tslib.__awaiter(void 0, void 0, void 0, function* () {
1221
1212
  DOMPurify.addHook('beforeSanitizeElements', function (node) {
1222
1213
  // nodeType 1 = element type
1223
1214
  var _a;
@@ -1268,16 +1259,43 @@ const markdownConvert = (markdown, extensions) => {
1268
1259
  node.setAttribute('xlink:show', 'new');
1269
1260
  }
1270
1261
  });
1271
- return DOMPurify.sanitize(converter.makeHtml(markdown), {
1272
- USE_PROFILES: {
1273
- html: true,
1274
- svg: true,
1275
- },
1276
- });
1277
- };
1262
+ const reverseString = (str) => str.split('').reverse().join('');
1263
+ // replace code fences that end in a double curly brace (which are used by our custom md extensions) with non
1264
+ // markdown formatting related tokens so that marked doesn't try to parse them as code spans
1265
+ //
1266
+ // we want to reverse the string before we do the substitution so that we only match the opening code fence which
1267
+ // corresponds to the closing code fence with the double curly brace
1268
+ const reversedMarkdown = reverseString(markdown);
1269
+ const reverseMarkdownWithSubstitutedCodeFences = reversedMarkdown.replace(/{{```((.|\n)*?)```/g, '{{@@@$1@@@');
1270
+ const markdownWithSubstitutedCodeFences = reverseString(reverseMarkdownWithSubstitutedCodeFences);
1271
+ const parsedMarkdown = yield marked.marked.parse(markdownWithSubstitutedCodeFences);
1272
+ // Swap the temporary tokens back to code fences before we run the extensions
1273
+ let md = parsedMarkdown.replace(/@@@/g, '```');
1274
+ if (extensions) {
1275
+ // Convert code spans back to md format before we run the custom extension regexes
1276
+ md = md.replace(/<code>(.*)<\/code>/g, '`$1`');
1277
+ extensions.forEach(({ regex, replace }) => {
1278
+ if (regex) {
1279
+ md = md.replace(regex, replace);
1280
+ }
1281
+ });
1282
+ // Convert any remaining backticks back into code spans
1283
+ md = md.replace(/`(.*)`/g, '<code>$1</code>');
1284
+ }
1285
+ return DOMPurify.sanitize(md);
1286
+ });
1278
1287
  const SyncMarkdownView = ({ content, emptyMsg, extensions, renderExtension, exactHeight, inline, className, }) => {
1279
1288
  const { getResource } = React__namespace.useContext(QuickStartContext);
1280
- const markup = React__namespace.useMemo(() => markdownConvert(content || emptyMsg || getResource('Not available'), extensions), [content, emptyMsg, extensions, getResource]);
1289
+ const [markup, setMarkup] = React__namespace.useState('');
1290
+ React__namespace.useEffect(() => {
1291
+ function getMd() {
1292
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1293
+ const md = yield markdownConvert(content || emptyMsg || getResource('Not available'), extensions);
1294
+ setMarkup(md);
1295
+ });
1296
+ }
1297
+ getMd();
1298
+ }, [content, emptyMsg, getResource, extensions]);
1281
1299
  const innerProps = {
1282
1300
  renderExtension: (extensions === null || extensions === void 0 ? void 0 : extensions.length) > 0 ? renderExtension : undefined,
1283
1301
  exactHeight,