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

pastehtml-example:should paste plain text into code block #5393

Closed
wants to merge 2 commits into from
Closed

Conversation

qirong77
Copy link
Contributor

Description
When we copy code from editors such as vscode, we don't want to keep the original style (Vscode uses div to represent each line of code, so it will not be parsed correctly) but use plain text to paste into our code block,so before we insertData , We should judge whether the current selection is a code block(eg:'code-block,'code-line') before we use inertData.

@changeset-bot
Copy link

changeset-bot bot commented Apr 12, 2023

⚠️ No Changeset found

Latest commit: 81fb781

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the sentiment.

I don't think this check is sufficient though because you can have nested structures in code blocks and I believe this would have unexpected results.

Perhaps take a look at https://github.com/udecode/plate/tree/main/packages/nodes/code-block/src which is a more comprehensive code block implementation for inspiration?

@qirong77
Copy link
Contributor Author

I agree with the sentiment.

I don't think this check is sufficient though because you can have nested structures in code blocks and I believe this would have unexpected results.

Perhaps take a look at https://github.com/udecode/plate/tree/main/packages/nodes/code-block/src which is a more comprehensive code block implementation for inspiration?

Thank you for your reply. I read the link you gave me and found that he used the deserializeHtmlCodeBlockPre method to process the copied code block. The main function of this method is to obtain the textContent of the node. I think his idea should be the same as mine. It is consistent. We need to perform additional processing on the copied code block, but the method may be different. However, there is no additional processing on the code block in this example, so it caused some problems when I learned and used it, but I'm clear now, thanks.

@dylans
Copy link
Collaborator

dylans commented Apr 14, 2023

I agree with the sentiment.
I don't think this check is sufficient though because you can have nested structures in code blocks and I believe this would have unexpected results.
Perhaps take a look at https://github.com/udecode/plate/tree/main/packages/nodes/code-block/src which is a more comprehensive code block implementation for inspiration?

Thank you for your reply. I read the link you gave me and found that he used the deserializeHtmlCodeBlockPre method to process the copied code block. The main function of this method is to obtain the textContent of the node. I think his idea should be the same as mine. It is consistent. We need to perform additional processing on the copied code block, but the method may be different. However, there is no additional processing on the code block in this example, so it caused some problems when I learned and used it, but I'm clear now, thanks.

Right, I also meant more that just checking to see if the parent has type code in it might not be sufficient to determine if the paste is happening in a code-block.

@qirong77 qirong77 closed this by deleting the head repository Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants