@@ -48,33 +48,29 @@ const reduceHeadings = (text) => text
48
48
. replace ( / ^ # # \s + ( .+ ) $ / gm, '**$1**' ) ; // Convert H2 to bold
49
49
50
50
/**
51
- * Converts PR links , issue links , and changelog links to markdown format.
51
+ * Converts PR, issue, and changelog links to markdown format, ignoring existing markdown links .
52
52
* - PR links: `https://github.com/OWNER/REPO/pull/1` -> `[PR #1](https://github.com/OWNER/REPO/pull/1)`
53
53
* - Issue links: `https://github.com/OWNER/REPO/issues/1` -> `[Issue #30](https://github.com/OWNER/REPO/issues/1)`
54
54
* - Changelog links: `https://github.com/OWNER/REPO/compare/v1.0.0...v1.1.0` -> `[v1.0.0...v1.1.0](https://github.com/OWNER/REPO/compare/v1.0.0...v1.1.0)`
55
55
* @param {string } text The input text.
56
56
* @returns {string } The text with links converted to markdown format.
57
57
*/
58
58
const convertLinksToMarkdown = ( text ) => {
59
- // Convert PR links
60
- text = text . replace (
61
- / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w - ] + ) \/ ( [ \w - ] + ) \/ p u l l \/ ( \d + ) / g,
62
- ( match , owner , repo , prNumber ) => `[PR #${ prNumber } ](${ match } )`
63
- ) ;
64
-
65
- // Convert issue links
66
- text = text . replace (
67
- / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w - ] + ) \/ ( [ \w - ] + ) \/ i s s u e s \/ ( \d + ) / g,
68
- ( match , owner , repo , issueNumber ) => `[Issue #${ issueNumber } ](${ match } )`
69
- ) ;
70
-
71
- // Convert changelog comparison links
72
- text = text . replace (
73
- / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w - ] + ) \/ ( [ \w - ] + ) \/ c o m p a r e \/ ( [ v \w . - ] + ) \. \. \. ( [ v \w . - ] + ) / g,
74
- ( match , owner , repo , fromVersion , toVersion ) => `[${ fromVersion } ...${ toVersion } ](${ match } )`
75
- ) ;
76
-
77
- return text ;
59
+ // Extract existing markdown links and replace them with placeholders
60
+ const markdownLinks = [ ] ;
61
+ const textWithoutMarkdownLinks = text . replace ( / \[ .* ?\] \( .* ?\) / g, ( link ) => {
62
+ markdownLinks . push ( link ) ;
63
+ return `__MARKDOWN_LINK_PLACEHOLDER_${ markdownLinks . length - 1 } __` ;
64
+ } ) ;
65
+
66
+ // Convert standalone PR, issue, and changelog URLs to markdown format
67
+ let processedText = textWithoutMarkdownLinks
68
+ . replace ( / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w - ] + ) \/ ( [ \w - ] + ) \/ p u l l \/ ( \d + ) / g, ( match , owner , repo , prNumber ) => `[PR #${ prNumber } ](${ match } )` )
69
+ . replace ( / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w - ] + ) \/ ( [ \w - ] + ) \/ i s s u e s \/ ( \d + ) / g, ( match , owner , repo , issueNumber ) => `[Issue #${ issueNumber } ](${ match } )` )
70
+ . replace ( / h t t p s : \/ \/ g i t h u b \. c o m \/ ( [ \w - ] + ) \/ ( [ \w - ] + ) \/ c o m p a r e \/ ( [ v \w . - ] + ) \. \. \. ( [ v \w . - ] + ) / g, ( match , owner , repo , fromVersion , toVersion ) => `[${ fromVersion } ...${ toVersion } ](${ match } )` ) ;
71
+
72
+ // Reinsert the original markdown links
73
+ return processedText . replace ( / _ _ M A R K D O W N _ L I N K _ P L A C E H O L D E R _ ( \d + ) _ _ / g, ( match , index ) => markdownLinks [ parseInt ( index , 10 ) ] ) ;
78
74
} ;
79
75
80
76
/**
0 commit comments