-
Notifications
You must be signed in to change notification settings - Fork 0
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
POC for implementing "bold" rich text functionality into document producer #3329
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@@ -61,6 +61,7 @@ const SectionEdit = ({ | |||
|
|||
const onChange = useCallback( | |||
(values: Descendant[]) => { | |||
console.log({ values }); |
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.
Should we remove this log?
if (isKeyHotkey('enter', nativeEvent)) { | ||
event.preventDefault(); | ||
Transforms.insertNodes(editor, { text: '\n' }); | ||
return; | ||
} | ||
|
||
if (isKeyHotkey('cmd+b', nativeEvent)) { | ||
// TODO We would need to figure out how to "unbold" the text. |
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.
Isn't this line !Editor.marks(editor)?.bold
already "unbolding"?
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.
graphite-app did the review!
The PR review from Graphite appears to have been useful here, nice! 🎉 |
477f0c5
to
4d193d6
Compare
… according to their docs
4d193d6
to
3b5a743
Compare
const formatEditorChildren = (children: CustomText[]): string => | ||
children.reduce((acc: string, textNode: CustomText) => { | ||
let text = textNode.text; | ||
if (textNode.bold) { | ||
// Going with asterisk bold | ||
// https://www.markdownguide.org/basic-syntax/#bold | ||
text = `**${textNode.text}**`; | ||
} | ||
|
||
return `${acc}${text}`; | ||
}, ''); |
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.
The markdown text **text**
assumes the text contains no asterisks. If the input text contains asterisks (e.g. "5 * 3 = 15"
), the resulting markdown will be malformed. Consider escaping asterisks in the input text by replacing *
with \*
before wrapping with bold markers:
text = textNode.text.replace(/\*/g, '\\*');
text = `**${text}**`;
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
TODO
Need to implement the "un bold"