Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:outline/rich-markdown-editor int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
tommoor committed Aug 29, 2020
2 parents 7483bdd + ea5d2bc commit 138a8af
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
node_modules/*
.log
.DS_Store
.DS_Store
.idea
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Placeholder from "./plugins/Placeholder";
import SmartText from "./plugins/SmartText";
import TrailingNode from "./plugins/TrailingNode";
import MarkdownPaste from "./plugins/MarkdownPaste";
import HardBreak from "./nodes/HardBreak";

export { schema, parser, serializer } from "./server";

Expand Down Expand Up @@ -218,6 +219,7 @@ class RichMarkdownEditor extends React.PureComponent<Props, State> {
[
new Doc(),
new Text(),
new HardBreak(),
new Paragraph(),
new Blockquote(),
new BulletList(),
Expand Down
18 changes: 18 additions & 0 deletions src/lib/markdown/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ export default function markdownTables(md: MarkdownIt) {
tokens[i].level--;
}

// convert break line into br tag
if (tokens[i].type === "inline" && tokens[i].content.includes("\\n")) {
const nodes: Token[] = [];
const breakParts = tokens[i].content.split("\\n");
breakParts.forEach((part, index) => {
const token = new Token("text", "", 1);
token.content = part.trim();
nodes.push(token);

if (index < breakParts.length - 1) {
const brToken = new Token("br", "br", 1);
nodes.push(brToken);
}
});

tokens.splice(i, 1, ...nodes);
}

// filter out incompatible tokens from markdown-it that we don't need
// in prosemirror. thead/tbody do nothing.
if (
Expand Down
45 changes: 45 additions & 0 deletions src/nodes/HardBreak.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Node from "./Node";
import { isInTable } from "prosemirror-tables";

export default class HardBreak extends Node {
get name() {
return "br";
}

get schema() {
return {
inline: true,
group: "inline",
selectable: false,
parseDOM: [{ tag: "br" }],
toDOM() {
return ["br"];
},
};
}

commands({ type }) {
return () => (state, dispatch) => {
dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
return true;
};
}

keys({ type }) {
return {
"Shift-Enter": (state, dispatch) => {
if (!isInTable(state)) return false;
dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
return true;
},
};
}

toMarkdown(state) {
state.write(" \\n ");
}

parseMarkdown() {
return { node: "br" };
}
}
20 changes: 10 additions & 10 deletions src/nodes/Table.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import Node from "./Node";
import { DecorationSet, Decoration } from "prosemirror-view";
import { Decoration, DecorationSet } from "prosemirror-view";
import {
tableEditing,
goToNextCell,
addColumnBefore,
addColumnAfter,
addColumnBefore,
deleteColumn,
deleteRow,
deleteTable,
toggleHeaderColumn,
toggleHeaderRow,
toggleHeaderCell,
setCellAttr,
fixTables,
goToNextCell,
isInTable,
setCellAttr,
tableEditing,
toggleHeaderCell,
toggleHeaderColumn,
toggleHeaderRow,
} from "prosemirror-tables";
import {
getCellsInColumn,
addRowAt,
createTable,
getCellsInColumn,
moveRow,
addRowAt,
} from "prosemirror-utils";
import { Plugin, TextSelection } from "prosemirror-state";

Expand Down

0 comments on commit 138a8af

Please sign in to comment.