mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 16:58:36 +00:00
* WIP * Remove formula conversion related changes * Move the file input click guard to formatted text component * Move format types into their own components * Use a shared markdown-it instance * Move the formatter into data explorer * Move minification logic into BaserowFormulaMinified * Renderer should own the root element * Ensure long choice names are truncated * Ensure line height doesn't grow for paragraphs * Add tests * Add changelog * Add specific tests for choice element
98 lines
2.3 KiB
Vue
98 lines
2.3 KiB
Vue
<!-- eslint-disable vue/no-v-html vue/no-v-text-v-html-on-component -->
|
|
<template>
|
|
<component
|
|
:is="inline ? 'span' : 'div'"
|
|
:key="contentHash"
|
|
class="markdown"
|
|
:class="{ 'markdown--inline': inline }"
|
|
@click="$emit('click', $event)"
|
|
v-html="htmlContent"
|
|
/>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, watch } from 'vue'
|
|
import { generateHash } from '@baserow/modules/core/utils/hashing'
|
|
import { renderMarkdown } from '@baserow/modules/core/utils/markdown'
|
|
|
|
defineEmits(['click'])
|
|
|
|
const props = defineProps({
|
|
content: {
|
|
required: true,
|
|
type: String,
|
|
},
|
|
rules: {
|
|
required: false,
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
openLinksInNewTab: {
|
|
required: false,
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
/**
|
|
* Renders the content as inline markdown: only the inline syntax (emphasis,
|
|
* links, code, ...) applies, and the result has no wrapping paragraph, so
|
|
* it inherits the typography of wherever it is placed.
|
|
*/
|
|
inline: {
|
|
required: false,
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
/**
|
|
* The names of the markdown-it rules to switch off for this component, e.g.
|
|
* `['image', 'link']`. Unknown names are ignored.
|
|
*/
|
|
disabledRules: {
|
|
required: false,
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
})
|
|
|
|
// The hash makes sure the data is updated if the content changes.
|
|
const contentHash = computed(() => generateHash(props.content))
|
|
|
|
// Use ref + watcher to avoid side effects in computed
|
|
const htmlContent = ref('')
|
|
|
|
const linkInNewTabRules = {
|
|
link_open: (tokens, idx, options, env, self) => {
|
|
if (tokens[idx].attrIndex('target') < 0) {
|
|
tokens[idx].attrPush(['target', '_blank'])
|
|
}
|
|
if (tokens[idx].attrIndex('rel') < 0) {
|
|
tokens[idx].attrPush(['rel', 'noopener noreferrer'])
|
|
}
|
|
return self.renderToken(tokens, idx, options)
|
|
},
|
|
}
|
|
|
|
watch(
|
|
() => [
|
|
props.content,
|
|
props.rules,
|
|
props.openLinksInNewTab,
|
|
props.inline,
|
|
props.disabledRules,
|
|
],
|
|
() => {
|
|
htmlContent.value = renderMarkdown(props.content, {
|
|
rules: {
|
|
...(props.openLinksInNewTab ? linkInNewTabRules : {}),
|
|
...props.rules,
|
|
},
|
|
inline: props.inline,
|
|
disabledRules: props.disabledRules,
|
|
})
|
|
},
|
|
{
|
|
deep: true,
|
|
immediate: true,
|
|
}
|
|
)
|
|
</script>
|