All Projects → letranloc → draft-js-katex-plugin

letranloc / draft-js-katex-plugin

Licence: other
A Katex plugin for DraftJS.

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to draft-js-katex-plugin

Megadraft
Megadraft is a Rich Text editor built on top of Facebook's Draft.JS featuring a nice default base of components and extensibility
Stars: ✭ 982 (+2875.76%)
Mutual labels:  draft-js
Yoyo
A dead simple comment engine built on top of AWS lambda and React, alternative comment service to Disqus.
Stars: ✭ 210 (+536.36%)
Mutual labels:  draft-js
KaTeXView
KaTeX View for android
Stars: ✭ 43 (+30.3%)
Mutual labels:  katex
Z Editor
Online Z-notations Editor with Draft.js and React.js
Stars: ✭ 99 (+200%)
Mutual labels:  draft-js
React Tapable Editor
A pluginable, intuitive medium/notion like rich text editor(currently in wip)
Stars: ✭ 170 (+415.15%)
Mutual labels:  draft-js
React Text Selection Popover
Selection based Text UI made easy
Stars: ✭ 245 (+642.42%)
Mutual labels:  draft-js
Dante2
A complete rewrite of dante editor in draft-js
Stars: ✭ 890 (+2596.97%)
Mutual labels:  draft-js
draftjs
Draft.js exporter for Go
Stars: ✭ 22 (-33.33%)
Mutual labels:  draft-js
Awesome Draft Js
Awesome list of Draft.js resources
Stars: ✭ 2,379 (+7109.09%)
Mutual labels:  draft-js
wagtaildraftail
🐦📝🍸 Draft.js editor for Wagtail, built upon Draftail and draftjs_exporter
Stars: ✭ 23 (-30.3%)
Mutual labels:  draft-js
Draft Extend
Build extensible Draft.js editors with configurable plugins and integrated serialization.
Stars: ✭ 109 (+230.3%)
Mutual labels:  draft-js
Medium Draft
📝 A medium like Rich Text Editor built on draft-js with a focus on keyboard shortcuts.
Stars: ✭ 1,705 (+5066.67%)
Mutual labels:  draft-js
Draft Js Markdown Shortcuts Plugin
A DraftJS plugin for supporting Markdown syntax shortcuts
Stars: ✭ 252 (+663.64%)
Mutual labels:  draft-js
Gatsby Starter Procyon
An opinionated Gatsby starter designed for trash-eating pandas.
Stars: ✭ 88 (+166.67%)
Mutual labels:  draft-js
notes
Simple text editor for your Markdown and LaTeX notes.
Stars: ✭ 24 (-27.27%)
Mutual labels:  katex
React Lz Editor
A multilingual react rich-text editor component includes media support such as texts, images, videos, audios, links etc. Development based on Draft-Js and Ant-design, good support html, markdown, draft-raw mode. 一款基于 draft-Js 和 ant-design 实现的 react 富文本编辑器组件,支持文本、图片、视频、音频、链接等元素插入,同时支持HTML、markdown、draft Raw格式。
Stars: ✭ 894 (+2609.09%)
Mutual labels:  draft-js
Mui Rte
Material-UI Rich Text Editor and Viewer
Stars: ✭ 233 (+606.06%)
Mutual labels:  draft-js
react-katex
Display math in TeX with KaTeX and ReactJS
Stars: ✭ 135 (+309.09%)
Mutual labels:  katex
downwrite
✍️ Markdown writing application that's down right, neat.
Stars: ✭ 103 (+212.12%)
Mutual labels:  draft-js
katex-rs
Rust bindings to KaTeX
Stars: ✭ 91 (+175.76%)
Mutual labels:  katex

DraftJS KaTeX Plugin

This is a plugin for the draft-js-plugins-editor.

This plugin insert and render LaTeX using KaTeX, modified from TeX example.

NPM

Usage

Add MathQuill libs if you want to use MathInput:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.min.js"></script>

Add plugin

import createKaTeXPlugin from 'draft-js-katex-plugin';
import katex from 'katex'

const kaTeXPlugin = createKaTeXPlugin({katex});

const { InsertButton } = kaTeXPlugin;

With MathInput:

import createKaTeXPlugin from 'draft-js-katex-plugin';
import katex from 'katex'
import MathInput from '../src/components/math-input/components/app';


const kaTeXPlugin = createKaTeXPlugin({katex, MathInput});

const { InsertButton } = kaTeXPlugin;

There are more examples in the stories/index.js file.

Configuration options:

Here shown with defaults:

{
    katex, // the katex object or a wrapper defining render() and __parse().

    doneContent: {    
        valid: 'Done',
        invalid: 'Invalid TeX',
    },
    
    MathInput: null, // Sett to the MathInput element to use MathInput
    removeContent: 'Remove',
    theme: {
        // CSS classes, either you define them or they come from the plugin.css import
        saveButton: '',
        removeButton: '',
        invalidButton: '',
        buttons: '',
    }
    // function (string) -> string. 
    translator: null, 
}

Loading katex async

If you want to load katex in the background instead of right away, then you can do this by wrapping the katex object that you pass into the plugin:

//file: asyncKatex.js
let katex = null
const renderQueue = []

System.import(/* webpackChunkName: 'katex' */ 'katex')
  .then(function methodName(module) {
    katex = module.default
  })
  .then(() => {
    console.log('Katex loaded, ', renderQueue)
    if (renderQueue.length) {
      const now = Date.now()
      renderQueue.map(([d, expression, baseNode, options]) => {
        if (now - d < 4000) {
          katex.render(expression, baseNode, options)
        }
      })
    }
  })

export default {
  render: (expression, baseNode, options) => {
    if (katex) {
      return katex.render(expression, baseNode, options)
    }

    renderQueue.push([Date.now(), expression, baseNode, options])
  },
  // parse is only used by this plugin to check syntax validity.
  __parse: (expression, options) => {
    if (katex) {
      return katex.parse(expression, options)
    }
    return null
  }
}

Store this in a separate file and and pass it to the plugin config:

import createKaTeXPlugin from 'draft-js-katex-plugin';
import katex from './asyncKatex'

const kaTeXPlugin = createKaTeXPlugin({katex});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].