Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anishmprasad/mathex
A Mathematical Expression Composer for CKEditor
https://github.com/anishmprasad/mathex
ckeditor ckeditor-plugin ckeditor4 mathex
Last synced: about 9 hours ago
JSON representation
A Mathematical Expression Composer for CKEditor
- Host: GitHub
- URL: https://github.com/anishmprasad/mathex
- Owner: anishmprasad
- License: gpl-2.0
- Created: 2018-07-27T12:16:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-16T17:27:57.000Z (about 4 years ago)
- Last Synced: 2025-01-01T08:42:07.090Z (about 2 months ago)
- Topics: ckeditor, ckeditor-plugin, ckeditor4, mathex
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MathEx
A CKEditor Plugin for MathML and Latex Mathemathical Expressions
Editor accepted string format from input
Download mathex plugin from [CKEditor Addons](https://ckeditor.com/cke4/addon/MathEx)
default class was math if you change this you need to configure through ``` mathexClass ```
```html
\({ MathML or Tex Mathemathical expressions }\)
```
Encoder Helper
``` let str = "a+b2" ```
``` this helper function added escape character before and html Decode for editor readable format ```
``` decoder(str) // \( >math<>mrow<>msup<>mfenced<>mrow<>mi<a>/mi<>mo<+>/mo<>mi<b>/mi<>/mrow<>/mfenced<>mn>2>/mn<>/msup<>/mrow<>/math> \) ```
```javascript
function encoder(text){
if (text){
var myregexp = /]+?class="math".*?>([\s\S]*?)<\/span>/g;
return text.replace(myregexp, function replacer(match) {
return match.replace(/([\s\S]*?)<\/math>/g , function replacerData(match) {
let tempString = match.replace(//g, "\\(");
return this.htmlEncode(tempString.replace(/<\/math>/g, "\\)"))
}.bind(this))
}.bind(this))
}
}```
Decoder Helper
``` let str = "\({ MathML or Tex Mathemathical expressions }\)" ```
``` this helper function removed escape character before ```
``` decoder(str) // MathML or Tex Mathemathical expressions ```
```javascript
function decoder(str) {
let tempString = str.replace(/\\\(/g, "");
return tempString.replace(/<\/math>\\\)/g, "");
}```
htmlEncode Helper
``` htmlEncode( 'A > B & C < D' ) // 'A > B & C < D' ```
```javascript
var ampRegex = /&/g,
gtRegex = />/g,
ltRegex = / B & C < D' ) ); // 'A > B & C < D'
*
* @param {String} text The string to be encoded.
* @returns {String} The encoded string.
*/
htmlEncode = text => {
// Backwards compatibility - accept also non-string values (casting is done below).
// Since 4.4.8 we return empty string for null and undefined because these values make no sense.
if (text === undefined || text === null) {
return '';
}return String(text).replace(ampRegex, '&').replace(gtRegex, '>').replace(ltRegex, '<');
}```
htmlDecode Helper
``` htmlDecode( '<a & b >' ) // '' ```
```javascript
var ampRegex = /&/g,
gtRegex = />/g,
ltRegex = /',
amp: '&',
quot: '"',
nbsp: '\u00a0',
shy: '\u00ad'
}allEscDecode(match, code) {
if (code[0] == '#') {
return String.fromCharCode(parseInt(code.slice(1), 10));
} else {
return namedEntities[code];
}
}/**
* Decodes HTML entities that browsers tend to encode when used in text nodes.
*
* console.log( htmlDecode( '<a & b >' ) ); // ''
*
* Read more about chosen entities in the [research].
*
* @param {String} The string to be decoded.
* @returns {String} The decoded string.
*/
htmlDecode = text => {
// See:
// * http://jsperf.com/wth-is-going-on-with-jsperf JSPerf has some serious problems, but you can observe
// that combined regexp tends to be quicker (except on V8). It will also not be prone to fail on '<'
return text.replace(allEscRegex, this.allEscDecode);
}```
### Licence
GPL 2.0