Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: patternfly/patternfly-quickstarts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.2
Choose a base ref
...
head repository: patternfly/patternfly-quickstarts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.3
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Feb 27, 2025

  1. fix(markdown): fix plain code fences not being transformed (#374)

    wise-king-sullyman authored Feb 27, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    e5529e0 View commit details
Showing with 14 additions and 2 deletions.
  1. +14 −2 packages/module/src/ConsoleInternal/components/markdown-view.tsx
16 changes: 14 additions & 2 deletions packages/module/src/ConsoleInternal/components/markdown-view.tsx
Original file line number Diff line number Diff line change
@@ -51,8 +51,20 @@ export const markdownConvert = async (markdown: string, extensions?: ShowdownExt
}
});

// Replace code fences with non markdown formatting relates tokens so that marked doesn't try to parse them as code spans
const markdownWithSubstitutedCodeFences = markdown.replace(/```/g, '@@@');
const reverseString = (str: string) => str.split('').reverse().join('');

// replace code fences that end in a double curly brace (which are used by our custom md extensions) with non
// markdown formatting related tokens so that marked doesn't try to parse them as code spans
//
// we want to reverse the string before we do the substitution so that we only match the opening code fence which
// corresponds to the closing code fence with the double curly brace
const reversedMarkdown = reverseString(markdown);
const reverseMarkdownWithSubstitutedCodeFences = reversedMarkdown.replace(
/{{```((.|\n)*?)```/g,
'{{@@@$1@@@',
);
const markdownWithSubstitutedCodeFences = reverseString(reverseMarkdownWithSubstitutedCodeFences);

const parsedMarkdown = await marked.parse(markdownWithSubstitutedCodeFences);
// Swap the temporary tokens back to code fences before we run the extensions
let md = parsedMarkdown.replace(/@@@/g, '```');