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

Fix/suggester compatible node #157

Merged
merged 2 commits into from
Mar 1, 2022
Merged
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
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ const cherryInstance = new Cherry({
### Node

```javascript
const { default: Cherry } = require('cherry-markdown');
const cherryInstance = new Cherry({
id: 'markdown-container',
value: '# welcome to cherry editor!',
});
const { default: CherryEngine } = require('cherry-markdown/dist/cherry-markdown.engine.core.common');
const cherryEngineInstance = new CherryEngine();
const htmlContent = cherryEngineInstance.makeHtml('# welcome to cherry editor!');
```

## Lite Version
Expand Down
16 changes: 9 additions & 7 deletions src/core/hooks/Suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
*/
import escapeRegExp from 'lodash/escapeRegExp';
import SyntaxBase from '@/core/SyntaxBase';
import Codemirror from 'codemirror';
import { Pass } from 'codemirror/src/util/misc';
import { isLookbehindSupported } from '@/utils/regexp';
import { replaceLookbehind } from '@/utils/lookbehind-replace';
import { isBrowser } from '@/utils/env';

export default class Suggester extends SyntaxBase {
static HOOK_NAME = 'suggester';

Expand Down Expand Up @@ -79,7 +81,7 @@ export default class Suggester extends SyntaxBase {

makeHtml(str) {
if (!this.RULE.reg) return str;
if (!suggesterPanel.hasEditor()) {
if (!suggesterPanel.hasEditor() && isBrowser()) {
const { editor } = this.$engine.$cherry;
suggesterPanel.setEditor(editor);
suggesterPanel.setSuggester(this.suggester);
Expand Down Expand Up @@ -124,7 +126,7 @@ export default class Suggester extends SyntaxBase {
}

mounted() {
if (!suggesterPanel.hasEditor()) {
if (!suggesterPanel.hasEditor() && isBrowser()) {
const { editor } = this.$engine.$cherry;
suggesterPanel.setEditor(editor);
suggesterPanel.setSuggester(this.suggester);
Expand All @@ -141,7 +143,7 @@ class SuggesterPanel {
this.cursorMove = true;
this.suggesterConfig = {};

if (!this.$suggesterPanel) {
if (!this.$suggesterPanel && isBrowser()) {
document.body.append(this.createDom(SuggesterPanel.panelWrap));
this.$suggesterPanel = document.querySelector('.cherry-suggester-panel');
}
Expand Down Expand Up @@ -187,19 +189,19 @@ class SuggesterPanel {
Up() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Codemirror.Pass;
return Pass;
}
},
Down() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Codemirror.Pass;
return Pass;
}
},
Enter() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Codemirror.Pass;
return Pass;
}
},
});
Expand Down