Skip to content

Commit 1559459

Browse files
committed
fix tests
1 parent d286b3a commit 1559459

File tree

9 files changed

+40
-49
lines changed

9 files changed

+40
-49
lines changed

dist/action.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19561,20 +19561,15 @@ function increment_headings() {
1956119561
*/
1956219562
function set_link_attributes() {
1956319563
return function transformer(tree) {
19564-
unistUtilVisit(tree, "link", (node) => {
19565-
let target_attr = "";
19566-
let title_attr = "";
19567-
19568-
if (node.url.startsWith("http")) {
19569-
target_attr = ' target="_blank"';
19570-
}
19564+
unistUtilVisit(tree, "element", (node) => {
19565+
// console.log(node);
19566+
if (node.tagName === "a") {
19567+
if (node.properties.href && node.properties.href.startsWith("http")) {
19568+
node.properties.target = "_blank";
19569+
}
1957119570

19572-
if (node.title !== null) {
19573-
title_attr = ` title="${node.title}"`;
19571+
node.properties.rel = "noopener noreferrer";
1957419572
}
19575-
19576-
((node ) ).type = "html";
19577-
((node ) ).value = `<a href="${node.url}"${target_attr}${title_attr} rel="noopener noreferrer">${node.children[0].value}</a>`;
1957819573
});
1957919574
};
1958019575
}
@@ -25772,7 +25767,6 @@ const { process: process$1 } = unified_1()
2577225767
.use(increment_headings)
2577325768
.use(validate_headings)
2577425769
.use(linkify_headings)
25775-
.use(set_link_attributes)
2577625770
.use(highight_code_block)
2577725771
// MDAST -> HAST
2577825772
.use(remarkRehype, {
@@ -25790,6 +25784,7 @@ const { process: process$1 } = unified_1()
2579025784
},
2579125785
})
2579225786
// HAST transforms
25787+
.use(set_link_attributes)
2579325788
.use(split_view)
2579425789
// HAST -> string
2579525790
.use(rehypeStringify, { allowDangerousCharacters: true, allowDangerousHtml: true });

dist/cli.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18324,20 +18324,15 @@ function increment_headings() {
1832418324
*/
1832518325
function set_link_attributes() {
1832618326
return function transformer(tree) {
18327-
unistUtilVisit(tree, "link", (node) => {
18328-
let target_attr = "";
18329-
let title_attr = "";
18330-
18331-
if (node.url.startsWith("http")) {
18332-
target_attr = ' target="_blank"';
18333-
}
18327+
unistUtilVisit(tree, "element", (node) => {
18328+
// console.log(node);
18329+
if (node.tagName === "a") {
18330+
if (node.properties.href && node.properties.href.startsWith("http")) {
18331+
node.properties.target = "_blank";
18332+
}
1833418333

18335-
if (node.title !== null) {
18336-
title_attr = ` title="${node.title}"`;
18334+
node.properties.rel = "noopener noreferrer";
1833718335
}
18338-
18339-
((node ) ).type = "html";
18340-
((node ) ).value = `<a href="${node.url}"${target_attr}${title_attr} rel="noopener noreferrer">${node.children[0].value}</a>`;
1834118336
});
1834218337
};
1834318338
}
@@ -24535,7 +24530,6 @@ const { process: process$1 } = unified_1()
2453524530
.use(increment_headings)
2453624531
.use(validate_headings)
2453724532
.use(linkify_headings)
24538-
.use(set_link_attributes)
2453924533
.use(highight_code_block)
2454024534
// MDAST -> HAST
2454124535
.use(remarkRehype, {
@@ -24553,6 +24547,7 @@ const { process: process$1 } = unified_1()
2455324547
},
2455424548
})
2455524549
// HAST transforms
24550+
.use(set_link_attributes)
2455624551
.use(split_view)
2455724552
// HAST -> string
2455824553
.use(rehypeStringify, { allowDangerousCharacters: true, allowDangerousHtml: true });

src/format/fixtures/api-docs-html.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/format/format_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const { process } = unified()
5656
.use(increment_headings)
5757
.use(validate_headings)
5858
.use(linkify_headings)
59-
.use(set_link_attributes)
6059
.use(highight_code_block)
6160
// MDAST -> HAST
6261
.use(rehype, {
@@ -74,6 +73,7 @@ const { process } = unified()
7473
},
7574
})
7675
// HAST transforms
76+
.use(set_link_attributes)
7777
.use(split_view)
7878
// HAST -> string
7979
.use(stringify, { allowDangerousCharacters: true, allowDangerousHtml: true });

src/transform/docs.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ _docs("transforms tutorials", async () => {
6969

7070
_docs("transforms blog", async () => {
7171
const output = await transform_blog(blog_in, "svelte", "blog");
72+
assert.equal(output.full[0].content, blog_out_full[0].content);
7273
assert.equal(output, { list: blog_out_list, full: blog_out_full });
7374
});
7475

src/transform/fixtures/blog.ts

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

src/transform/fixtures/docs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const docs_readme_full_out: Doc[] = [
6060
},
6161
],
6262
content:
63-
'<p>asdasdas</p>\n<h3><span id="hello" class="offset-anchor"></span><a href="http://github.com/docs/adapter-vercel#hello" class="anchor" aria-hidden></a>hello</h3>\n<p>asdasd</p>\n<h4><span id="hello-third-heading" class="offset-anchor"></span><a href="http://github.com/docs/adapter-vercel#hello-third-heading" class="anchor" aria-hidden></a>Third heading</h4>\n<p>asdasdasd</p>',
63+
'<p>asdasdas</p>\n<h3><span id="hello" class="offset-anchor"></span><a href="http://github.com/docs/adapter-vercel#hello" class="anchor" aria-hidden rel="noopener noreferrer"></a>hello</h3>\n<p>asdasd</p>\n<h4><span id="hello-third-heading" class="offset-anchor"></span><a href="http://github.com/docs/adapter-vercel#hello-third-heading" class="anchor" aria-hidden rel="noopener noreferrer"></a>Third heading</h4>\n<p>asdasdasd</p>',
6464
},
6565
];
6666

@@ -98,7 +98,7 @@ export const docs_full_out: Doc[] = [
9898
},
9999
],
100100
content:
101-
'<h3><span id="part-1-docs1-content" class="offset-anchor"></span><a href="http://github.com/docs#part-1-docs1-content" class="anchor" aria-hidden></a>docs1 content</h3>',
101+
'<h3><span id="part-1-docs1-content" class="offset-anchor"></span><a href="http://github.com/docs#part-1-docs1-content" class="anchor" aria-hidden rel="noopener noreferrer"></a>docs1 content</h3>',
102102
},
103103
{
104104
title: "part 2",
@@ -112,7 +112,7 @@ export const docs_full_out: Doc[] = [
112112
},
113113
],
114114
content:
115-
'<h3><span id="part-2-docs2-content" class="offset-anchor"></span><a href="http://github.com/docs#part-2-docs2-content" class="anchor" aria-hidden></a>docs2 content</h3>',
115+
'<h3><span id="part-2-docs2-content" class="offset-anchor"></span><a href="http://github.com/docs#part-2-docs2-content" class="anchor" aria-hidden rel="noopener noreferrer"></a>docs2 content</h3>',
116116
},
117117
{
118118
title: "part 3",
@@ -126,7 +126,7 @@ export const docs_full_out: Doc[] = [
126126
},
127127
],
128128
content:
129-
'<h3><span id="part-3-docs3-content" class="offset-anchor"></span><a href="http://github.com/docs#part-3-docs3-content" class="anchor" aria-hidden></a>docs3 content</h3>',
129+
'<h3><span id="part-3-docs3-content" class="offset-anchor"></span><a href="http://github.com/docs#part-3-docs3-content" class="anchor" aria-hidden rel="noopener noreferrer"></a>docs3 content</h3>',
130130
},
131131
];
132132

src/transform/fixtures/everything.ts

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

src/transform/fixtures/migrating.ts

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)