Coder Social home page Coder Social logo

Comments (4)

F-loat avatar F-loat commented on May 23, 2024 2
<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.

akFace avatar akFace commented on May 23, 2024

谢谢,解决问题了,段落就是文章的段落啊

from vue-simplemde.

F-loat avatar F-loat commented on May 23, 2024

嗯,那段落数可能也得用正则匹配来计算,可以对 content 匹配下 \n 这个字符

from vue-simplemde.

akFace avatar akFace commented on May 23, 2024

ok

from vue-simplemde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.