mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: display markdown to html
This commit is contained in:
1 parent
ebd81f7cb4
commit
abaacf7ee7
5 files changed
+72
-18
No files matched your search
@@ -20,7 +20,9 @@
|
|||||||
"@linux-odyssey/file-graph": "*",
|
"@linux-odyssey/file-graph": "*",
|
||||||
"@linux-odyssey/utils": "*",
|
"@linux-odyssey/utils": "*",
|
||||||
"axios": "^1.6.0",
|
"axios": "^1.6.0",
|
||||||
|
"dompurify": "^3.0.6",
|
||||||
"echarts": "^5.4.3",
|
"echarts": "^5.4.3",
|
||||||
|
"marked": "^10.0.0",
|
||||||
"socket.io-client": "^4.7.1",
|
"socket.io-client": "^4.7.1",
|
||||||
"validator": "^13.11.0",
|
"validator": "^13.11.0",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.3.4",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch, computed } from 'vue'
|
||||||
import sessionStore from '../store/session'
|
import sessionStore from '../store/session'
|
||||||
|
import markdown2HTML from '../utils/markdown'
|
||||||
|
|
||||||
const current = ref(-1)
|
const current = ref(-1)
|
||||||
watch(
|
watch(
|
||||||
@@ -22,6 +23,12 @@ const right = () => {
|
|||||||
current.value += 1
|
current.value += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hints = computed(() => {
|
||||||
|
return sessionStore.session.hints.map((stageHints) =>
|
||||||
|
stageHints.map(markdown2HTML)
|
||||||
|
)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -50,13 +57,13 @@ const right = () => {
|
|||||||
<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">{{ 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">/</p>
|
||||||
<p class="inline text-text font-xl w-1/14 p-2 m-1">
|
<p class="inline text-text font-xl w-1/14 p-2 m-1">
|
||||||
{{ sessionStore.session.hints.length }}
|
{{ hints.length }}
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
class="p-2 m-1 w-1/8"
|
class="p-2 m-1 w-1/8"
|
||||||
id="Rbutton"
|
id="Rbutton"
|
||||||
@click="right"
|
@click="right"
|
||||||
:disabled="current === sessionStore.session.hints.length - 1"
|
:disabled="current === hints.length - 1"
|
||||||
>
|
>
|
||||||
<font-awesome-icon :icon="['fas', 'arrow-right']" class="text-text" />
|
<font-awesome-icon :icon="['fas', 'arrow-right']" class="text-text" />
|
||||||
</button>
|
</button>
|
||||||
@@ -65,12 +72,11 @@ const right = () => {
|
|||||||
<div id="hint" class="bg-bg flex flex-wrap p-8">
|
<div id="hint" class="bg-bg flex flex-wrap p-8">
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
<li
|
||||||
v-for="hint in sessionStore.session.hints[current]"
|
v-for="hint in hints[current]"
|
||||||
:key="hint"
|
:key="hint"
|
||||||
class="text-text font-xl whitespace-pre-wrap"
|
class="text-text font-xl whitespace-pre-wrap"
|
||||||
>
|
v-html="hint"
|
||||||
{{ hint }}
|
></li>
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
import sessionStore from '../store/session'
|
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) => {
|
||||||
|
const prefix = task.completed ? '✓' : '➤'
|
||||||
|
const color = task.completed ? 'text-text-primary' : 'text-text'
|
||||||
|
return {
|
||||||
|
...task,
|
||||||
|
class: `${color} markdown-content`,
|
||||||
|
content: markdown2HTML(`${prefix} ${task.name}`),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -10,26 +28,37 @@ import sessionStore from '../store/session'
|
|||||||
<br />
|
<br />
|
||||||
<div>
|
<div>
|
||||||
<div v-if="sessionStore.quest" class="whitespace-pre-wrap">
|
<div v-if="sessionStore.quest" class="whitespace-pre-wrap">
|
||||||
<p class="text-text">{{ sessionStore.quest.instruction }}</p>
|
<p class="text-text markdown-content" v-html="instruction"></p>
|
||||||
<br />
|
<br />
|
||||||
<p id="tasks" class="text-text">
|
<p id="tasks" class="text-text">
|
||||||
<!-- Tasks: -->
|
<!-- Tasks: -->
|
||||||
任務:
|
任務:
|
||||||
</p>
|
</p>
|
||||||
<ul v-if="sessionStore.session">
|
<ul v-if="sessionStore.session">
|
||||||
<li v-for="task in sessionStore.session.tasks" :key="task.id">
|
<li
|
||||||
<p v-if="task.completed" class="text-text-primary">
|
v-for="task in tasks"
|
||||||
<span class=""> ✓</span>
|
:key="task.id"
|
||||||
{{ task.name }}
|
:class="task.class"
|
||||||
</p>
|
v-html="task.content"
|
||||||
<p v-else class="text-text">
|
></li>
|
||||||
<span class="">➤</span>
|
|
||||||
{{ task.name }}
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-text" v-else>Loading...</p>
|
<p class="text-text" v-else>Loading...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</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>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { marked } from 'marked'
|
||||||
|
import DOMPurify from 'dompurify'
|
||||||
|
|
||||||
|
export default function markdown2HTML(markdown) {
|
||||||
|
const html = marked.parse(markdown)
|
||||||
|
return DOMPurify.sanitize(html)
|
||||||
|
}
|
||||||
@@ -2404,6 +2404,11 @@ dom-accessibility-api@^0.5.9:
|
|||||||
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz#5a7429e6066eb3664d911e33fb0e45de8eb08453"
|
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz#5a7429e6066eb3664d911e33fb0e45de8eb08453"
|
||||||
integrity sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==
|
integrity sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==
|
||||||
|
|
||||||
|
dompurify@^3.0.6:
|
||||||
|
version "3.0.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.0.6.tgz#925ebd576d54a9531b5d76f0a5bef32548351dae"
|
||||||
|
integrity sha512-ilkD8YEnnGh1zJ240uJsW7AzE+2qpbOUYjacomn3AvJ6J4JhKGSZ2nh4wUIXPZrEPppaCLx5jFe8T89Rk8tQ7w==
|
||||||
|
|
||||||
dotenv@^16.3.1:
|
dotenv@^16.3.1:
|
||||||
version "16.3.1"
|
version "16.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
|
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
|
||||||
@@ -4691,6 +4696,11 @@ makeerror@1.0.12:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tmpl "1.0.5"
|
tmpl "1.0.5"
|
||||||
|
|
||||||
|
marked@^10.0.0:
|
||||||
|
version "10.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/marked/-/marked-10.0.0.tgz#7fe1805bb908433d760e2de0fcc8841a2b2d745c"
|
||||||
|
integrity sha512-YiGcYcWj50YrwBgNzFoYhQ1hT6GmQbFG8SksnYJX1z4BXTHSOrz1GB5/Jm2yQvMg4nN1FHP4M6r03R10KrVUiA==
|
||||||
|
|
||||||
media-typer@0.3.0:
|
media-typer@0.3.0:
|
||||||
version "0.3.0"
|
version "0.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||||
|
|||||||
Reference in new issue
Block a user