Skip to content

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Github_Reply_Comments/Github_Reply_Comments.user.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,37 @@
3434
});
3535
};
3636

37+
function turndownPluginGitHubAlert(turndownService) {
38+
turndownService.addRule("gfm-alert", {
39+
filter: function (node, _options) {
40+
return (
41+
node.nodeName === "DIV" &&
42+
node.classList.contains("markdown-alert")
43+
);
44+
},
45+
replacement: function (content, node, options) {
46+
const variant = node
47+
.querySelector(".markdown-alert-title")
48+
.innerText.trim();
49+
content = content.replace(/^\n+|\n+$/g, "");
50+
content = content.replace(
51+
// eslint-disable-next-line security/detect-non-literal-regexp
52+
new RegExp("^" + variant),
53+
"[!" + variant.toUpperCase() + "]",
54+
);
55+
return options.rules.blockquote.replacement(content);
56+
},
57+
});
58+
}
59+
3760
var turndownService = new TurndownService({
3861
headingStyle: "atx",
3962
codeBlockStyle: "fenced",
4063
hr: "***",
4164
});
4265
turndownService.use(turndownPluginGfm.gfm);
4366
turndownService.use(turndownPluginGithubCodeSnippet);
67+
turndownService.use(turndownPluginGitHubAlert);
4468

4569
function getCommentTextarea(replyBtn) {
4670
var newComment = replyBtn;

Github_Reply_Comments/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ reply button on an comment.
2424

2525
- 🐛 Ignore "Reference new issue" modals when quoting.
2626
- 🐛 Skip empty PR description.
27+
- Add support for [GitHub alerts](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts).
2728

2829
- version **1.0.6**
2930

0 commit comments

Comments
 (0)