Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editors with third parties spell check compatibility / multi editors #696

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ Valid values for `homepage`: `pages` (default), `posts`, `<collection_name>`,
jekyll_admin:
homepage: "posts"
```

#### `editors` and `default_editor`

Specify the list of editors you want to have, and the default one.

```yaml
jekyll_admin:
editors: [SimpleMDE, TinyMDE, TextArea, TUI_WW, TUI_SS, TUI_Tab]
default_editor: TinyMDE
```




126 changes: 125 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"author": "Mert Kahyaoğlu",
"license": "MIT",
"dependencies": {
"@toast-ui/editor": "^3.2.1",
"brace": "0.9.1",
"classnames": "2.2.6",
"highlight.js": "^9.17.1",
Expand Down Expand Up @@ -54,6 +55,7 @@
"rimraf": "^3.0.2",
"simplemde": "1.11.2",
"sortablejs": "1.8.4",
"tiny-markdown-editor": "^0.1.5",
"underscore": "1.9.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/site/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ collections:

jekyll_admin:
homepage: "posts"
# editors: []
default_editor: TinyMDE
7 changes: 7 additions & 0 deletions spec/fixtures/site/_drafts/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
tags: []
categories: []
title: test
---

<details data-raw-html="details">TestData</details>\\\\\\\\\\\\\\\\\\\\\\\\\~\\\\\\\\\\\\\\\\\\\\\\\\\~\\\\\\\\\\\\\\\\\\\\\\\\\~\\\\\\\\\\\\\\\\\\\\\\\\\~ \\\\\\\\\\\\\\\\{\\\\\\\\\\\\\\\\{ ' test' \\\\\\\\\\\\\\\\|relative\\\\\\\\\\\\\\\\_url \\\\\\\\\\\\\\\\}\\\\\\\\\\\\\\\\} Test\\\\\\[: style="color: red"\\\\\\}
1 change: 1 addition & 0 deletions src/components/CreateMarkdownPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function CreateMarkdownPage({
<div className="content-wrapper">
<MarkdownPageBody
type={type}
config={config}
updatePath={updatePath}
updateTitle={updateTitle}
updateBody={updateBody}
Expand Down
150 changes: 150 additions & 0 deletions src/components/MarkdownEditor-SimpleMDE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SimpleMDE from 'simplemde';
import hljs from '../utils/highlighter';
import FilePicker from './FilePicker';
import { getExtensionFromPath } from '../utils/helpers';

const classNames = [
'editor-toolbar',
'CodeMirror',
'editor-preview-side',
'editor-statusbar',
];

class MarkdownEditor_SimpleMDE extends Component {
componentDidMount() {
this.create();
window.hljs = hljs; // TODO: fix this after the next release of SimpleMDE
}

shouldComponentUpdate(nextProps) {
return nextProps.initialValue !== this.props.initialValue;
}

componentDidUpdate() {
this.destroy();
this.create();
}

componentWillUnmount() {
this.destroy();
}

create() {
const { onChange, onSave } = this.props;
let opts = Object.create(this.props);
opts['element'] = this.refs.text;
opts['autoDownloadFontAwesome'] = false;
opts['spellChecker'] = false;
opts['renderingConfig'] = {
codeSyntaxHighlighting: true,
};
opts['insertTexts'] = {
image: ['![', '](#url#)'],
};
let toolbarIcons = [
'bold',
'italic',
'heading',
'|',
'code',
'quote',
'unordered-list',
'ordered-list',
'|',
'link',
'image',
'table',
{
name: 'filepicker',
action: () => this.refs.filepicker.refs.trigger.click(),
className: 'fa fa-paperclip',
title: 'Insert Static File',
},
'|',
'preview',
'side-by-side',
'fullscreen',
'|',
];
if (onSave) {
toolbarIcons.push({
name: 'save',
action: onSave,
className: 'fa fa-floppy-o',
title: 'Save',
});
}
opts['toolbar'] = toolbarIcons;
const editor = new SimpleMDE(opts);
if (editor.codemirror) {
editor.codemirror.on('change', () => {
onChange(editor.value());
});
}
this.editor = editor;
}

destroy() {
for (let i in classNames) {
let elementToRemove = this.refs.container.querySelector(
'.' + classNames[i]
);
elementToRemove && elementToRemove.remove();
}
}

// Adapted from an internal helper function within SimpleMDE package.
_replaceSelectedText = (cm, headNTail, url) => {
const startPoint = cm.getCursor('start');
const endPoint = cm.getCursor('end');
const text = cm.getSelection();

let [head, tail] = headNTail;
if (url) {
tail = tail.replace('#url#', url);
}

cm.replaceSelection(`${head}${text}${tail}`);
startPoint.ch += head.length;

if (startPoint !== endPoint) {
endPoint.ch += head.length;
}

cm.setSelection(startPoint, endPoint);
cm.focus();
};

handleFilePick = path => {
const { codemirror, options } = this.editor;
const { image, link } = options.insertTexts;
const url = `{{ '${path}' | relative_url }}`;
const ext = getExtensionFromPath(path);

const type = /png|jpg|gif|jpeg|svg|ico/i.test(ext) ? image : link;
this._replaceSelectedText(codemirror, type, url);
};

render() {
return (
<div>
<div style={{ display: 'none' }}>
<FilePicker ref="filepicker" onPick={this.handleFilePick} />
</div>
<div ref="container">
<textarea ref="text" />
</div>
</div>
);
}
}

MarkdownEditor_SimpleMDE.propTypes = {
initialValue: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired,
};

export default MarkdownEditor_SimpleMDE;
Loading