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

🚸 Rewrite the markdown deserializer to improve br… #1198

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

baptisteArno
Copy link
Owner

@baptisteArno baptisteArno commented Jan 30, 2024

Summary by CodeRabbit

  • Refactor
    • Updated markdown handling and serialization libraries for improved performance and accuracy in text formatting.
  • New Features
    • Enhanced rich text and markdown conversion capabilities, providing users with more reliable and seamless text formatting options.
  • Documentation
    • Added detailed documentation for markdown to rich text conversion and vice versa, ensuring easier understanding and implementation for developers.

Copy link

vercel bot commented Jan 30, 2024

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

Name Status Preview Comments Updated (UTC)
builder-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2024 10:57am
landing-page-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2024 10:57am
viewer-v2 🔄 Building (Inspect) Visit Preview Jan 30, 2024 10:57am

Copy link

coderabbitai bot commented Jan 30, 2024

Walkthrough

The overall change shifts the markdown serialization and deserialization logic from @udecode/plate-serializer-md to a more specialized implementation under @typebot.io/lib/markdown. This involves updating import paths for markdown conversion functions, removing redundant code, and enhancing the markdown processing capabilities with new serialization strategies, support for rich text conversion, and improved handling of AST nodes. The refactoring aims to streamline markdown handling within the bot engine and lib packages, focusing on efficiency and modularity.

Changes

File Path Change Summary
.../parseBubbleBlock.ts Removed @udecode/plate-serializer-md imports; added convertMarkdownToRichText from @typebot.io/lib/markdown.
.../whatsapp/convertInputToWhatsAppMessage.ts Updated convertRichTextToMarkdown import path to @typebot.io/lib/markdown.
.../whatsapp/convertMessageToWhatsAppMessage.ts Updated convertRichTextToMarkdown import path to @typebot.io/lib/markdown.
.../lib/markdown/convertMarkdownToRichText.ts Added functionality for converting markdown to rich text using @udecode/plate-common and unified.
.../lib/markdown/convertRichTextToMarkdown.ts Refactored serialization process; updated import paths.
.../lib/markdown/deserializer/... Introduced deserialization functionality and types for Markdown to Slate.js format.
.../lib/markdown/remark-slate/... Provided functions and types for transforming Markdown AST nodes to Slate elements, text nodes, and handling transformations based on rules.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 26872e2 and bddec3e.
Files ignored due to path filters (4)
  • apps/docs/openapi/builder.json is excluded by: !**/*.json
  • packages/bot-engine/package.json is excluded by: !**/*.json
  • packages/lib/package.json is excluded by: !**/*.json
  • pnpm-lock.yaml is excluded by: !**/*.yaml
Files selected for processing (16)
  • packages/bot-engine/parseBubbleBlock.ts (2 hunks)
  • packages/bot-engine/whatsapp/convertInputToWhatsAppMessage.ts (1 hunks)
  • packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts (1 hunks)
  • packages/lib/markdown/convertMarkdownToRichText.ts (1 hunks)
  • packages/lib/markdown/convertRichTextToMarkdown.ts (1 hunks)
  • packages/lib/markdown/deserializer/deserialize.ts (1 hunks)
  • packages/lib/markdown/deserializer/types.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkDefaultElementRules.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkDefaultTextRules.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkPlugin.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkTextTypes.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkTransformElement.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkTransformElementChildren.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkTransformNode.ts (1 hunks)
  • packages/lib/markdown/remark-slate/remarkTransformText.ts (1 hunks)
  • packages/lib/markdown/remark-slate/types.ts (1 hunks)
Additional comments: 16
packages/lib/markdown/remark-slate/remarkTextTypes.ts (1)
  • 1-10: The definition of remarkTextTypes correctly lists markdown text node types that are likely to be processed for text styling or transformation. This setup is essential for distinguishing between different text styles during markdown deserialization.
packages/lib/markdown/deserializer/types.ts (1)
  • 1-8: The DeserializeMdPlugin interface is well-defined, including optional elementRules and textRules for customization of the deserialization process, and an indentList boolean to control list indentation. This structure allows for flexible configuration of markdown deserialization.
packages/lib/markdown/remark-slate/remarkTransformElement.ts (1)
  • 1-17: The remarkTransformElement function correctly applies transformation rules to markdown elements. It ensures that if no rule is found for an element type, an empty array is returned, preventing errors in the transformation process. This approach maintains robustness in handling various markdown elements.
packages/lib/markdown/remark-slate/remarkTransformElementChildren.ts (1)
  • 1-17: The remarkTransformElementChildren function is designed to recursively transform the children of a markdown node. It uses flatMap to handle nodes that transform into multiple elements, ensuring a flat structure for the transformed children. This method is crucial for accurately representing nested markdown structures in the target format.
