init project
This commit is contained in:
6
src/components/markdown-view/index.ts
Normal file
6
src/components/markdown-view/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import view from "./index.vue";
|
||||
import Toolkit from "~/utils/Toolkit";
|
||||
import "./style.less";
|
||||
|
||||
export const MarkdownView = Toolkit.withInstall(view);
|
||||
export default MarkdownView;
|
||||
42
src/components/markdown-view/index.vue
Normal file
42
src/components/markdown-view/index.vue
Normal file
@@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<div
|
||||
class="tui-markdown-view selectable break-all line-numbers"
|
||||
v-html="markdownHTML"
|
||||
:data-max-height="maxHeight"
|
||||
></div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import Prism from "prismjs";
|
||||
import Markdown from "~/utils/Markdown";
|
||||
|
||||
defineOptions({
|
||||
name: "MarkdownView"
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
content?: string;
|
||||
showCodeBorder?: boolean;
|
||||
maxHeight?: string;
|
||||
}>(), {
|
||||
content: "",
|
||||
showCodeBorder: true,
|
||||
maxHeight: "400px"
|
||||
});
|
||||
const { content } = toRefs(props);
|
||||
const markdownHTML = ref("");
|
||||
|
||||
const doRender = async () => {
|
||||
markdownHTML.value = await Markdown.getInstance().toHTML(content.value);
|
||||
await nextTick();
|
||||
Prism.highlightAll();
|
||||
};
|
||||
|
||||
watch(() => props.content, doRender);
|
||||
onMounted(doRender);
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.tui-markdown-view {
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
341
src/components/markdown-view/style.less
Normal file
341
src/components/markdown-view/style.less
Normal file
@@ -0,0 +1,341 @@
|
||||
@import url(~/assets/style/variable);
|
||||
|
||||
.tui-markdown-view {
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
margin: 2rem 0 .5rem 0;
|
||||
padding: .25rem 1rem;
|
||||
position: relative;
|
||||
border-left: .4rem solid var(--tui-light-blue);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
p:first-child,
|
||||
h1:first-child,
|
||||
h2:first-child,
|
||||
h3:first-child,
|
||||
h4:first-child,
|
||||
h5:first-child,
|
||||
h6:first-child {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1:hover a.anchor,
|
||||
h2:hover a.anchor,
|
||||
h3:hover a.anchor,
|
||||
h4:hover a.anchor,
|
||||
h5:hover a.anchor,
|
||||
h6:hover a.anchor {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
h2 a,
|
||||
h3 a {
|
||||
color: #34495E;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
h5 {
|
||||
font-size: .8rem;
|
||||
}
|
||||
|
||||
h6 {
|
||||
color: #777;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
p,
|
||||
ul,
|
||||
ol,
|
||||
dl,
|
||||
table,
|
||||
blockquote {
|
||||
margin: .5rem 0;
|
||||
min-height: 2em;
|
||||
}
|
||||
|
||||
p {
|
||||
text-indent: 2em;
|
||||
}
|
||||
|
||||
blockquote p {
|
||||
text-indent: 0;
|
||||
}
|
||||
|
||||
code {
|
||||
padding: .2em .5em;
|
||||
background: #EEE;
|
||||
box-sizing: border-box;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
li > ol,
|
||||
li > ul {
|
||||
margin: 0 0;
|
||||
}
|
||||
|
||||
li > p {
|
||||
text-indent: 0;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 2px;
|
||||
margin: 16px 0;
|
||||
border: 0 none;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background: #E7E7E7;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
h1 p,
|
||||
h2 p,
|
||||
h3 p,
|
||||
h4 p,
|
||||
h5 p,
|
||||
h6 p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
li p.first {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
ul:first-child,
|
||||
ol:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
ul:last-child,
|
||||
ol:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: disc;
|
||||
}
|
||||
|
||||
video {
|
||||
width: 100%;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 520px;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
padding: 2px 10px;
|
||||
background: rgba(153, 153, 153, .1);
|
||||
border-left: 4px solid #EDEDED;
|
||||
}
|
||||
|
||||
table {
|
||||
padding: 0;
|
||||
margin: 0 auto;
|
||||
min-width: 240px;
|
||||
max-width: 100%;
|
||||
word-break: initial;
|
||||
border-spacing: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table thead {
|
||||
background: #F2F2F2;
|
||||
}
|
||||
|
||||
table tr {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-top: 1px solid #DFE2E5;
|
||||
}
|
||||
|
||||
table tr:nth-child(2n) {
|
||||
background-color: #FAFAFA;
|
||||
}
|
||||
|
||||
table tr th {
|
||||
border: 1px solid #DFE2E5;
|
||||
margin: 0;
|
||||
padding: 2px 13px;
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
table tr td {
|
||||
border: 1px solid #DFE2E5;
|
||||
margin: 0;
|
||||
padding: 0 13px;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
text-align: left;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
table tr th:first-child,
|
||||
table tr td:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
table tr th:last-child,
|
||||
table tr td:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
tt {
|
||||
color: #e96900;
|
||||
padding: 2px 4px;
|
||||
font-size: 0.92rem;
|
||||
background: #F8F8F8;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
tt {
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.border {
|
||||
border: 1px solid #525870;
|
||||
}
|
||||
|
||||
.media {
|
||||
margin: .5rem auto;
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
|
||||
+ .media-tips {
|
||||
color: #777;
|
||||
display: block;
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
// 代码
|
||||
pre[class*="language-"] {
|
||||
border: 1px solid #B8BBC9;
|
||||
padding: 0 !important;
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
font-size: 14px;
|
||||
background: transparent;
|
||||
max-height: var(data-max-height);
|
||||
transition: max-height .5s var(--tui-bezier);
|
||||
font-family: var(--td-font-family);
|
||||
line-height: 1;
|
||||
border-radius: 0;
|
||||
|
||||
code {
|
||||
color: #333;
|
||||
background: transparent;
|
||||
text-shadow: none !important;
|
||||
font-family: var(--td-font-family);
|
||||
|
||||
.line-numbers-rows {
|
||||
left: 0;
|
||||
float: left;
|
||||
z-index: 1;
|
||||
position: sticky;
|
||||
background: rgba(242, 242, 242, .9);
|
||||
letter-spacing: 1px;
|
||||
|
||||
>span::before {
|
||||
padding-right: .2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.codes {
|
||||
position: absolute;
|
||||
min-width: calc(100% - 4.6em);
|
||||
padding-right: .5em;
|
||||
|
||||
.token.namespace {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.token.constant {
|
||||
color: #FF7A9B;
|
||||
}
|
||||
|
||||
.token.annotation {
|
||||
color: purple;
|
||||
}
|
||||
|
||||
.token.function {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.token.class-name {
|
||||
color: #FF461F;
|
||||
}
|
||||
|
||||
.token.generics .class-name {
|
||||
color: #895532;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.comment {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.token.string {
|
||||
color: #55AA55;
|
||||
}
|
||||
|
||||
.token.number {
|
||||
color: #EB9354;
|
||||
}
|
||||
|
||||
.token.keyword,
|
||||
.token.boolean {
|
||||
color: #177CB0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user