-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Editor fast follow #653
Editor fast follow #653
Changes from all commits
67229d7
81ce365
869c3f6
85b8b86
e0783e4
ae52d30
f8f592c
65c9e9d
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { get, isEmpty, reduce, pull } from 'lodash'; | ||
import { get, isEmpty, reduce, pull, trimEnd } from 'lodash'; | ||
import unified from 'unified'; | ||
import u from 'unist-builder'; | ||
import markdownToRemarkPlugin from 'remark-parse'; | ||
|
@@ -118,27 +118,32 @@ export const remarkToMarkdown = obj => { | |
fences: true, | ||
listItemIndent: '1', | ||
|
||
// Settings to emulate the defaults from the Prosemirror editor, not | ||
// necessarily optimal. Should eventually be configurable. | ||
/** | ||
* Settings to emulate the defaults from the Prosemirror editor, not | ||
* necessarily optimal. Should eventually be configurable. | ||
*/ | ||
bullet: '*', | ||
strong: '*', | ||
rule: '-', | ||
}; | ||
|
||
/** | ||
* Escape markdown entities found in text and html nodes within the MDAST. | ||
* Transform the MDAST with plugins. | ||
*/ | ||
const escapedMdast = unified() | ||
const processedMdast = unified() | ||
.use(remarkEscapeMarkdownEntities) | ||
.use(remarkStripTrailingBreaks) | ||
.runSync(mdast); | ||
|
||
const markdown = unified() | ||
.use(remarkToMarkdownPlugin, remarkToMarkdownPluginOpts) | ||
.use(remarkAllowAllText) | ||
.stringify(escapedMdast); | ||
.stringify(processedMdast); | ||
|
||
return markdown; | ||
/** | ||
* Return markdown with trailing whitespace removed. | ||
*/ | ||
return trimEnd(markdown); | ||
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. This fixes at least two annoying bugs I've been having, thank you! |
||
}; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { flow, partial, flatMap, flatten, map } from 'lodash'; | ||
import { has, flow, partial, flatMap, flatten, map } from 'lodash'; | ||
import { joinPatternSegments, combinePatterns, replaceWhen } from '../../../../lib/regexHelper'; | ||
|
||
/** | ||
|
@@ -248,6 +248,12 @@ function escape(delim) { | |
*/ | ||
export default function remarkEscapeMarkdownEntities() { | ||
const transform = (node, index) => { | ||
/** | ||
* Shortcode nodes will intentionally inject markdown entities in text node | ||
* children not be escaped. | ||
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 there a typo here, or do I just not understand what it means? 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. Nope, that's a typo. |
||
*/ | ||
if (has(node.data, 'shortcode')) return node; | ||
|
||
const children = node.children && node.children.map(transform); | ||
|
||
/** | ||
|
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.
🎉 This makes a lot more sense.