Add better support for markdown (switch nano-markdown for markdown-it as the former doesn't support backtick-code-formatting), add Markdown element. See #1929

This commit is contained in:
Pieter Vander Vennet 2024-04-27 22:44:35 +02:00
parent 9ead113555
commit d2e7bac775
10 changed files with 120 additions and 32 deletions

View file

@ -0,0 +1,17 @@
<script lang="ts">
import markdownit from "markdown-it"
import { UIEventSource } from "../../Logic/UIEventSource"
const md = markdownit()
export let src: string
export let srcWritable: UIEventSource<string> = undefined
srcWritable?.addCallbackAndRunD(t => {
src = t
})
if(typeof src !== "string") {
throw "Markdown.svelte got a non-string object"
}
</script>
{#if src?.length > 0}
{@html md.render(src)}
{/if}

View file

@ -263,7 +263,7 @@
{#if config.questionhint}
{#if config.questionHintIsMd}
<Markdown src={config.questionHint} />
<Markdown srcWritable={ config.questionhint.current} />
{:else}
<div class="max-h-60 overflow-y-auto">
<SpecialTranslation
@ -274,7 +274,7 @@
feature={selectedElement}
/>
</div>
{/if}
{/if}
{/if}
</legend>

View file

@ -8,6 +8,7 @@
import QuestionPreview from "./QuestionPreview.svelte"
import SchemaBasedMultiType from "./SchemaBasedMultiType.svelte"
import ShowConversionMessage from "./ShowConversionMessage.svelte"
import Markdown from "../Base/Markdown.svelte"
export let state: EditLayerState
export let schema: ConfigMeta
@ -97,9 +98,7 @@
<h3>{schema.path.at(-1)}</h3>
{#if subparts.length > 0}
<span class="subtle">
{schema.description}
</span>
<Markdown src={schema.description}/>
{/if}
{#if $currentValue === undefined}
No array defined

View file

@ -41,10 +41,11 @@
if (lastIsString) {
types.splice(types.length - 1, 1)
}
const configJson: QuestionableTagRenderingConfigJson = {
const configJson: QuestionableTagRenderingConfigJson & {questionHintIsMd: boolean}= {
id: "TYPE_OF:" + path.join("_"),
question: "Which subcategory is needed for " + schema.path.at(-1) + "?",
questionHint: nmd(schema.description),
questionHint: schema.description,
questionHintIsMd: true,
mappings: types
.map((opt) => opt.trim())
.filter((opt) => opt.length > 0)