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

Implement Markdown parsing in useHandlePastedText #245

Merged
merged 2 commits into from
Jul 25, 2023

Conversation

juliopavila
Copy link
Collaborator

Description

This PR addresses the request in issue #236. It involves modifying the useHandlePastedText method to handle Markdown formatted text.

Changes Implemented:

  1. Added marked library to parse Markdown into HTML.
  2. The method isMarkdown has been added to identify if the incoming pasted text is in Markdown format. It checks for common Markdown syntax characters such as "#", "*", "_", "~", "[", "]", "(", ")", "|", "`", ">", "-".
  3. If the text is identified as Markdown, it is first converted to HTML using marked. The HTML is then parsed into Draft.js blocks using convertFromHTML. The resulting blocks replace the current selection in the editor.
  4. If the text is not identified as Markdown, it's treated as plain text and the function behaves as it did originally - replacing the current selection with the plain text.

Here's a sample Markdown snippet for testing:

# Heading

This is a paragraph with **bold text**, _italic text_, text with a [link](https://www.example.com), and `inline code`.

1. This is the first item in an ordered list
2. This is the second item on the ordered list
   - This is the first item in a nested unordered list
   - This is the second item in the nested unordered list

> This is a quote

***
This is a divider line

```python
# This is a code block
print('Hello, world!')```

This Markdown text covers all the scenarios we are aiming to handle with this PR.

Test Record

Screen.Recording.2023-07-25.at.1.57.42.PM.mov

@vercel
Copy link

vercel bot commented Jul 25, 2023

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

Name Status Preview Comments Updated (UTC)
tabula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2023 5:18pm

Copy link
Collaborator

@cedricwaxwing cedricwaxwing left a comment

Choose a reason for hiding this comment

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

Really nice! 🤩

@juliopavila juliopavila merged commit b3d2576 into tabula-v.2.1 Jul 25, 2023
3 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2023
@juliopavila juliopavila deleted the issue-#236 branch May 28, 2024 20:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants