@globalbrain/sefirot 4.3.2 → 4.4.0
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useLinkifyIt } from 'sefirot/composables/Markdown'
|
|
2
3
|
import { computed } from 'vue'
|
|
3
4
|
import { useHasSlotContent } from '../composables/Utils'
|
|
4
5
|
import SDescEmpty from './SDescEmpty.vue'
|
|
@@ -7,6 +8,7 @@ const props = defineProps<{
|
|
|
7
8
|
value?: string | null
|
|
8
9
|
lineClamp?: string | number
|
|
9
10
|
preWrap?: boolean
|
|
11
|
+
linkify?: boolean
|
|
10
12
|
}>()
|
|
11
13
|
|
|
12
14
|
const classes = computed(() => [
|
|
@@ -17,14 +19,23 @@ const classes = computed(() => [
|
|
|
17
19
|
const hasSlot = useHasSlotContent()
|
|
18
20
|
|
|
19
21
|
const lineClamp = computed(() => props.lineClamp ?? 'none')
|
|
22
|
+
|
|
23
|
+
const linkifyIt = useLinkifyIt()
|
|
24
|
+
|
|
25
|
+
const _value = computed(() => {
|
|
26
|
+
if (props.linkify) {
|
|
27
|
+
return linkifyIt(props.value ?? '')
|
|
28
|
+
}
|
|
29
|
+
return props.value
|
|
30
|
+
})
|
|
20
31
|
</script>
|
|
21
32
|
|
|
22
33
|
<template>
|
|
23
|
-
<div v-if="hasSlot ||
|
|
24
|
-
<div class="value">
|
|
25
|
-
<slot
|
|
26
|
-
<template v-else>{{ value }}</template>
|
|
34
|
+
<div v-if="hasSlot || _value" class="SDescText" :class="classes">
|
|
35
|
+
<div class="value" v-if="hasSlot">
|
|
36
|
+
<slot />
|
|
27
37
|
</div>
|
|
38
|
+
<div class="value" v-else v-html="_value" />
|
|
28
39
|
</div>
|
|
29
40
|
<SDescEmpty v-else />
|
|
30
41
|
</template>
|
|
@@ -32,6 +32,20 @@ export function useMarkdown(options: UseMarkdownOptions = {}): UseMarkdown {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
export function useLinkifyIt() {
|
|
36
|
+
const md = new MarkdownIt('zero', { linkify: true })
|
|
37
|
+
md.enable('linkify')
|
|
38
|
+
|
|
39
|
+
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
|
40
|
+
const token = tokens[idx]
|
|
41
|
+
token.attrSet('target', '_blank')
|
|
42
|
+
token.attrSet('rel', 'noreferrer')
|
|
43
|
+
return self.renderToken(tokens, idx, options)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (source: string) => md.renderInline(source)
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
export interface UseLink {
|
|
36
50
|
addListeners(): void
|
|
37
51
|
removeListeners(): void
|
package/package.json
CHANGED