packages/lib/markdown/remark-slate/remarkDefaultTextRules.ts (1)
  • 1-12: The remarkDefaultTextRules object correctly maps markdown text types to their respective transformations, including styling marks and handling HTML breaks. This setup ensures that text elements are transformed accurately, maintaining their intended styling and structure in the target format.
packages/lib/markdown/remark-slate/remarkPlugin.ts (1)
  • 1-18: The remarkPlugin function is well-implemented, using a custom compiler to transform markdown nodes. It correctly updates the lastLineNumber to maintain accurate line number tracking through transformations. This approach is essential for plugins that rely on line numbers for additional processing or error reporting.
packages/lib/markdown/remark-slate/remarkTransformNode.ts (1)
  • 1-20: The remarkTransformNode function effectively distinguishes between text and element nodes, applying the appropriate transformation based on the node type. This distinction is crucial for correctly handling different markdown constructs and ensuring their accurate representation in the target format.
packages/lib/markdown/deserializer/deserialize.ts (1)
  • 1-30: The deserialize function is correctly implemented to convert markdown into a rich text format. It utilizes the unified library with the remark-parse plugin and a custom remarkPlugin to apply transformation rules. This setup ensures a flexible and extensible markdown deserialization process.
packages/lib/markdown/remark-slate/remarkTransformText.ts (1)
  • 1-36: The remarkTransformText function adeptly transforms markdown text nodes, applying defined text rules and handling inherited mark properties. It ensures that text transformations are applied consistently, and inherited styles are preserved, which is essential for maintaining the intended styling of nested text elements.
packages/lib/markdown/convertRichTextToMarkdown.ts (1)
  • 1-33: The convertRichTextToMarkdown function is well-structured, handling the serialization of rich text elements into markdown format. It correctly deals with newlines and the serialization of variable nodes, ensuring that the generated markdown accurately represents the original rich text content.
packages/lib/markdown/remark-slate/types.ts (1)
  • 1-67: The types and interfaces defined in this file provide a comprehensive framework for the remark-slate transformation process. They ensure that the transformation rules and options are well-typed, facilitating the development of robust and error-resistant markdown processing logic.
packages/lib/markdown/convertMarkdownToRichText.ts (1)
  • 1-69: The convertMarkdownToRichText function is correctly implemented, utilizing the unified library and custom remark plugins to convert markdown into rich text. It sets up deserialization options and plugins, ensuring a flexible and customizable conversion process. This approach is essential for accurately transforming markdown content into the target rich text format.
packages/bot-engine/whatsapp/convertMessageToWhatsAppMessage.ts (1)
  • 3-9: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-6]

The update to the import path for convertRichTextToMarkdown reflects a reorganization of the codebase. This change is correctly applied, ensuring that the function is imported from its new location. It's crucial for maintaining the functionality of converting messages to the WhatsApp message format.

packages/bot-engine/whatsapp/convertInputToWhatsAppMessage.ts (1)
  • 5-11: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-8]

The update to the import path for convertRichTextToMarkdown is correctly applied, reflecting changes in the codebase structure. This ensures that the function is accessible from its new location, maintaining the ability to convert input blocks to WhatsApp messages.

packages/bot-engine/parseBubbleBlock.ts (1)
  • 14-17: The import of convertMarkdownToRichText from its new location is correctly applied, indicating a codebase reorganization. This change is essential for parsing bubble blocks, ensuring that markdown content is accurately converted to rich text.
packages/lib/markdown/remark-slate/remarkDefaultElementRules.ts (1)
  • 1-233: The remarkDefaultElementRules object comprehensively defines default transformation rules for various markdown elements. It ensures that elements are transformed accurately, maintaining their intended structure and styling in the target format. This setup is crucial for a robust and flexible markdown deserialization process.

@baptisteArno baptisteArno merged commit ff9c472 into main Jan 31, 2024
5 checks passed
@baptisteArno baptisteArno deleted the feat/improve-md-deserializing branch January 31, 2024 07:03
thercd pushed a commit to thercd/typebot.io that referenced this pull request Feb 2, 2024
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Updated markdown handling and serialization libraries for improved
performance and accuracy in text formatting.
- **New Features**
- Enhanced rich text and markdown conversion capabilities, providing
users with more reliable and seamless text formatting options.
- **Documentation**
- Added detailed documentation for markdown to rich text conversion and
vice versa, ensuring easier understanding and implementation for
developers.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

None yet

1 participant