-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe overall change shifts the markdown serialization and deserialization logic from Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
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 optionalelementRules
andtextRules
for customization of the deserialization process, and anindentList
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 usesflatMap
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 thelastLineNumber
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 theunified
library with theremark-parse
plugin and a customremarkPlugin
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 theunified
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.
<!-- 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 -->
Summary by CodeRabbit