-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,351 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<script lang="ts"> | ||
// Forked from: https://github.com/JanGuillermo/vue3-markdown-it | ||
import './katex.css' | ||
import MarkdownItKatex from '@traptitech/markdown-it-katex' | ||
import MarkdownIt from 'markdown-it' | ||
import MarkdownItAnchor from 'markdown-it-anchor' | ||
import MarkdownItDeflist from 'markdown-it-deflist' | ||
import MarkdownItFootnote from 'markdown-it-footnote' | ||
import MarkdownItTOC, {TocOptions} from 'markdown-it-toc-done-right' | ||
import {defineComponent, h, onMounted, PropType, ref, watch} from 'vue' | ||
// import MarkdownItMonacoHighlight from './markdown-it-monaco-highlight' | ||
export default defineComponent({ | ||
name: 'MarkdownIt', | ||
props: { | ||
source: { | ||
type: String, | ||
default: '', | ||
}, | ||
/** | ||
* Options for MarkdownItAnchor plugin | ||
*/ | ||
anchor: { | ||
type: Object as PropType<MarkdownItAnchor.AnchorOptions>, | ||
default: () => ({}), | ||
}, | ||
/** | ||
* Convert '\n' in paragraphs into <br> | ||
*/ | ||
breaks: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
/** | ||
* Enable HTML tags in source | ||
*/ | ||
html: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
/** | ||
* CSS language prefix for fenced blocks. Can be useful for external highlighters. | ||
*/ | ||
langPrefix: { | ||
type: String, | ||
default: 'language-', | ||
}, | ||
/** | ||
* Autoconvert URL-like text to links | ||
*/ | ||
linkify: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
/** | ||
* Options for MarkdownItTOC plugin | ||
*/ | ||
toc: { | ||
type: Object as PropType<TocOptions>, | ||
default: () => ({}), | ||
}, | ||
}, | ||
setup(props: any) { | ||
const md = ref() | ||
const renderMarkdown = () => { | ||
const markdown = new MarkdownIt() | ||
.use(MarkdownItAnchor, props.anchor) | ||
.use(MarkdownItDeflist) | ||
.use(MarkdownItFootnote) | ||
.use(MarkdownItKatex) | ||
// .use(MarkdownItMonacoHighlight) | ||
.use(MarkdownItTOC, props.toc) | ||
.set({ | ||
breaks: props.breaks, | ||
html: props.html, | ||
langPrefix: props.langPrefix, | ||
linkify: props.linkify, | ||
}) | ||
md.value = markdown.render(props.source) | ||
} | ||
onMounted(() => renderMarkdown()) | ||
watch(props, renderMarkdown) | ||
return () => h('entry', {class: ['MarkdownIt'], innerHTML: md.value}) | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// import {invoke} from '@vueuse/core' | ||
// import _ from 'lodash' | ||
// import MarkdownIt from 'markdown-it' | ||
// import {editor} from 'monaco-editor' | ||
|
||
// import {useMonacoEditor} from '../MonacoEditor' | ||
|
||
// const MarkdownItMonacoHighlight = (md: MarkdownIt) => { | ||
// useMonacoEditor() | ||
|
||
// const temp = md.renderer.rules.fence?.bind(md.renderer.rules) | ||
|
||
// if (!temp) throw new Error('Cannot retrieve fence function from MarkdownIt') | ||
|
||
// md.renderer.rules.fence = (tokens, idx, options, env, slf) => { | ||
// const token = tokens[idx] | ||
// const code = token.content.trim() | ||
|
||
// const uid = _.uniqueId('Markdown__highlight_') | ||
// token.attrPush(['id', uid]) | ||
|
||
// invoke(async () => { | ||
// editor.setTheme('custom-theme') | ||
// const html = await editor.colorize(code, 'glsl', {}) | ||
// const el = document.getElementById(uid) | ||
// if (el) el.innerHTML = html | ||
// }) | ||
|
||
// return temp(tokens, idx, options, env, slf) | ||
// } | ||
// } | ||
|
||
// export default MarkdownItMonacoHighlight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Markdown from './Markdown.vue' | ||
|
||
export default Markdown |
Oops, something went wrong.