Skip to content

Commit f236191

Browse files
committed
feat(ui): improved src/slot handling
1 parent 8221f32 commit f236191

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

ui/src/components/QMarkdown.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ export default defineComponent({
128128
],
129129

130130
setup (props, { slots, emit, expose }) {
131-
const $q = useQuasar(),
132-
rendered = ref(null),
131+
const $q = useQuasar()
132+
const rendered = ref(null),
133133
source = ref(null),
134134
markdownRef = ref(null)
135135

@@ -143,6 +143,17 @@ export default defineComponent({
143143
return { ...props, ...globalProps }
144144
})
145145

146+
const rawSource = computed(() => {
147+
let rawSource = ''
148+
if (allProps.value.src && allProps.value.src.length > 0) {
149+
rawSource = allProps.value.fixCr ? allProps.value.src.replace(/\\n/gi, '\n') : allProps.value.src
150+
}
151+
if (slots.default !== undefined && slots.default()[ 0 ].children.trim().length > 0) {
152+
rawSource = slots.default()[ 0 ].children
153+
}
154+
return rawSource
155+
})
156+
146157
const parsedCopyIcon = computed(() => {
147158
// default mdiContentCopy
148159
return allProps.value.copyIcon
@@ -255,11 +266,7 @@ export default defineComponent({
255266
const tocData = []
256267

257268
// get the markdown - slot overrides 'src'
258-
let markdown = source.value || ''
259-
if (slots.default !== undefined && slots.default()[ 0 ].children.trim().length > 0) {
260-
markdown = slots.default()[ 0 ].children.replace(/\\ /g, '\n').replace(/'/g, '')
261-
}
262-
269+
const markdown = rawSource.value || ''
263270
const highlight = (str, lang) => {
264271
if (__isEnabled(allProps.value.noHighlight)) {
265272
return prismHighlight(Prism, str, lang)

0 commit comments

Comments
 (0)