Skip to content

Commit

Permalink
Enh #33: Implement em + strikethrough input rules
Browse files Browse the repository at this point in the history
- Created em_strikethrough plugin.
- Added em_strikethrough icon.
- Changed toolbar svg-icons.
- Changed Keyboard right arrow navigation and Keyboard left navigation tests.
  • Loading branch information
serh-mosk committed Jun 8, 2023
1 parent 414d560 commit 571d815
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 128 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changelog
- Enh #91: Update JS dependencies
- Fix #59: @ becomes @@ when copying mentioning in wiki editor
- Enh #30: Tabulator Support
- Enh #33: Implement em + strikethrough input rules


1.1.3 (Unreleased)
Expand Down
158 changes: 79 additions & 79 deletions src/editor/core/menu/icons.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/editor/core/plugins/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
import {schema} from './schema'
import {menu} from "./menu"

import {schema} from './schema';
import {menu} from "./menu";
import {codeRules} from "./input-rules";

const code = {
Expand Down
8 changes: 3 additions & 5 deletions src/editor/core/plugins/code/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

import {icons, markItem} from "../../menu/menu"


function markCode(context) {
return markItem(context.schema.marks.code, {
title: context.translate("Toggle code font"),
icon: icons.code,
sortOrder: 400
sortOrder: 500
}, context);
}

Expand All @@ -24,5 +22,5 @@ export function menu(context) {
group: 'marks',
item: markCode(context)
}
]
}
];
}
6 changes: 2 additions & 4 deletions src/editor/core/plugins/code/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

const schema = {
marks: {
code:{
isCode: true,
sortOrder: 400,
preventMarks: ['link'],
parseDOM: [{tag: "code"}],
toDOM: () => {
return ["code"]
},
parseMarkdown: {code_inline: {mark: "code"}},
parseMarkdown: {code_inline: {mark: "code"}},
toMarkdown: {open: "`", close: "`"}
}
}
};

export {schema}
export {schema};
6 changes: 3 additions & 3 deletions src/editor/core/plugins/em/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
import {schema} from './schema'
import {menu} from "./menu"

import {schema} from './schema';
import {menu} from "./menu";

const em = {
id: 'em',
Expand Down
8 changes: 3 additions & 5 deletions src/editor/core/plugins/em/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

import {icons, markItem} from "../../menu/menu"

import {icons, markItem} from "../../menu/menu";

function markEm(context) {
return markItem(context.schema.marks.em, {
Expand All @@ -24,5 +22,5 @@ export function menu(context) {
group: 'marks',
item: markEm(context)
}
]
}
];
}
8 changes: 3 additions & 5 deletions src/editor/core/plugins/em/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

