Comments (4)
<template>
<markdown-editor v-model="content"></markdown-editor>
</template>
<script>
import markdownEditor from 'vue-simplemde/src/markdown-editor';
// wordCount这个函数是simplemde源码里的
function wordCount(data) {
const pattern = /[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
const m = data.match(pattern);
let count = 0;
if (m === null) return count;
for (let i = 0; i < m.length; i++) {
if (m[i].charCodeAt(0) >= 0x4E00) {
count += m[i].length;
} else {
count += 1;
}
}
return count;
}
export default {
name: 'demo',
components: {
markdownEditor,
},
data() {
return {
content: '',
};
},
computed: {
simplemde() {
return this.$refs.markdownEditor.simplemde;
},
},
};
</script>
// 获取行数
this.simplemde.codemirror.lineCount();
// 获取字数
this.content.length;
// 获取单词数
wordCount(this.content);
不太清楚你说的段落数是指什么,这个编辑器默认是会忽略空行的
更正:markdown语法里,一次换行会生成一个 br
标签,两次及以上换行会生成新段落(即 p
标签)
from vue-simplemde.
谢谢,解决问题了,段落就是文章的段落啊
from vue-simplemde.
嗯,那段落数可能也得用正则匹配来计算,可以对 content
匹配下 \n
这个字符
from vue-simplemde.
ok
from vue-simplemde.
Related Issues (20)
- @input event never fire HOT 1
- Editor not working. Showing regular textarea field HOT 2
- @input event not firing HOT 1
- Vue2.6.x导入VueSimplemde时出现报错 xxx is not exported from package HOT 2
- support for emojis
- marked is not a function
- Cannot enable code highlight HOT 1
- Displaying the rendered markdown without going fullscreen.
- Focusing Element needed HOT 1
- 请问是否删除了 vue-simplemde/src/markdown-editor ? HOT 2
- Vetur & typescript: Cannot find module 'vue-simplemde'. Vetur(2307) HOT 1
- modelVal not updating on model change HOT 3
- Changing the config setup in initialise to the spread operator broke in IE HOT 4
- How do you clear the vue-simplemde after axios.post method? HOT 1
- 怎么使用单纯的查看模式 HOT 3
- v-model is broken HOT 4
- Question: customising button bar HOT 1
- Add changelog.md
- vue-simplemde 支持vue3吗 HOT 1
- Updating modelValue from outside of the editor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-simplemde.