feat: separate Markdown to a component

This commit is contained in:
Lin, Hung-Shin committed 2023-11-26 23:32:37 +08:00
1 parent abaacf7ee7
commit 8f31e4f2cd
3 files changed
+55 -41

No files matched your search

+8 -13
View File
@@ -1,7 +1,7 @@
<script setup>
import { ref, watch, computed } from 'vue'
import { ref, watch } from 'vue'
import sessionStore from '../store/session'
import markdown2HTML from '../utils/markdown'
import MarkdownText from './MarkdownText.vue'
const current = ref(-1)
watch(
@@ -23,12 +23,6 @@ const right = () => {
current.value += 1
}
}
const hints = computed(() => {
return sessionStore.session.hints.map((stageHints) =>
stageHints.map(markdown2HTML)
)
})
</script>
<template>
@@ -57,13 +51,13 @@ const hints = computed(() => {
<p class="inline text-text font-xl w-1/14 p-2 m-1">{{ current + 1 }}</p>
<p class="inline text-text font-xl w-1/14 p-2 m-1">/</p>
<p class="inline text-text font-xl w-1/14 p-2 m-1">
{{ hints.length }}
{{ sessionStore.session.hints.length }}
</p>
<button
class="p-2 m-1 w-1/8"
id="Rbutton"
@click="right"
:disabled="current === hints.length - 1"
:disabled="current === sessionStore.session.hints.length - 1"
>
<font-awesome-icon :icon="['fas', 'arrow-right']" class="text-text" />
</button>
@@ -72,11 +66,12 @@ const hints = computed(() => {
<div id="hint" class="bg-bg flex flex-wrap p-8">
<ul>
<li
v-for="hint in hints[current]"
v-for="hint in sessionStore.session.hints[current]"
:key="hint"
class="text-text font-xl whitespace-pre-wrap"
v-html="hint"
></li>
>
<MarkdownText :content="hint" />
</li>
</ul>
<br />
</div>
+38
View File
@@ -0,0 +1,38 @@
<script setup>
import { computed, defineProps } from 'vue'
import markdown2HTML from '../utils/markdown'
const props = defineProps({
content: {
type: String,
required: true,
},
})
const html = computed(() => {
return markdown2HTML(props.content)
})
</script>
<template>
<div class="markdown-content" v-html="html"></div>
</template>
<style scoped>
.markdown-content {
margin: 0;
padding: 0;
line-height: 1;
}
.markdown-content :deep(ol) {
list-style: decimal;
padding-left: 1em;
}
.markdown-content :deep(code) {
background-color: #282a33;
border-radius: 0.25rem;
padding: 0.25rem;
font-size: 0.875rem;
}
</style>
+9 -28
View File
@@ -1,11 +1,7 @@
<script setup>
import { computed } from 'vue'
import MarkdownText from './MarkdownText.vue'
import sessionStore from '../store/session'
import markdown2HTML from '../utils/markdown'
const instruction = computed(() => {
return markdown2HTML(sessionStore.quest.instruction)
})
const tasks = computed(() => {
return sessionStore.session.tasks.map((task) => {
@@ -14,7 +10,7 @@ const tasks = computed(() => {
return {
...task,
class: `${color} markdown-content`,
content: markdown2HTML(`${prefix} ${task.name}`),
content: `${prefix} ${task.name}`,
}
})
})
@@ -28,37 +24,22 @@ const tasks = computed(() => {
<br />
<div>
<div v-if="sessionStore.quest" class="whitespace-pre-wrap">
<p class="text-text markdown-content" v-html="instruction"></p>
<MarkdownText
class="text-text markdown-content"
:content="sessionStore.quest.instruction"
/>
<br />
<p id="tasks" class="text-text">
<!-- Tasks: -->
任務:
</p>
<ul v-if="sessionStore.session">
<li
v-for="task in tasks"
:key="task.id"
:class="task.class"
v-html="task.content"
></li>
<li v-for="task in tasks" :key="task.id">
<MarkdownText :class="task.class" :content="task.content" />
</li>
</ul>
</div>
<p class="text-text" v-else>Loading...</p>
</div>
</div>
</template>
<style scoped>
.markdown-content :deep(p) {
margin: 0;
color: 'red';
padding: 0;
}
.markdown-content :deep(code) {
background-color: #282a33;
border-radius: 0.25rem;
padding: 0.25rem;
font-size: 0.875rem;
}
</style>