Skip to content

[PE-68] fix: markdown transformation of mention and custom image components#5864

Merged
SatishGandham merged 3 commits intopreviewfrom
fix/editor-markdown
Oct 22, 2024
Merged

[PE-68] fix: markdown transformation of mention and custom image components#5864
SatishGandham merged 3 commits intopreviewfrom
fix/editor-markdown

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Oct 18, 2024

Improvements:

  1. Added markdown parsing rules for custom components.
  2. Updated the UI and CTA link of the issue embed upgrade card.

Summary by CodeRabbit

  • New Features

    • Enhanced image serialization to Markdown format for both custom and read-only image extensions.
    • Added Markdown serialization for mentions, creating links with mention labels.
    • Updated IssueEmbedUpgradeCard for improved layout and dynamic styling.
  • Bug Fixes

    • Adjusted attributes for image nodes to ensure proper serialization.
  • Refactor

    • Simplified structure of the IssueEmbedUpgradeCard component for better readability and maintainability.
    • Improved styling approach for the IssueEmbedUpgradeCard component.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request introduces enhancements to several extensions within the editor package, focusing on Markdown serialization for images and mentions. The CustomImageExtension and CustomReadOnlyImageExtension now support serialization of image nodes into Markdown format, including new attributes like aspectRatio. The CustomMention extension has also been updated to serialize mention nodes into Markdown links. Additionally, the IssueEmbedUpgradeCard component has been refactored for improved styling and structure, including the removal of unnecessary elements and the use of a new button styling approach.

Changes

File Change Summary
packages/editor/src/core/extensions/custom-image/custom-image.ts Enhanced CustomImageExtension with Markdown serialization, added aspectRatio attribute.
packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts Updated CustomReadOnlyImageExtension for Markdown serialization of images.
packages/editor/src/core/extensions/mentions/extension.tsx Updated CustomMention extension to serialize mentions into Markdown links.
web/ce/components/pages/editor/embed/issue-embed-upgrade-card.tsx Refactored IssueEmbedUpgradeCard for improved styling and structure, replaced button with anchor tag.

Possibly related PRs

Suggested reviewers

  • Palanikannan1437
  • SatishGandham
  • rahulramesha

🐇 In the editor, we make a change,
With Markdown magic, it’s not so strange.
Images and mentions, all in a row,
Aspect ratios added, watch them grow!
Refactored cards, now sleek and bright,
Hop along, let’s code through the night! 🌙


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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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.

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (4)
web/ce/components/pages/editor/embed/issue-embed-upgrade-card.tsx (2)

10-15: LGTM: Improved styling approach with a minor suggestion

The use of the cn function for conditional styling is a good practice. It improves readability and maintainability of the component's styles.

Consider using a Tailwind CSS class for the border width instead of a custom value:

- "border-[0.5px] border-custom-border-200",
+ "border border-custom-border-200",

This change would align better with Tailwind's utility-first approach and maintain consistency with the rest of the codebase.


24-31: LGTM: Improved CTA implementation with a suggestion

The replacement of the Button component with an anchor tag is appropriate for external links. The use of getButtonStyling ensures consistent button styling across the application.

Consider adding an aria-label to the anchor tag to improve accessibility:

<a
  href="https://plane.so/pro"
  target="_blank"
  rel="noopener noreferrer"
+ aria-label="Upgrade to Plane Pro"
  className={cn(getButtonStyling("primary", "md"), "no-underline")}
>
  Upgrade
</a>

This addition will provide more context to screen reader users about the purpose of the link.

packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts (1)

61-61: Consider including the height attribute in serialized output

Currently, only the src and width attributes are included in the serialized <img> tag. If the height attribute is relevant for image rendering, consider including it in the output to ensure consistent display across different platforms.

Apply the following diff to include the height attribute:

- state.write(`<img src="${imageSource}" width="${attrs.width}" />`);
+ state.write(`<img src="${imageSource}" width="${attrs.width}" height="${attrs.height}" />`);
packages/editor/src/core/extensions/custom-image/custom-image.ts (1)

128-130: Consider including aspectRatio in the serialized output

Since you've added an aspectRatio attribute to the image node, you might want to include it in the serialized Markdown output if it's necessary for reconstructing the image during deserialization.

Suggestion:

Include the aspectRatio attribute in the <img> tag.

- state.write(`<img src="${imageSource}" width="${attrs.width}" />`);
+ state.write(`<img src="${imageSource}" width="${attrs.width}" aspectRatio="${attrs.aspectRatio}" />`);

This will ensure that the aspectRatio is preserved during the serialization and deserialization process.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 46302f4 and 79a9014.

