diff --git a/gradle/changelog/remark-text-adapter.yaml b/gradle/changelog/remark-text-adapter.yaml new file mode 100644 index 0000000000..7e1d5fd493 --- /dev/null +++ b/gradle/changelog/remark-text-adapter.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Make MarkdownView backwards-compatible with edge-cases ([#1737](https://github.com/scm-manager/scm-manager/pull/1737)) diff --git a/scm-ui/ui-components/src/__resources__/markdown-commit-link.md.ts b/scm-ui/ui-components/src/__resources__/markdown-commit-link.md.ts index 462179a73d..7c7e6eccb7 100644 --- a/scm-ui/ui-components/src/__resources__/markdown-commit-link.md.ts +++ b/scm-ui/ui-components/src/__resources__/markdown-commit-link.md.ts @@ -24,9 +24,9 @@ export default `# Commit Links in Markdown namespace/name@1a5s4w8a -Please check for this commit: namespace/name@1a5s4w8a +Please check for this commit: namespace/name@1a5s4w8a it *works* -hitchhiker/heart-of-gold@c7237cb60689046990dc9dc2a388a517adb3e2b2 +**really** also check *this* commit: hitchhiker/heart-of-gold@c7237cb60689046990dc9dc2a388a517adb3e2b2 hitchhiker/heart-of-gold@c7237cb diff --git a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap index a1b0086d58..0ca4662c22 100644 --- a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap +++ b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap @@ -53591,7 +53591,6 @@ exports[`Storyshots MarkdownView Commit Links 1`] = ` -
- -Please check for this commit: namespace/name@1a5s4w8a + it + + works +
- -+ + really + + also check + + this + + commit:
- - - - -@@ -53663,7 +53665,6 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
-Prefix suffix
- diff --git a/scm-ui/ui-components/src/markdown/remarkValuelessTextAdapter.ts b/scm-ui/ui-components/src/markdown/remarkValuelessTextAdapter.ts index 26fe29cd06..d1f2ca2a5b 100644 --- a/scm-ui/ui-components/src/markdown/remarkValuelessTextAdapter.ts +++ b/scm-ui/ui-components/src/markdown/remarkValuelessTextAdapter.ts @@ -28,13 +28,37 @@ import { Node, Parent } from "unist"; /** * Some existing remark plugins (e.g. changesetShortLinkParser or the plugin for issue tracker links) create * text nodes without values but with children. This does not get parsed properly by remark2rehype. - * This remark-plugin transforms all of these invalid text nodes to valid paragraphs. + * This remark-plugin takes the children of these invalid text nodes and inserts them into the node's parent + * in place of the text node. + * + * @example + * ``` + * # This -> + * + * validNode + * invalidNode + * child1 + * child2 + * child3 + * validNode + * + * # Becomes -> + * + * validNode + * child1 + * child2 + * child3 + * validNode + * ``` */ export const createTransformer = (): AstPlugin => { return ({ visit }) => { visit("text", (node: Node, index: number, parent?: Parent) => { if (node.value === undefined && Array.isArray(node.children) && node.children.length > 0) { - node.type = "paragraph"; + const children = node.children; + const preChildren = parent?.children.slice(0, index) || []; + const postChildren = parent?.children.slice(index + 1) || []; + parent!.children = [...preChildren, ...children, ...postChildren]; } }); };