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

POC for implementing "bold" rich text functionality into document producer #3329

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nickgraz
Copy link
Contributor

@nickgraz nickgraz commented Nov 11, 2024

TODO

  • Figure out if we really want this! This is just a proof of concept.
  • Determine how to store this server side. We will need to make sure the text within the section has some information associated to it so we know which sections have which rich text features. I think we can just utilize HTML for this.
  • Need to implement the "un bold"
  • Implement italic and un italic
  • Make sure document preview is implementing the correct CSS to show rich text correctly

Copy link

vercel bot commented Nov 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
terraware-web-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 5:29pm
tree-location-web ❌ Failed (Inspect) Dec 2, 2024 5:29pm

@nickgraz nickgraz marked this pull request as ready for review November 11, 2024 21:44
@nickgraz nickgraz requested a review from a team as a code owner November 11, 2024 21:44
Copy link
Contributor Author

nickgraz commented Nov 11, 2024

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 });
Copy link
Contributor

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.
Copy link
Contributor

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"?

Copy link
Contributor

@constanzauanini constanzauanini left a 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!

@joshbuchea
Copy link
Contributor

The PR review from Graphite appears to have been useful here, nice! 🎉

@nickgraz nickgraz changed the base branch from ng/SW-6168 to main December 2, 2024 17:15
Comment on lines +141 to +151
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}`;
}, '');
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants