@datagouv/components-next 1.4.1-dev.1351.gdb12fa73 → 1.4.1-dev.1354.gd30ac2d8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datagouv/components-next",
3
- "version": "1.4.1-dev.1351.gdb12fa73",
3
+ "version": "1.4.1-dev.1354.gd30ac2d8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -42,6 +42,7 @@
42
42
  "pdfjs-dist": "^4.10.38",
43
43
  "pmtiles": "^4.5.0",
44
44
  "popmotion": "^11.0.5",
45
+ "rehype-external-links": "^3.0.0",
45
46
  "rehype-highlight": "^7.0.2",
46
47
  "rehype-raw": "^7.0.0",
47
48
  "rehype-sanitize": "^6.0.0",
@@ -2,7 +2,7 @@
2
2
  <template>
3
3
  <div
4
4
  :class="size === 'sm' ? markdownSmClasses : markdownClasses"
5
- v-html="formatMarkdown(content, { minDepth: minHeading, noHeadings })"
5
+ v-html="formatMarkdown(content, { minDepth: minHeading, noHeadings, followLinks })"
6
6
  />
7
7
  </template>
8
8
 
@@ -14,9 +14,12 @@ withDefaults(defineProps<{
14
14
  minHeading?: 1 | 2 | 3 | 4 | 5 | 6
15
15
  noHeadings?: boolean
16
16
  size?: 'sm' | 'md'
17
+ // Only for content written by the team, see formatMarkdown.
18
+ followLinks?: boolean
17
19
  }>(), {
18
20
  minHeading: 3,
19
21
  size: 'sm',
20
22
  noHeadings: false,
23
+ followLinks: false,
21
24
  })
22
25
  </script>
@@ -1,6 +1,7 @@
1
1
  import type hast from 'hast'
2
2
  import behead, { type Options } from 'remark-behead'
3
3
  import remarkBreaks from 'remark-breaks'
4
+ import rehypeExternalLinks from 'rehype-external-links'
4
5
  import rehypeHighlight from 'rehype-highlight'
5
6
  import remarkParse from 'remark-parse'
6
7
  import remarkRehype from 'remark-rehype'
@@ -57,15 +58,17 @@ function rehypeNoHeadings(this: Processor): Transformer {
57
58
  }
58
59
  }
59
60
 
60
- export function formatMarkdown(md: string, config: number | { minDepth: number, noHeadings: boolean } = 3) {
61
+ export function formatMarkdown(md: string, config: number | { minDepth: number, noHeadings: boolean, followLinks?: boolean } = 3) {
61
62
  let minDepth: number
62
63
  let noHeadings = false
64
+ let followLinks = false
63
65
  if (typeof config === 'number') {
64
66
  minDepth = config
65
67
  }
66
68
  else {
67
69
  minDepth = config.minDepth
68
70
  noHeadings = config.noHeadings
71
+ followLinks = config.followLinks ?? false
69
72
  }
70
73
  const result = unified()
71
74
  .use(behead, { minDepth: minDepth > 1 ? minDepth : undefined } as Options)
@@ -84,6 +87,12 @@ export function formatMarkdown(md: string, config: number | { minDepth: number,
84
87
  .use(rehypeHighlight)
85
88
  .use(rehypeSlug)
86
89
  .use(rehypeSanitize)
90
+ // Markdown mostly comes from users: links leaving the site must not pass on its search
91
+ // ranking, or they become worth spamming for. `followLinks` is for content written by the team.
92
+ .use(rehypeExternalLinks, {
93
+ rel: followLinks ? [] : ['ugc', 'nofollow', 'noopener'],
94
+ protocols: ['http', 'https', 'mailto'],
95
+ })
87
96
  // Serialize syntax tree to HTML
88
97
  .use(rehypeStringify)
89
98
  .use(noHeadings ? [rehypeLazyLoad, rehypeNoHeadings] : [rehypeLazyLoad])