fix: properly pass checkbox id to markdown renderer
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2022-09-15 14:23:46 +02:00
parent 39ccdd7a51
commit 8c866401b0
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 5 additions and 4 deletions

View File

@ -222,7 +222,7 @@ export default defineComponent({
return checkboxes[n]
},
renderPreview() {
setupMarkdownRenderer()
setupMarkdownRenderer(this.checkboxId)
this.preview = DOMPurify.sanitize(marked(this.text), {ADD_ATTR: ['target']})

View File

@ -1,7 +1,7 @@
import {marked} from 'marked'
import hljs from 'highlight.js/lib/common'
export function setupMarkdownRenderer() {
export function setupMarkdownRenderer(checkboxId: string) {
const renderer = new marked.Renderer()
const linkRenderer = renderer.link
@ -26,7 +26,7 @@ export function setupMarkdownRenderer() {
}
checkboxNum++
return `<input type="checkbox" data-checkbox-num="${checkboxNum}" ${checked} class="text-checkbox-${this.checkboxId}"/>`
return `<input type="checkbox" data-checkbox-num="${checkboxNum}" ${checked} class="text-checkbox-${checkboxId}"/>`
},
link: (href, title, text) => {
const isLocal = href.startsWith(`${location.protocol}//${location.hostname}`)

View File

@ -19,6 +19,7 @@ import {useStore} from '@/store'
import {setupMarkdownRenderer} from '@/helpers/markdownRenderer'
import {marked} from 'marked'
import DOMPurify from 'dompurify'
import {createRandomID} from '@/helpers/randomId'
const props = defineProps({
listId: {
@ -37,7 +38,7 @@ const htmlDescription = computed(() => {
return ''
}
setupMarkdownRenderer()
setupMarkdownRenderer(createRandomID())
return DOMPurify.sanitize(marked(description), {ADD_ATTR: ['target']})
})
</script>