-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat (core): added support for an empty string #505
base: main
Are you sure you want to change the base?
Changes from all commits
1c12e20
5a6b8e7
2d2a6ad
296e132
11dd96d
63bad68
4ef6f8d
533d944
b8cf4ba
c36b8b5
0fa5029
b6c3987
5427ef7
cef8738
1c2d298
1850ec4
fd08ec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import {EditorView as CMEditorView} from '@codemirror/view'; | |
import {TextSelection} from 'prosemirror-state'; | ||
import {EditorView as PMEditorView} from 'prosemirror-view'; | ||
|
||
import {getAutocompleteConfig} from '../../src/markup/codemirror/autocomplete'; | ||
import type {CommonEditor, MarkupString} from '../common'; | ||
import { | ||
type ActionStorage, | ||
|
@@ -248,6 +249,7 @@ export class EditorImpl extends SafeEventEmitter<EventMapInt> implements EditorI | |
mdPreset, | ||
initialContent: this.#markup, | ||
extensions: this.#extensions, | ||
pmTransformers: this.#mdOptions.pmTransformers, | ||
allowHTML: this.#mdOptions.html, | ||
linkify: this.#mdOptions.linkify, | ||
linkifyTlds: this.#mdOptions.linkifyTlds, | ||
|
@@ -279,7 +281,11 @@ export class EditorImpl extends SafeEventEmitter<EventMapInt> implements EditorI | |
extensions: this.#markupConfig.extensions, | ||
disabledExtensions: this.#markupConfig.disabledExtensions, | ||
keymaps: this.#markupConfig.keymaps, | ||
yfmLangOptions: {languageData: this.#markupConfig.languageData}, | ||
yfmLangOptions: { | ||
languageData: getAutocompleteConfig({ | ||
preserveEmptyRows: this.#mdOptions.preserveEmptyRows, | ||
}), | ||
}, | ||
Comment on lines
-282
to
+288
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should concat languageData config from |
||
autocompletion: this.#markupConfig.autocompletion, | ||
directiveSyntax: this.directiveSyntax, | ||
receiver: this, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import type {ReactNode} from 'react'; | ||
|
||
import {TransformFn} from 'src/core/markdown/ProseMirrorTransformer'; | ||
|
||
import type {MarkupString} from '../common'; | ||
import type {EscapeConfig, Extension} from '../core'; | ||
import type {CreateCodemirrorParams, YfmLangOptions} from '../markup'; | ||
|
@@ -39,9 +41,11 @@ export type WysiwygPlaceholderOptions = { | |
|
||
export type MarkdownEditorMdOptions = { | ||
html?: boolean; | ||
preserveEmptyRows?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this setting to experiment options |
||
breaks?: boolean; | ||
linkify?: boolean; | ||
linkifyTlds?: string | string[]; | ||
pmTransformers?: TransformFn[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this field not needed anymore? |
||
}; | ||
|
||
export type MarkdownEditorInitialOptions = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import type {CommonEditor, ContentHandler, MarkupString} from '../common'; | |
import type {ActionsManager} from './ActionsManager'; | ||
import {WysiwygContentHandler} from './ContentHandler'; | ||
import {ExtensionsManager} from './ExtensionsManager'; | ||
import {TransformFn} from './markdown/ProseMirrorTransformer'; | ||
import type {ActionStorage} from './types/actions'; | ||
import type {Extension} from './types/extension'; | ||
import type {Parser} from './types/parser'; | ||
|
@@ -30,6 +31,7 @@ export type WysiwygEditorOptions = { | |
mdPreset?: PresetName; | ||
allowHTML?: boolean; | ||
linkify?: boolean; | ||
pmTransformers?: TransformFn[]; | ||
linkifyTlds?: string | string[]; | ||
escapeConfig?: EscapeConfig; | ||
/** Call on any state change (move cursor, change selection, etc...) */ | ||
|
@@ -74,6 +76,7 @@ export class WysiwygEditor implements CommonEditor, ActionStorage { | |
allowHTML, | ||
mdPreset, | ||
linkify, | ||
pmTransformers, | ||
linkifyTlds, | ||
escapeConfig, | ||
onChange, | ||
|
@@ -90,7 +93,7 @@ export class WysiwygEditor implements CommonEditor, ActionStorage { | |
actions, | ||
} = ExtensionsManager.process(extensions, { | ||
// "breaks" option only affects the renderer, but not the parser | ||
mdOpts: {html: allowHTML, linkify, breaks: true, preset: mdPreset}, | ||
mdOpts: {pmTransformers, html: allowHTML, linkify, breaks: true, preset: mdPreset}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
linkifyTlds, | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {TransformFn} from './index'; | ||
|
||
export const transformEmptyParagraph: TransformFn = (node) => { | ||
if (node.type !== 'paragraph') return; | ||
if (node.content?.length !== 1) return; | ||
if (node.content[0]?.type !== 'text') return; | ||
if (node.content[0].text === String.fromCharCode(160)) delete node.content; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// TODO: add a new method to the ExtensionBuilder | ||
import {transformEmptyParagraph} from './emptyRowParser'; | ||
|
||
import {TransformFn} from '.'; | ||
|
||
type GetTransformersProps = { | ||
emptyRowTransformer?: boolean; | ||
}; | ||
|
||
type GetPMTransformersType = (config: GetTransformersProps) => TransformFn[]; | ||
|
||
export const getPMTransformers: GetPMTransformersType = ({emptyRowTransformer}) => { | ||
const transformers = []; | ||
|
||
if (emptyRowTransformer) { | ||
transformers.push(transformEmptyParagraph); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add today: add a new method to the ExtensionBuilder |
||
} | ||
|
||
return transformers; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add preserveEmptyRows to the following line in Playground.tsx to enable rerendering in the demo.