Skip to content

Commit

Permalink
Additional tweaks
Browse files Browse the repository at this point in the history
Removed extra font files, added math case in customTextBetween, adjusted inline math input rule, changed display math menu insertio
n logic, changed toDOM and parseDOM logic (thanks mrtcode), removed math handling from clipboard serializer, adjusted display math styl
ing.
  • Loading branch information
sawyerpollard committed Jul 7, 2022
1 parent 4d469d7 commit 3e6d1ab
Show file tree
Hide file tree
Showing 50 changed files with 13,120 additions and 46 deletions.
13,068 changes: 13,049 additions & 19 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@benrbray/prosemirror-math": "^0.2.2",
"classnames": "^2.3.1",
"katex": "^0.13.24",
"prop-types": "^15.7.2",
"prosemirror-commands": "^1.1.10",
"prosemirror-dropcursor": "^1.3.5",
Expand Down
Binary file removed res/fonts/KaTeX_AMS-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_AMS-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Caligraphic-Bold.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Caligraphic-Bold.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Caligraphic-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Caligraphic-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Fraktur-Bold.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Fraktur-Bold.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Fraktur-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Fraktur-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-Bold.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-Bold.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-BoldItalic.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-BoldItalic.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-Italic.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-Italic.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Main-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Math-BoldItalic.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Math-BoldItalic.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Math-Italic.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Math-Italic.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_SansSerif-Bold.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_SansSerif-Bold.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_SansSerif-Italic.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_SansSerif-Italic.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_SansSerif-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_SansSerif-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Script-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Script-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size1-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size1-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size2-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size2-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size3-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size3-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size4-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Size4-Regular.woff
Binary file not shown.
Binary file removed res/fonts/KaTeX_Typewriter-Regular.ttf
Binary file not shown.
Binary file removed res/fonts/KaTeX_Typewriter-Regular.woff
Binary file not shown.
8 changes: 8 additions & 0 deletions src/core/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,14 @@ export function customTextBetween (slice, from, to, blockSeparator, leafText) {
if (node.type === schema.nodes.citation) {
text += serializeCitationInnerText(node);
}
else if (node.type === schema.nodes.math_display) {
text += blockSeparator + '$$' + node.textContent + '$$';
return false;
}
else if (node.type === schema.nodes.math_inline) {
text += '$' + node.textContent + '$';
return false;
}
else if (node.isText) {
text += node.text.slice(Math.max(from, pos) - pos, to - pos);
separated = !blockSeparator;
Expand Down
2 changes: 1 addition & 1 deletion src/core/editor-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { keymap } from 'prosemirror-keymap';
import { history } from 'prosemirror-history';
import { baseKeymap } from 'prosemirror-commands';
import applyDevTools from 'prosemirror-dev-tools';
import { mathPlugin } from "@benrbray/prosemirror-math";
import { mathPlugin } from '@benrbray/prosemirror-math';


import {
Expand Down
4 changes: 2 additions & 2 deletions src/core/input-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { schema } from './schema';
import { TextSelection } from 'prosemirror-state';

import { makeBlockMathInputRule, makeInlineMathInputRule } from "@benrbray/prosemirror-math";
import { makeBlockMathInputRule, makeInlineMathInputRule } from '@benrbray/prosemirror-math';

function markInputRule(regexp, markType, size) {
return new InputRule(regexp, (state, match, start, end) => {
Expand Down Expand Up @@ -57,7 +57,7 @@ export function buildInputRules({ enableSmartQuotes }) {
}),
linkInputRule(),
makeBlockMathInputRule(/^\$\$\s+$/, schema.nodes.math_display),
makeInlineMathInputRule(/\$\$(.+)\$\$/, schema.nodes.math_inline),
makeInlineMathInputRule(/\$(.+)\$/, schema.nodes.math_inline),
markInputRule(/(?:[^`0-9A-Za-z]+)(__([^\s_][^_]+)__)$|^(__([^\s _][^_]+)__)$/, schema.marks.strong, 2),
markInputRule(/^(?:[^`]+)(\*\*([^\s*][^*]+)\*\*)$|^(\*\*([^\s*][^*]+)\*\*)$/, schema.marks.strong, 2),
markInputRule(/(?:[^_`0-9A-Za-z]+)(_([^\s_][^_]+?)_)$|^(_([^\s_][^_]+)_)$/, schema.marks.em, 1),
Expand Down
14 changes: 12 additions & 2 deletions src/core/plugins/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { wrapInList } from 'prosemirror-schema-list';
import * as commands from '../commands';
import { schema } from '../schema';

import { TextSelection } from 'prosemirror-state';
import { TextSelection, NodeSelection } from 'prosemirror-state';
import nodeIsActive, { getActiveColor, randomString } from '../utils';
import { NodeRange } from 'prosemirror-model';
import { findWrapping, liftTarget } from 'prosemirror-transform';
Expand Down Expand Up @@ -213,11 +213,21 @@ class Menu {
}
};

this.math_display = {
isActive: false,
run() {
let { $from } = state.selection;
let mathNode = schema.nodes.math_display.create();
let tr = state.tr.replaceSelectionWith(mathNode);
tr = tr.setSelection(NodeSelection.create(tr.doc, $from.pos-1));
dispatch(tr);
}
}

let insideList = nodeIsActive(state, schema.nodes.orderedList) || nodeIsActive(state, schema.nodes.bulletList);
let insideBlockquote = nodeIsActive(state, schema.nodes.blockquote);
this.paragraph = this.buildBlock(schema.nodes.paragraph, {}, insideList || insideBlockquote);
this.codeBlock = this.buildBlock(schema.nodes.codeBlock);
this.math_display = this.buildBlock(schema.nodes.math_display);
this.heading1 = this.buildBlock(schema.nodes.heading, { level: 1 });
this.heading2 = this.buildBlock(schema.nodes.heading, { level: 2 });
this.heading3 = this.buildBlock(schema.nodes.heading, { level: 3 });
Expand Down
53 changes: 37 additions & 16 deletions src/core/schema/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ export default {
},


math_display: {
group: 'block math',
content: 'text*',
atom: true,
code: true,
toDOM: node => ['pre', {
class: 'math'
}, '$$' + node.textContent + '$$'],
parseDOM: [{
tag: 'pre.math',
getContent(dom) {
let text = dom.textContent;
text = text.trim();
if (text.slice(0, 2) === '$$' && text.slice(-2) === '$$') {
text = text.slice(2, -2);
}
return Fragment.from(schema.text(text));
}
}]
},


codeBlock: {
group: 'block',
content: 'text*',
Expand Down Expand Up @@ -259,17 +281,6 @@ export default {
}),


math_display: {
group: "block math",
content: "text*",
atom: true,
code: true,
toDOM: () => ["pre", 0],
parseDOM: [{
tag: "pre"
}]
},

// Inline nodes

// TinyMCE needs non-breaking spaces to represent sequential spaces,
Expand Down Expand Up @@ -420,13 +431,23 @@ export default {


math_inline: {
group: "inline math",
content: "text*",
group: 'inline math',
content: 'text*',
inline: true,
atom: true,
toDOM: () => ["span", 0],
toDOM: node => ['span', {
class: 'math'
}, '$' + node.textContent + '$'],
parseDOM: [{
tag: "span"
tag: 'span.math',
getContent(dom) {
let text = dom.textContent;
text = text.trim();
if (text.slice(0, 2) === '$' && text.slice(-2) === '$') {
text = text.slice(2, -2);
}
return Fragment.from(schema.text(text));
}
}]
},
}
};
6 changes: 0 additions & 6 deletions src/core/schema/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@ export function buildClipboardSerializer(provider, schema, metadata) {
class: 'highlight',
'data-annotation': annotation && encodeObject(annotation)
}, 0];
},
math_display(node) {
return ['pre', `$$${node.textContent}$$`];
},
math_inline(node) {
return ['span', `$$${node.textContent}$$`];
}
}),
Object.assign({}, base.marks, {
Expand Down
5 changes: 5 additions & 0 deletions src/stylesheets/darwin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ $mode: "production" !default;

.math-node.empty-math .math-render::before {
content: "Click to insert LaTex ...";
color: black;
}

.math-node .math-render.parse-error::before {
content: "Cannot parse LaTeX.";
cursor: help;
}

.math-node .ProseMirror-focused {
outline: none;
}

math-display {
position: relative;

Expand Down
5 changes: 5 additions & 0 deletions src/stylesheets/generic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ $mode: "production" !default;

.math-node.empty-math .math-render::before {
content: "Click to insert LaTex ...";
color: black;
}

.math-node .math-render.parse-error::before {
content: "Cannot parse LaTeX.";
cursor: help;
}

.math-node .ProseMirror-focused {
outline: none;
}

math-display {
position: relative;

Expand Down

0 comments on commit 3e6d1ab

Please sign in to comment.