mirror of
https://github.com/doocs/md.git
synced 2025-01-23 12:24:43 +08:00
Compare commits
3 Commits
fbe6421cbd
...
ef29242214
Author | SHA1 | Date | |
---|---|---|---|
|
ef29242214 | ||
|
1ab6cbfeb2 | ||
|
67ef9dc21c |
@ -64,6 +64,15 @@ const copyMode = useStorage(addPrefix(`copyMode`), `txt`)
|
|||||||
const source = ref(``)
|
const source = ref(``)
|
||||||
const { copy: copyContent } = useClipboard({ source })
|
const { copy: copyContent } = useClipboard({ source })
|
||||||
|
|
||||||
|
const creatEmptyNode = () => {
|
||||||
|
const node = document.createElement(`p`)
|
||||||
|
node.style.fontSize = `0`
|
||||||
|
node.style.lineHeight = `0`
|
||||||
|
node.style.margin = `0`
|
||||||
|
node.innerHTML = ` `
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
// 复制到微信公众号
|
// 复制到微信公众号
|
||||||
function copy() {
|
function copy() {
|
||||||
emit(`startCopy`)
|
emit(`startCopy`)
|
||||||
@ -107,13 +116,11 @@ function copy() {
|
|||||||
|
|
||||||
clipboardDiv.focus()
|
clipboardDiv.focus()
|
||||||
|
|
||||||
// edge case: 由于 svg 无法复制, 在前面插入一个空节点
|
// 由于 svg 无法复制, 在前后各插入一个空白节点
|
||||||
const p = document.createElement(`p`)
|
const beforeNode = creatEmptyNode()
|
||||||
p.style.fontSize = `0` // 设置字体大小为 0
|
const afterNode = creatEmptyNode()
|
||||||
p.style.lineHeight = `0` // 行高也为 0
|
clipboardDiv.insertBefore(beforeNode, clipboardDiv.firstChild)
|
||||||
p.style.margin = `0` // 避免外边距干扰
|
clipboardDiv.appendChild(afterNode)
|
||||||
p.innerHTML = ` `
|
|
||||||
clipboardDiv.insertBefore(p, clipboardDiv.firstChild)
|
|
||||||
|
|
||||||
// 兼容 Mermaid
|
// 兼容 Mermaid
|
||||||
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)
|
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)
|
||||||
|
@ -170,12 +170,15 @@ watch(isDark, () => {
|
|||||||
toRaw(editor.value)?.setOption?.(`theme`, theme)
|
toRaw(editor.value)?.setOption?.(`theme`, theme)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const charCount = ref(0)
|
||||||
|
|
||||||
// 初始化编辑器
|
// 初始化编辑器
|
||||||
function initEditor() {
|
function initEditor() {
|
||||||
const editorDom = document.querySelector<HTMLTextAreaElement>(`#editor`)!
|
const editorDom = document.querySelector<HTMLTextAreaElement>(`#editor`)!
|
||||||
|
|
||||||
if (!editorDom.value) {
|
if (!editorDom.value) {
|
||||||
editorDom.value = store.posts[store.currentPostIndex].content
|
editorDom.value = store.posts[store.currentPostIndex].content
|
||||||
|
charCount.value = store.posts[store.currentPostIndex].content.replace(/\s/g, ``).length
|
||||||
}
|
}
|
||||||
editor.value = CodeMirror.fromTextArea(editorDom, {
|
editor.value = CodeMirror.fromTextArea(editorDom, {
|
||||||
mode: `text/x-markdown`,
|
mode: `text/x-markdown`,
|
||||||
@ -222,7 +225,9 @@ function initEditor() {
|
|||||||
clearTimeout(changeTimer.value)
|
clearTimeout(changeTimer.value)
|
||||||
changeTimer.value = setTimeout(() => {
|
changeTimer.value = setTimeout(() => {
|
||||||
onEditorRefresh()
|
onEditorRefresh()
|
||||||
store.posts[store.currentPostIndex].content = e.getValue()
|
const value = e.getValue()
|
||||||
|
store.posts[store.currentPostIndex].content = value
|
||||||
|
charCount.value = value.replace(/\s/g, ``).length
|
||||||
}, 300)
|
}, 300)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -414,6 +419,7 @@ onMounted(() => {
|
|||||||
</ContextMenuContent>
|
</ContextMenuContent>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="relative flex-1">
|
||||||
<div
|
<div
|
||||||
id="preview"
|
id="preview"
|
||||||
ref="preview"
|
ref="preview"
|
||||||
@ -432,6 +438,10 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="bg-muted absolute bottom-0 left-0 p-2 text-xs shadow">
|
||||||
|
{{ charCount }} 个字符
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<CssEditor class="flex-1" />
|
<CssEditor class="flex-1" />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
Loading…
Reference in New Issue
Block a user