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

Support custom parsing logic (pass worklet as parser prop) #439

Merged
merged 172 commits into from
Dec 4, 2024

Conversation

tomekzaw
Copy link
Collaborator

@tomekzaw tomekzaw commented Jul 25, 2024

Details

This PR removes separate JS bundle with ExpensiMark logic and allows for customizing MarkdownTextInput formatting logic via parser property. Parser needs to be a function that accepts a plaintext string and returns an array of ranges.

Related Issues

#317

Manual Tests

Linked PRs

@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 6, 2024

Regression: toggling font size doesn't work properly

Screen.Recording.2024-11-06.at.13.53.44.mov

It works correctly if there's a blockquote (NSParagraphStyle) in the middle of the text:

Screen.Recording.2024-11-06.at.14.01.11.mov

@bbaoNg97
Copy link

any update on this?

@tomekzaw
Copy link
Collaborator Author

@bbaoNg97 This PR is currently in internal review.

@tomekzaw
Copy link
Collaborator Author

TODO: check in release mode

@tomekzaw tomekzaw requested a review from j-piasecki December 3, 2024 13:16
@tomekzaw tomekzaw merged commit 0c283b5 into main Dec 4, 2024
9 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/worklets branch December 4, 2024 12:48
@os-botify
Copy link
Contributor

os-botify bot commented Dec 4, 2024

🚀 Published to npm in 0.1.188 🎉

@garygcchiu
Copy link

Hi, thank you for this fix. Unfortunately I think the patch here is causing install issues for yarn users: #573

if (markdown.length > MAX_PARSABLE_LENGTH) {
return [];
}
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @tomekzaw, coming from Expensify/App#54522, we're facing the issue when text and markdown are different then the error will be thrown. If so users can't perform their action. I don't think we should remove try/catch here. Can you please help take a look? Thank you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was a deliberate decision to remove try/catch block so we can show a RedBox with the error if something fails.

However, looks like I forgot about the case when Markdown message before and after parsing don't match. I think we should show a warning and return an empty array in such case, like this:

if (text !== markdown) {
  console.warn(
    `[react-native-live-markdown] Parsing error: the processed text does not match the original Markdown input. This may be caused by incorrect parsing functions or invalid input Markdown.\nProcessed input: '${JSON.stringify(
      text,
    )}'\nOriginal input: '${JSON.stringify(markdown)}'`,
  );
  return [];
}

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.

5 participants