Compare commits

...

3 Commits

Author SHA1 Message Date
YangFong
36dd217d92
Merge 67ef9dc21c into 23de6453a3 2024-12-25 08:24:05 +08:00
Libin YANG
23de6453a3
fix: render tab to spaces (#498)
Some checks failed
Build and Deploy / build-and-deploy (push) Has been skipped
Build and Push Docker Images / build (push) Failing after 32s
#497
2024-12-24 11:55:57 +08:00
YangFong
67ef9dc21c feat: display character count 2024-12-21 14:18:01 +08:00
2 changed files with 26 additions and 14 deletions

View File

@ -174,6 +174,8 @@ export function initRenderer(opts: IOpts) {
const langText = lang.split(` `)[0]
const language = hljs.getLanguage(langText) ? langText : `plaintext`
let highlighted = hljs.highlight(text, { language }).value
// tab to 4 spaces
highlighted = highlighted.replace(/\t/g, ' ')
highlighted = highlighted
.replace(/\r\n/g, `<br/>`)
.replace(/\n/g, `<br/>`)

View File

@ -170,12 +170,15 @@ watch(isDark, () => {
toRaw(editor.value)?.setOption?.(`theme`, theme)
})
const charCount = ref(0)
//
function initEditor() {
const editorDom = document.querySelector<HTMLTextAreaElement>(`#editor`)!
if (!editorDom.value) {
editorDom.value = store.posts[store.currentPostIndex].content
charCount.value = store.posts[store.currentPostIndex].content.replace(/\s/g, ``).length
}
editor.value = CodeMirror.fromTextArea(editorDom, {
mode: `text/x-markdown`,
@ -222,7 +225,9 @@ function initEditor() {
clearTimeout(changeTimer.value)
changeTimer.value = setTimeout(() => {
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)
})
@ -414,6 +419,7 @@ onMounted(() => {
</ContextMenuContent>
</ContextMenu>
</div>
<div class="relative flex-1">
<div
id="preview"
ref="preview"
@ -432,6 +438,10 @@ onMounted(() => {
</div>
</div>
</div>
<div class="bg-muted absolute bottom-0 left-0 p-2 text-xs shadow">
{{ charCount }} 个字符
</div>
</div>
<CssEditor class="flex-1" />
</div>
</main>