mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-05 03:40:56 +01:00
rework valueless text adapter to be backwards-compatible with edge-cases (#1737)
When implementing the remark rehype rework, which was supposed to be backwards-compatible, incorrect mdast was produced by the remarkValuelessTextAdapter in some edge-cases. This caused markdown generated by other plugins, such as the issue-tracker-plugin, to be faulty (e.g. Und die #10 ist *so* toll caused visual artifacts). This PR solves the issue by inlining the children of the empty text node instead of wrapping them in a paragraph. This is also more consistent with the previous output, as can be observed when pairing SCM-Manager <= 2.15.0 with the issue-tracker-plugin and using the aforementioned snippet.
This commit is contained in:
committed by
GitHub
parent
f52c0b07bf
commit
e5a1702e95
2
gradle/changelog/remark-text-adapter.yaml
Normal file
2
gradle/changelog/remark-text-adapter.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Make MarkdownView backwards-compatible with edge-cases ([#1737](https://github.com/scm-manager/scm-manager/pull/1737))
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -53591,7 +53591,6 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
</h1>
|
||||
|
||||
|
||||
<p />
|
||||
<p>
|
||||
<a
|
||||
href="/repo/namespace/name/code/changeset/1a5s4w8a"
|
||||
@@ -53600,10 +53599,8 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
namespace/name@1a5s4w8a
|
||||
</a>
|
||||
</p>
|
||||
<p />
|
||||
|
||||
|
||||
<p />
|
||||
<p>
|
||||
Please check for this commit:
|
||||
<a
|
||||
@@ -53612,12 +53609,22 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
>
|
||||
namespace/name@1a5s4w8a
|
||||
</a>
|
||||
it
|
||||
<em>
|
||||
works
|
||||
</em>
|
||||
</p>
|
||||
<p />
|
||||
|
||||
|
||||
<p />
|
||||
<p>
|
||||
<strong>
|
||||
really
|
||||
</strong>
|
||||
also check
|
||||
<em>
|
||||
this
|
||||
</em>
|
||||
commit:
|
||||
<a
|
||||
href="/repo/hitchhiker/heart-of-gold/code/changeset/c7237cb60689046990dc9dc2a388a517adb3e2b2"
|
||||
title="changeset.shortlink.title"
|
||||
@@ -53625,10 +53632,8 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
hitchhiker/heart-of-gold@c7237cb60689046990dc9dc2a388a517adb3e2b2
|
||||
</a>
|
||||
</p>
|
||||
<p />
|
||||
|
||||
|
||||
<p />
|
||||
<p>
|
||||
<a
|
||||
href="/repo/hitchhiker/heart-of-gold/code/changeset/c7237cb"
|
||||
@@ -53637,10 +53642,8 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
hitchhiker/heart-of-gold@c7237cb
|
||||
</a>
|
||||
</p>
|
||||
<p />
|
||||
|
||||
|
||||
<p />
|
||||
<p>
|
||||
<a
|
||||
href="/repo/hitchhiker/heart-of-gold/code/changeset/42"
|
||||
@@ -53649,7 +53652,6 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
hitchhiker/heart-of-gold@42
|
||||
</a>
|
||||
</p>
|
||||
<p />
|
||||
|
||||
|
||||
<p>
|
||||
@@ -53663,7 +53665,6 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
</p>
|
||||
|
||||
|
||||
<p />
|
||||
<p>
|
||||
Prefix
|
||||
<a
|
||||
@@ -53681,7 +53682,6 @@ exports[`Storyshots MarkdownView Commit Links 1`] = `
|
||||
</a>
|
||||
suffix
|
||||
</p>
|
||||
<p />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user