@datagouv/components-next 0.0.11 → 0.0.12
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/dist/{JsonPreview.client-Boqx8dM7.js → JsonPreview.client-DIkmdH2M.js} +2 -2
- package/dist/{MapContainer.client-DbRyTZ69.js → MapContainer.client-C_ziilUT.js} +1 -1
- package/dist/{PdfPreview.client-wbXsTNTV.js → PdfPreview.client-ClQF3S8E.js} +2 -2
- package/dist/{Pmtiles.client-pnjwffA_.js → Pmtiles.client-FkdZAUG-.js} +1 -1
- package/dist/Swagger.client-QQlOMFC1.js +4 -0
- package/dist/{XmlPreview.client-Z6TgGP2G.js → XmlPreview.client-DfHUWkih.js} +2 -2
- package/dist/components-next.css +3 -3
- package/dist/components-next.js +26 -26
- package/dist/{main-CLgZLazG.js → main-D4D0CyPW.js} +71938 -49181
- package/dist/{pdf-vue3-CwfAPVHf.js → pdf-vue3-DFzYx_2k.js} +1 -1
- package/dist/{text-clamp.esm--JneuJHF.js → text-clamp.esm-pQ8Iya95.js} +1 -1
- package/dist/{vue3-json-viewer-CWdqwDBZ.js → vue3-json-viewer-AGKmPmT9.js} +1 -1
- package/dist/{vue3-xml-viewer.common-B4U761SY.js → vue3-xml-viewer.common-CntqATO7.js} +799 -805
- package/package.json +12 -3
- package/src/components/ResourceAccordion/ResourceAccordion.vue +2 -2
- package/src/functions/markdown.ts +56 -33
- package/dist/Swagger.client-DwYQ-RDs.js +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagouv/components-next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/main.ts",
|
|
@@ -29,16 +29,25 @@
|
|
|
29
29
|
"dompurify": "^3.2.5",
|
|
30
30
|
"geopf-extensions-openlayers": "^1.0.0-beta.5",
|
|
31
31
|
"maplibre-gl": "^5.5.0",
|
|
32
|
-
"markdown-it": "^14.1.0",
|
|
33
32
|
"ofetch": "^1.4.1",
|
|
34
33
|
"ol": "^10.6.1",
|
|
35
34
|
"pdf-vue3": "^1.0.12",
|
|
36
35
|
"pmtiles": "^4.3.0",
|
|
37
36
|
"popmotion": "^8.7.6",
|
|
38
|
-
"
|
|
37
|
+
"rehype-highlight": "^7.0.2",
|
|
38
|
+
"rehype-raw": "^7.0.0",
|
|
39
|
+
"rehype-sanitize": "^6.0.0",
|
|
40
|
+
"rehype-slug": "^6.0.0",
|
|
41
|
+
"rehype-stringify": "^10.0.1",
|
|
42
|
+
"remark-behead": "^3.1.0",
|
|
43
|
+
"remark-breaks": "^4.0.0",
|
|
39
44
|
"remark-gfm": "^4.0.1",
|
|
45
|
+
"remark-parse": "^11.0.0",
|
|
46
|
+
"remark-rehype": "^11.1.2",
|
|
40
47
|
"strip-markdown": "^6.0.0",
|
|
41
48
|
"swagger-ui": "^5.20.1",
|
|
49
|
+
"unified": "^11.0.5",
|
|
50
|
+
"unist-util-visit": "^5.0.0",
|
|
42
51
|
"vue": "^3.5.13",
|
|
43
52
|
"vue-content-loader": "^2.0.1",
|
|
44
53
|
"vue-i18n": "^10.0.6",
|
|
@@ -219,7 +219,7 @@
|
|
|
219
219
|
>
|
|
220
220
|
<div
|
|
221
221
|
class="fr-mt-0 markdown fr-text--sm text-mention-grey"
|
|
222
|
-
v-html="
|
|
222
|
+
v-html="formatMarkdown(resource.description || '')"
|
|
223
223
|
/>
|
|
224
224
|
</div>
|
|
225
225
|
<div
|
|
@@ -340,7 +340,7 @@ import { useI18n } from 'vue-i18n'
|
|
|
340
340
|
import { RiDownloadLine, RiFileCopyLine, RiFileWarningLine } from '@remixicon/vue'
|
|
341
341
|
import OrganizationNameWithCertificate from '../OrganizationNameWithCertificate.vue'
|
|
342
342
|
import { filesize, summarize } from '../../functions/helpers'
|
|
343
|
-
import {
|
|
343
|
+
import { formatMarkdown } from '../../functions/markdown'
|
|
344
344
|
import { useFormatDate } from '../../functions/dates'
|
|
345
345
|
import type { CommunityResource, Resource } from '../../types/resources'
|
|
346
346
|
import type { Dataset, DatasetV2 } from '../../types/datasets'
|
|
@@ -1,45 +1,68 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import type hast from 'hast'
|
|
2
|
+
import behead, { type Options } from 'remark-behead'
|
|
3
|
+
import remarkBreaks from 'remark-breaks'
|
|
4
|
+
import rehypeHighlight from 'rehype-highlight'
|
|
5
|
+
import remarkParse from 'remark-parse'
|
|
6
|
+
import remarkRehype from 'remark-rehype'
|
|
7
|
+
import rehypeRaw from 'rehype-raw'
|
|
8
|
+
import rehypeSanitize from 'rehype-sanitize'
|
|
9
|
+
import rehypeSlug from 'rehype-slug'
|
|
10
|
+
import rehypeStringify from 'rehype-stringify'
|
|
11
|
+
import { unified, type Processor, type Transformer } from 'unified'
|
|
12
|
+
import type { Node } from 'unist'
|
|
13
|
+
import { visit } from 'unist-util-visit'
|
|
3
14
|
import remarkGfm from 'remark-gfm'
|
|
4
15
|
import strip from 'strip-markdown'
|
|
5
16
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
markdownParser.use(function (md) {
|
|
17
|
-
md.renderer.rules.link_open = function (tokens, idx, options, _env, self) {
|
|
18
|
-
const link_open = tokens[idx]
|
|
19
|
-
link_open.attrs?.push(['rel', 'ugc nofollow noopener'])
|
|
20
|
-
return self.renderToken(tokens, idx, options)
|
|
17
|
+
// Copied from https://github.com/potato4d/rehype-plugin-image-native-lazy-loading/blob/v1.2.0/src/index.ts
|
|
18
|
+
function lazyLoadPlugin(this: Processor): Transformer {
|
|
19
|
+
function visitor(el: hast.Element) {
|
|
20
|
+
if (el.tagName !== 'img') {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
el.properties = {
|
|
24
|
+
...(el.properties || {}),
|
|
25
|
+
loading: 'lazy',
|
|
26
|
+
}
|
|
21
27
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
s_open.tag = 'del'
|
|
27
|
-
return self.renderToken(tokens, idx, options)
|
|
28
|
-
}
|
|
29
|
-
md.renderer.rules.s_close = function (tokens, idx, options, _env, self) {
|
|
30
|
-
const s_close = tokens[idx]
|
|
31
|
-
s_close.type = 'del_close'
|
|
32
|
-
s_close.tag = 'del'
|
|
33
|
-
return self.renderToken(tokens, idx, options)
|
|
28
|
+
|
|
29
|
+
function transformer(htmlAST: Node): Node {
|
|
30
|
+
visit(htmlAST, 'element', visitor)
|
|
31
|
+
return htmlAST
|
|
34
32
|
}
|
|
35
|
-
})
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
return transformer
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function formatMarkdown(md: string, minDepth = 3) {
|
|
38
|
+
const result = unified()
|
|
39
|
+
.use(behead, { minDepth: minDepth > 1 ? minDepth : undefined } as Options)
|
|
40
|
+
// Take Markdown as input and turn it into MD syntax tree
|
|
41
|
+
.use(remarkParse, { fragment: true })
|
|
42
|
+
.use(remarkBreaks)
|
|
43
|
+
.use(remarkGfm)
|
|
44
|
+
// Switch from MD syntax tree to HTML syntax tree (remark -> rehype)
|
|
45
|
+
.use(remarkRehype, {
|
|
46
|
+
// Necessary for support HTML embeds (see next plugin)
|
|
47
|
+
allowDangerousHtml: true,
|
|
48
|
+
})
|
|
49
|
+
// Support HTML embedded inside markdown
|
|
50
|
+
.use(rehypeRaw)
|
|
51
|
+
// Improve code highlighting
|
|
52
|
+
.use(rehypeHighlight)
|
|
53
|
+
.use(rehypeSlug)
|
|
54
|
+
.use(rehypeSanitize)
|
|
55
|
+
// Serialize syntax tree to HTML
|
|
56
|
+
.use(rehypeStringify)
|
|
57
|
+
.use(lazyLoadPlugin)
|
|
58
|
+
// And finally, process the input
|
|
59
|
+
.processSync(md)
|
|
60
|
+
|
|
61
|
+
return String(result)
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
export async function removeMarkdown(text: string) {
|
|
42
|
-
const file = await
|
|
65
|
+
const file = await unified()
|
|
43
66
|
.use(remarkGfm)
|
|
44
67
|
.use(strip)
|
|
45
68
|
.process(text)
|