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(commonmark-editor): detect and format pasted code #147
Conversation
✅ Deploy Preview for nifty-lalande-39c157 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
b84f781
to
db0a798
Compare
if (isMarkdown) { | ||
codeData = `${ | ||
$from.pos === 1 ? "" : "\n" | ||
}\`\`\`\n${codeData}\n\`\`\`\n`; | ||
} |
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 is the main modification to codePasteHandler
to operate within the CommonMark editor.
1e96950
to
3e4c847
Compare
# Conflicts: # test/shared/prosemirror-plugins/code-paste-handler.test.ts
Made some tweaks to split the plugin into two (one for rich-text, one for commonmark), moving the shared functionality out into a common, testable function. Additionally, I set up the commonmark extension to detect pasted code in the same manner the rich-text editor's schema does. |
OK, does this even work? I tried to paste any text into the commonmark editor and it is always formatted as code. Keep in mind that:
|
@double-beep Can you be more specific in what issue you're running into? Can you provide repro steps for me? I've contemplated in the past whether to consider text copied from the commonmark editor as code or not. I'm going to revisit that this morning and make a decision before cutting the next release. |
@double-beep I think I'm reproing the issue you're describing. The fix is simple - I'll get it in place with some updated tests asap. |
closes #135
Describe your changes
Detect pasted code and wrap it in code fences.
PR Checklist
/** ... */
docsbug
/enhancement
and other labels as appropriatePasting within an existing commonmark code block
The functionality introduced in this PR does not currently account for pasting into an existing code block in markdown mode (it always wraps pasted code in fences). Although this behavior is somewhat odd from a UX standpoint, it lines up with the existing behavior of the code block command. I'd suggest we create a new issue for this behavior and consider addressing it out of scope for this PR. What do you think @b-kelly?
A note on the approach taken in this PR
From the related issue #135:
I took a very light touch approach with this PR by purely extending the functionality of
codePasteHandler
just to wrap pasted code in code fences. For the sake of time/scope, I suggest this "light touch" approach for now and revisiting spinning up the rich-text schema/editor as a refactor down the road, since that approach might be applicable in for a few different features (markdown preview pane, rich-text paste node parsing for CommonMark editor, etc.).