Git Product home page Git Product logo

vuetify-markdown-editor's Introduction

vuetify-markdown-editor

npm version npm downloads GitHub

A Vue.js Component for editing and previewing markdown using Vuetify.js and markdown-it.

Install

npm install vuetify-markdown-editor

Since this component is based on Vuetify, it is required to install and configure Vuetify. For installing Vuetify, please visit https://vuetifyjs.com/en/getting-started/quick-start.

Features

  • TypeScript support
  • Solo and inline mode
  • Editor-only and Editor-Preview mode
  • Code highlighting
  • Emoji picking
  • Math formula (See markdown-it-texmath)
  • Image uploading and previewing (to use uploaded image in markdown, use the filename as the link)
  • Mermaid diagram rendering (use code block with language mermaid)

TODO

  • Fix SSR
  • Allow to change sets of emoji
  • Add typescript support
  • Add copy icon
  • Add viewer mode
  • Fix large image
  • Add self-hosted emoji images
  • Add emoji rendering in rendered text
  • Add more WYSIWYG functions
  • Add plantuml support

Usage

This package can be used in Node.js module:

<template>
  <v-app>
    <Editor
      mode="preview"
      ref="editor"
      hint="Hint"
      :outline="false"
      :render-config="renderConfig"
      v-model="text"
    />
  </v-app>
</template>

<script>
import { Editor } from "vuetify-markdown-editor";
import { VApp } from 'vuetify/lib';

export default {
  name: "app",
  components: {
    Editor,
    VApp
  },
  data() {
    return {
      text: "",
      renderConfig: {
        // Mermaid config
        mermaid: {
          theme: "dark"
        }
      }
    };
  },
  mounted() {
    // Access properties or methods using $refs
    // this.$refs.editor.focus();
    // this.$refs.editor.upload();

    // Dark theme
    this.$vuetify.theme.dark = true;
  }
};
</script>

To show the rendered html only, use viewer mode.

To use the markdown-it renderer directly, use createRenderer to create it.

Exported modules

  • Editor: a vue component to edit markdown
  • createRenderer: a function to create a markdown-it render

Props

Prop Default Description
value '' String that binds to the textarea
mode 'preview' Possible value 'editor', 'preview' or 'viewer'. When set to 'editor' or 'viewer', only the editor or viewer is displayed, while 'preview' mode displays both.
renderConfig undefined Override default configurations
outline false The border will be outlined instead of card style
color undefined The outline and icon's color
nativeEmoji false Use native emoji instead of pictures
emoji true Enable emoji input
emojiSet "apple" Supported emoji sets: 'apple', 'google', 'twitter', 'facebook'
image true Enable image upload
fileTarget '/' Image upload target uri
fileFilter file => file.type.startsWith('image') Allow only specific files. Return true to allow, false to reject
baseUrl '/' The baseUrl for uploaded images. Must end with a slash (mainly used in viewer mode)

Other props that are not listed in the above table will be directly passed to v-textarea, which enables you to set the native props in v-textarea.

Default Renderer Configurations

{
  // markdown-it-texmath config
  texmath: undefined,
  // markdown-it-highlightjs config
  hightlightjs: undefined,
  // markdown-it-code-copy config
  codeCopy: {
    buttonClass: 'v-icon theme--dark'
  },
  // The native mermaid config
  mermaid: undefined,
  // Markdown-it config
  markdownIt: undefined
}

Methods

Method Description
upload() Start or resume uploading all files in list
pause() Pause uploading
resume() Resume uploading
focus() Focus on the editor

Properties

Property Description
files Get all files in list in FlowFile format

Test

Clone this repository, and then run:

npm install
npm run serve

Then open http://localhost:8080 in browser to test.

Screenshots

Solo mode: <Editor v-model="text" />

Solo

Dark mode: this.$vuetify.theme.dark = true;

Dark

Outline mode: <Editor outline v-model="text" />

Outline

Dependencies

License

MIT License

vuetify-markdown-editor's People

Contributors

dcsunset avatar dependabot[bot] avatar marcotribuz avatar tony080 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vuetify-markdown-editor's Issues

add more plugins dynamically

Is there a way to add more plugins dinamically?

for instance I use markdown-it-checkbox I would need to a dynamic way to expose markdown-it, to call .use() on this plugin instance

is this available in some way?

What about adding table?

Can we make this component render table while text on md file is,

Command Description
hydra -P password-file.txt -v $ip snmp Hydra brute force against SNMP

And this would lead to a simple table??

Only resizable editor's textarea vertically

this issue apears in Vuetify version 2.6.0
image

my package-lock.json

