You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apify-docs-theme/src/markdown.js
+39-4Lines changed: 39 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,10 @@
1
1
const{ remark }=require('remark');
2
2
3
+
/**
4
+
* Updates the markdown content for better UX and compatibility with Docusaurus v3.
5
+
* @param {string} changelog The markdown content.
6
+
* @returns {string} The updated markdown content.
7
+
*/
3
8
functionupdateChangelog(changelog){
4
9
consttree=remark.parse(changelog);
5
10
@@ -13,6 +18,13 @@ function updateChangelog(changelog) {
13
18
returnchangelog;
14
19
}
15
20
21
+
/**
22
+
* Bumps the headings levels in the markdown content. This function increases the depth
23
+
* of all headings in the content by 1. This is useful when the content is included in
24
+
* another markdown file with a higher-level heading.
25
+
* @param {*} tree Remark AST tree.
26
+
* @returns {void} Nothing. This function modifies the tree in place.
27
+
*/
16
28
functionbumpHeadingsLevels(tree){
17
29
tree.children?.forEach((child)=>{
18
30
if(child.type==='heading'){
@@ -23,6 +35,12 @@ function bumpHeadingsLevels(tree) {
23
35
});
24
36
}
25
37
38
+
/**
39
+
* Links user tags in the markdown content. This function replaces the user tags
40
+
* (e.g. `@username`) with a link to the user's GitHub profile (just like GitHub's UI).
41
+
* @param {*} tree Remark AST tree.
42
+
* @returns {void} Nothing. This function modifies the tree in place.
43
+
*/
26
44
functionlinkifyUserTags(tree){
27
45
for(leti=0;i<tree.children?.length;i++){
28
46
constchild=tree.children[i];
@@ -56,7 +74,12 @@ function linkifyUserTags(tree) {
56
74
}
57
75
}
58
76
59
-
// If there is a PR URL (https://github.com/**/**/pull/number) in the text body, split the body, and replace the URL with a link to the PR (the text should be the PR number).
77
+
/**
78
+
* Prettifies PR links in the markdown content. Just like GitHub's UI, this function
79
+
* replaces the full PR URL with a link represented by the PR number (prefixed by a hashtag).
80
+
* @param {*} tree Remark AST tree.
81
+
* @returns {void} Nothing. This function modifies the tree in place.
82
+
*/
60
83
functionprettifyPRLinks(tree){
61
84
for(leti=0;i<tree.children?.length;i++){
62
85
constchild=tree.children[i];
@@ -90,15 +113,27 @@ function prettifyPRLinks(tree) {
0 commit comments