fix: 链接添加跳转
This commit is contained in:
parent
c095f6e6e2
commit
5a5050c0fd
@ -5,14 +5,20 @@
|
|||||||
:modelValue="item"
|
:modelValue="item"
|
||||||
v-for="(item, index) in md_view_list"
|
v-for="(item, index) in md_view_list"
|
||||||
:key="index"
|
:key="index"
|
||||||
@onHtmlChanged="onHtmlChanged"
|
|
||||||
class="maxkb-md"
|
class="maxkb-md"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, nextTick, ref } from 'vue'
|
import { computed, nextTick, ref } from 'vue'
|
||||||
import { MdPreview } from 'md-editor-v3'
|
import { MdPreview, config } from 'md-editor-v3'
|
||||||
|
config({
|
||||||
|
markdownItConfig(md: markdownit) {
|
||||||
|
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
||||||
|
tokens[idx].attrSet('target', '_blank')
|
||||||
|
return md.renderer.renderToken(tokens, idx, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
const props = withDefaults(defineProps<{ source?: string; inner_suffix?: boolean }>(), {
|
const props = withDefaults(defineProps<{ source?: string; inner_suffix?: boolean }>(), {
|
||||||
source: ''
|
source: ''
|
||||||
})
|
})
|
||||||
@ -37,19 +43,5 @@ const md_view_list = computed(() => {
|
|||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
const onHtmlChanged = () => {
|
|
||||||
appendTarget()
|
|
||||||
}
|
|
||||||
const appendTarget = () => {
|
|
||||||
nextTick(() => {
|
|
||||||
var item = document.getElementsByClassName('maxkb-md')
|
|
||||||
for (var j = 0; j < item.length; j++) {
|
|
||||||
var aTags = item[j].getElementsByTagName('a')
|
|
||||||
for (var i = 0; i < aTags.length; i++) {
|
|
||||||
aTags[i].setAttribute('target', '_blank')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user