"packages": {
    "": {
      "name": "my-app",
      "version": "0.1.0",
      "dependencies": {
        "core-js": "^3.8.3",
        "vue": "^2.6.14",
        "vue-router": "^3.5.1",
        "vuetify": "^2.6.0",
        "vuetify-markdown-editor": "^3.3.3",
        "vuex": "^3.6.2"
      },

MdTest.Vue

<template>
  <div>
    
    <Editor v-model="tcData" />
  </div>
</template>

<script>
import { Editor } from "vuetify-markdown-editor";

export default {
  name: 'MdTest',
  components: {
    Editor,
  },
  data() {
    return {
      tcData: "",
    };
  },
}
</script>

Originally posted by @jkpark in #8 (comment)

[Vue warn]: Unknown custom element: <> - did you register the component correctly?

<template>
  <v-app>
    <navbar></navbar>
     This is the create article page.
    <markdown-editor
      mode="Rendered"
      ref="editor"
      hint="Test"
      nativeEmoji
      :outline="false"
      :preview="true"
      v-model="text"
      />
  </v-app>
</template>

<script>
import navbar from "../components/Navbar";
import { Editor } from "vuetify-markdown-editor";
import "vuetify-markdown-editor/dist/vuetify-markdown-editor.css";

export default {
  name: 'CreateArticlePage',
  components: {
    navbar,
    'markdown-editor': Editor,
  },
  data() {
    return {
      text: ''
    };
  },
  mounted() {
    // Access properties or methods using $refs
    //console.info(Vue.config.components)
    // this.$refs.editor.focus()
    // this.$refs.editor.upload();

    // Dark theme
    //this.$vuetify.theme.dark = true;
  }
};
</script>

That is my CreateArticlePage.vue in /views, vue cli.
I have installed the module by npm install.
Everything works fine during npm run serve...
When open the web page, the editor is invisible, and the browser console output such errors.

[Vue warn]: Unknown custom element: <v-container> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

[Vue warn]: Unknown custom element: <v-row> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

[Vue warn]: Unknown custom element: <v-col> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

etc.

I thought the key is I register the component wrongly. But I try for many times, like reinstall, import in global App.vue or man.js. Still get this trouble.

Besides, the cloned demo works all fine. I can only see the editor in that demo.

I have looking for solving for two days, but get noting. I am a noob of Vue and Vuetify, and this is my first issue in github. Can you give me some suggestions

"invalid regular expression flag s"

Hi,

npm v 6.14.4

node v 13.12.0

Git cloned repo

ran npm i && npm run serve

Nothing works either by using the git or by importing the module to another project,

Screen hangs and I get a console error:

[Vue warn]: Error in getter for watcher "compiled": "SyntaxError: invalid regular expression flag s"

found in

---> at src/components/MarkdownEditor.vue

at src/App.vue

Seems to point to line 226 in MarkdownEditor component:

let compiled = render(
				this.value,
				this.renderOptions,
				_.merge(this.renderConfig, copyConfig),
				cache
			);

anyone knows how to fix this?

How can I set initial number of rows of the v-textarea on the Editor?

Thank you for your great job! This editor is so helpful!

This is one help request, Is there any way to set the initial row number of v-textarea on the Editor from the App?

For example;

<Editor
  mode="preview"
  ref="editor"

  rows="1"

   hint="Hint"
  :outline="false"
  :render-config="renderConfig"
  v-model="text"
/>

Then, rows="1" affect to the initial row number of v-textarea on the Editor as follows:

<v-textarea
	solo
	flat
	:counter="counter"

	rows="1"

Thank you for your kindly help!

Module not found: Error: Can't resolve 'vuetify-markdown-editor'

My script tag looks as follows:

import { Editor } from 'vuetify-markdown-editor'
import 'vuetify-markdown-editor/dist/vuetify-markdown-editor.css'
export default {
  name: 'BlogpostCreator',
  components: { Editor },
  data () {
    return {
      title: '',
      content: ''
    }
  }
}

which renders:

Failed to compile.

./src/components/UI/BlogpostCreator.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UI/BlogpostCreator.vue?vue&type=script&lang=js&)
Module not found: Error: Can't resolve 'vuetify-markdown-editor' in '/Users/divebox/Documents/01 Programming/01 Websites/08 Portfolio Website/portfolio-website/src/components/UI'

Any suggestions what I did wrong?

Katex breaks the editor

Hey I encountered this when I was writing some code blocks in the Editor:

As soon as there are two "$" characters spread somewhere in the text, Katex will go nuts and break the whole editor. As in it will not respond until the site is reloaded. It will throw:

[Vue warn]: Error in getter for watcher "compiled": "ParseError: KaTeX parse error: Expected 'EOF', got '&' at position 112: …sponse</span> =&̲gt;</span> {

I could fix it with a workaround of using the following render config:

renderConfig: {
        katex: {
          // formula delimiters
          delimiters: [
            {
              left: '$$$',
              right: '$$$',
              options: {
                displayMode: true // block
              }
            },
            {
              left: '\\[',
              right: '\\]',
              options: {
                displayMode: true // block
              }
            },
            {
              left: '$$',
              right: '$$',
              options: {
                displayMode: false // inline
              }
            },
            {
              left: '\\(',
              right: '\\)',
              options: {
                displayMode: false // inline
              }
            }
          ]
        },
        mermaid: undefined // The native mermaid config
      }

Which just changes the Katex prefixes so that the single "$" characters are ignored. If I actually try to write any LaTeX, the Editor will instantly break down with various error messages.

About a glitch and a request

glitch is:
1

the width of editor get reduced.

request:
could you add a prop for words counter and an event if the words is out of limits, would emit an event?

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.