const schema = {
marks: {
em: {
sortOrder: 100,
parseDOM: [{tag: "i"}, {tag: "em"},
{
style: "font-style", getAttrs: function (value) {
return value == "italic" && null;
}
return value === "italic" && null;
}
}],
toDOM: () => {
return ["em"]
Expand All @@ -24,4 +22,4 @@ const schema = {
}
};

export {schema}
export {schema};
16 changes: 16 additions & 0 deletions src/editor/core/plugins/em_strikethrough/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

import {schema} from './schema';
import {menu} from "./menu";

const em_strikethrough = {
id: 'em_strikethrough',
schema: schema,
menu: (context) => menu(context)
};

export default em_strikethrough;
26 changes: 26 additions & 0 deletions src/editor/core/plugins/em_strikethrough/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

import {icons, markItem} from "../../menu/menu";

function markEmStrikethrough(context) {
return markItem(context.schema.marks.em_strikethrough, {
title: context.translate("Toggle emphasis + strikethrough"),
icon: icons.em_strikethrough,
sortOrder: 400
}, context);
}

export function menu(context) {
return [
{
id: 'markEmStrikethrough',
mark: 'em_strikethrough',
group: 'marks',
item: markEmStrikethrough(context)
}
];
}
20 changes: 20 additions & 0 deletions src/editor/core/plugins/em_strikethrough/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

const schema = {
marks: {
em_strikethrough: {
parseDOM: [{tag: "s[data-emphasis]"}],
toDOM: () => {
return ["s", {"data-emphasis": true, style: "font-style: italic"}];
},
parseMarkdown: {mark: "em_strikethrough"},
toMarkdown: {open: "_~~", close: "~~_", mixable: true, expelEnclosingWhitespace: true}
}
}
};

export {schema};
2 changes: 2 additions & 0 deletions src/editor/core/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import maxHeight from "./max_height";
import save from "./save";
import source from "./source";
import tabBehavior from "./tab_behavior";
import em_strikethrough from "./em_strikethrough";
import {PluginRegistry} from "./registry";

const registry = new PluginRegistry();
Expand Down Expand Up @@ -88,6 +89,7 @@ registerPlugin(maxHeight, 'markdown');
registerPlugin(save, 'markdown');
registerPlugin(source, 'markdown');
registerPlugin(tabBehavior, 'markdown');
registerPlugin(em_strikethrough, 'markdown');

registerPreset('normal', {
extend: 'markdown',
Expand Down
2 changes: 1 addition & 1 deletion src/editor/core/plugins/link/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function linkItem(context) {
let mark = context.schema.marks.link;
return new MenuItem({
title: context.translate("Add or remove link"),
sortOrder: 500,
sortOrder: 600,
icon: icons.link,
active(state) {
return markActive(state, mark)
Expand Down
6 changes: 3 additions & 3 deletions src/editor/core/plugins/strikethrough/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
import {schema} from './schema'
import {menu} from "./menu"

import {schema} from './schema';
import {menu} from "./menu";

const strikethrough = {
id: 'strikethrough',
Expand Down
6 changes: 2 additions & 4 deletions src/editor/core/plugins/strikethrough/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

import {icons, markItem} from "../../menu/menu"


function markStrikethrough(context) {
return markItem(context.schema.marks.strikethrough, {
title: context.translate("Toggle strikethrough"),
Expand All @@ -24,5 +22,5 @@ export function menu(context) {
group: 'marks',
item: markStrikethrough(context)
}
]
}
];
}
3 changes: 1 addition & 2 deletions src/editor/core/plugins/strikethrough/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

const schema = {
Expand All @@ -18,4 +17,4 @@ const schema = {
}
};

export {schema}
export {schema};
26 changes: 12 additions & 14 deletions src/editor/markdown/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

import {MarkdownSerializer, MarkdownSerializerState} from "prosemirror-markdown"
import {getPlugins, PresetManager} from "../core/plugins"
import {Mark} from "prosemirror-model";
import {MarkdownSerializer, MarkdownSerializerState} from "prosemirror-markdown";
import {getPlugins, PresetManager} from "../core/plugins";

let presets = new PresetManager({
name: 'serializer',
Expand All @@ -33,17 +31,17 @@ let createSerializer = (context) => {

for (let key in nodes) {
let node = nodes[key];
if(node.toMarkdown) {
nodeSpec[key] = node.toMarkdown
if (node.toMarkdown) {
nodeSpec[key] = node.toMarkdown;
}
}

let marks = plugin.schema.marks || {};

for (let key in marks) {
let mark = marks[key];
if(mark.toMarkdown) {
markSpec[key] = mark.toMarkdown
if (mark.toMarkdown) {
markSpec[key] = mark.toMarkdown;
} else {
markSpec[key] = {open: '', close: ''};
}
Expand All @@ -59,9 +57,9 @@ class HumHubMarkdownSerializer extends MarkdownSerializer {
// [CommonMark](http://commonmark.org/).
serialize(content, options) {
let state = new HumHubMarkdownSerializerState(
this.nodes,
this.marks,
{...options, tightLists: false}
this.nodes,
this.marks,
{...options, tightLists: false}
);
state.renderContent(content);
return state.out;
Expand All @@ -75,9 +73,9 @@ class HumHubMarkdownSerializerState extends MarkdownSerializerState {
// has special meaning only at the start of the line.
esc(str, startOfLine) {
// eslint-disable-next-line
str = str.replace(/[|`*\\~\[\]]/g, "\\$&")
if (startOfLine) str = str.replace(/^[:#\-*+]/, "\\$&").replace(/^(\d+)\./, "$1\\.")
return str
str = str.replace(/[|`*\\~\[\]]/g, "\\$&");
if (startOfLine) str = str.replace(/^[:#*+-]/, "\\$&").replace(/^(\d+)\./, "$1\\.");
return str;
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,9 @@ ProsemirrorEditor img {
}

.ProseMirror-menu-dropdown-item div[title],
.ProseMirror-menu-dropdown-item a.ProseMirror-menu-trigger,
.ProseMirror-menu-submenu-wrap {
display: block;
padding: 4px;
}

Expand Down
2 changes: 2 additions & 0 deletions test/menu/test-menu-accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("Menu:accessibility", () => {
navigate(DIR_RIGHT, 'markStrong');
navigate(DIR_RIGHT, 'markEm');
navigate(DIR_RIGHT, 'markStrikethrough');
navigate(DIR_RIGHT, 'markEmStrikethrough');
navigate(DIR_RIGHT, 'markCode');
navigate(DIR_RIGHT, 'linkItem');
navigate(DIR_RIGHT, 'insertEmoji');
Expand All @@ -75,6 +76,7 @@ describe("Menu:accessibility", () => {
navigate(DIR_LEFT, 'insertEmoji');
navigate(DIR_LEFT, 'linkItem');
navigate(DIR_LEFT, 'markCode');
navigate(DIR_LEFT, 'markEmStrikethrough');
navigate(DIR_LEFT, 'markStrikethrough');
navigate(DIR_LEFT, 'markEm');
navigate(DIR_LEFT, 'markStrong');
Expand Down

0 comments on commit 571d815

Please sign in to comment.