📒 Files selected for processing (4)
  • packages/editor/src/core/extensions/custom-image/custom-image.ts (2 hunks)
  • packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts (2 hunks)
  • packages/editor/src/core/extensions/mentions/extension.tsx (2 hunks)
  • web/ce/components/pages/editor/embed/issue-embed-upgrade-card.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint-web
web/ce/components/pages/editor/embed/issue-embed-upgrade-card.tsx

[warning] 8-8:
Unexpected any. Specify a different type

🔇 Additional comments (8)
web/ce/components/pages/editor/embed/issue-embed-upgrade-card.tsx (2)

1-2: LGTM: Improved import for button styling

The addition of getButtonStyling from "@plane/ui" is a good practice. It centralizes button styling, which can lead to more consistent UI across the application and easier maintenance.

Also applies to: 5-6


17-22: LGTM: Improved content structure

The simplification of the inner content structure enhances readability and reduces unnecessary DOM nesting. The use of a p tag for the description text is semantically correct and improves accessibility.

packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts (3)

3-4: Imports added for Markdown serialization

The imports for MarkdownSerializerState and Node are correctly added to support the Markdown serialization functionality.


7-7: Importing ImageAttributes

The import of ImageAttributes from @/extensions/custom-image is appropriate and used correctly in the code.


57-64: Enhancing image handling with Markdown serialization

The addition of the markdown storage with a serialize method appropriately enhances image handling by enabling Markdown serialization for custom images.

packages/editor/src/core/extensions/mentions/extension.tsx (1)

3-4: Imports for Markdown serialization are appropriate

The addition of MarkdownSerializerState and Node imports is necessary for implementing the custom Markdown serialization functionality.

packages/editor/src/core/extensions/custom-image/custom-image.ts (2)

3-4: Imports are appropriate

The imports of MarkdownSerializerState and Node are necessary for implementing the Markdown serialization functionality.


8-8: Import statement for custom types

Importing CustomImageNode and ImageAttributes from @/extensions/custom-image ensures that the custom image node and its attributes are correctly referenced.

Copy link
Contributor

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 79a9014 and 6141071.

📒 Files selected for processing (3)
  • packages/editor/src/core/extensions/custom-image/custom-image.ts (2 hunks)
  • packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts (2 hunks)
  • packages/editor/src/core/extensions/mentions/extension.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/editor/src/core/extensions/custom-image/custom-image.ts
  • packages/editor/src/core/extensions/mentions/extension.tsx
🧰 Additional context used
🔇 Additional comments (3)
packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts (3)

3-4: LGTM: New imports for markdown serialization

The new imports for MarkdownSerializerState and Node are correctly added and necessary for the new markdown serialization feature.


7-7: LGTM: Updated import for ImageAttributes

The import statement has been correctly updated to include ImageAttributes, which is likely used in the new markdown serialization feature.


57-65: LGTM: New markdown serialization for images

The new markdown object with its serialize method is well-implemented. It correctly constructs an <img> tag with the necessary attributes, uses proper escaping, and maintains consistent image source resolution with the existing code.

markdown: {
serialize(state: MarkdownSerializerState, node: Node) {
const attrs = node.attrs as ImageAttributes;
const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src) || attrs.src);
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 18, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix invocation of getImageSource command

The current implementation doesn't address the issue raised in a previous review. The getImageSource command returns a function that needs to be invoked to get the actual image source. Currently, the function is not being called, which may result in imageSource being assigned a function instead of the expected string.

Apply the following diff to fix the issue:

- const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src) || attrs.src);
+ const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src)?.() || attrs.src);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src) || attrs.src);
const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src)?.() || attrs.src);

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check this issue. getImageSource is returning a function here

getImageSource: (path: string) => () => getAssetSrc(path),

Copy link
Contributor

Choose a reason for hiding this comment

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

@SatishGandham, thank you for bringing this to my attention. You're correct; in read-only-custom-image.ts, the getImageSource command returns a string directly, not a function. Therefore, the current implementation is correct, and my previous suggestion isn't necessary. I apologize for the oversight.

(>_<) Sorry about that.


✏️ Learnings added
Learnt from: SatishGandham
PR: makeplane/plane#5864
File: packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts:60-60
Timestamp: 2024-10-22T08:03:04.172Z
Learning: In `packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts`, the `getImageSource` command returns a string directly, not a function.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

markdown: {
serialize(state: MarkdownSerializerState, node: Node) {
const attrs = node.attrs as ImageAttributes;
const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src) || attrs.src);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check this issue. getImageSource is returning a function here

getImageSource: (path: string) => () => getAssetSrc(path),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants