github-issue-tower-defence-management 1.144.2 → 1.144.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>TDPM Console</title>
7
- <script type="module" crossorigin src="/assets/index-BYoG8oQb.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-Bmc_nF1d.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-CKX2ny-z.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-issue-tower-defence-management",
3
- "version": "1.144.2",
3
+ "version": "1.144.3",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {
@@ -61,7 +61,7 @@ describe('renderMarkdownToSafeHtml', () => {
61
61
  repo: 'npm-cli-github-issue-tower-defence-management',
62
62
  });
63
63
  expect(html).toContain(
64
- '<a href="https://github.com/HiromiShikata/npm-cli-github-issue-tower-defence-management/issues/127">#127</a>',
64
+ '<a href="https://github.com/HiromiShikata/npm-cli-github-issue-tower-defence-management/issues/127" target="_blank" rel="noopener noreferrer">#127</a>',
65
65
  );
66
66
  });
67
67
 
@@ -179,3 +179,26 @@ describe('hasMermaidFence', () => {
179
179
  expect(hasMermaidFence('```ts\nconst a = 1;\n```')).toBe(false);
180
180
  });
181
181
  });
182
+
183
+ describe('renderMarkdownToSafeHtml link targets', () => {
184
+ it('opens an autolinked url in a new tab', () => {
185
+ const html = renderMarkdownToSafeHtml('https://example.com/doc');
186
+ expect(html).toContain('target="_blank"');
187
+ expect(html).toContain('rel="noopener noreferrer"');
188
+ });
189
+
190
+ it('opens an inline markdown link in a new tab', () => {
191
+ const html = renderMarkdownToSafeHtml('[doc](https://example.com/doc)');
192
+ expect(html).toContain('target="_blank"');
193
+ expect(html).toContain('rel="noopener noreferrer"');
194
+ });
195
+
196
+ it('opens an issue reference link in a new tab', () => {
197
+ const html = renderMarkdownToSafeHtml('see #12', {
198
+ owner: 'demo',
199
+ repo: 'repo',
200
+ });
201
+ expect(html).toContain('https://github.com/demo/repo/issues/12');
202
+ expect(html).toContain('target="_blank"');
203
+ });
204
+ });
@@ -66,6 +66,16 @@ marked.use({
66
66
  ],
67
67
  });
68
68
 
69
+ const withLinksOpeningInNewTab = (html: string): string => {
70
+ const template = document.createElement('template');
71
+ template.innerHTML = html;
72
+ for (const anchor of Array.from(template.content.querySelectorAll('a'))) {
73
+ anchor.setAttribute('target', '_blank');
74
+ anchor.setAttribute('rel', 'noopener noreferrer');
75
+ }
76
+ return template.innerHTML;
77
+ };
78
+
69
79
  export const renderMarkdownToSafeHtml = (
70
80
  source: string,
71
81
  repoContext?: ConsoleRepoContext,
@@ -79,7 +89,7 @@ export const renderMarkdownToSafeHtml = (
79
89
  try {
80
90
  const parsed = marked.parse(source, { async: false });
81
91
  const rawHtml = typeof parsed === 'string' ? parsed : '';
82
- return DOMPurify.sanitize(rawHtml);
92
+ return withLinksOpeningInNewTab(DOMPurify.sanitize(rawHtml));
83
93
  } finally {
84
94
  activeRepoContext = null;
85
95
  }