Skip to content

feat: support HTML preview #19162

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

LeeeeeeM
Copy link
Contributor

Summary

support HTML preview just like kimi

feat: #19159

Screenshots

2025-04-30 16 48 56

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. 💪 enhancement New feature or request labels Apr 30, 2025
@LeeeeeeM
Copy link
Contributor Author

2025-04-30 16 57 05

@LeeeeeeM LeeeeeeM mentioned this pull request Apr 30, 2025
5 tasks
@crazywoola
Copy link
Member

Can you DM me via wechat: crazyphage ?

@crazywoola crazywoola requested a review from Copilot April 30, 2025 09:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an HTML preview feature to the application, enabling users to preview HTML code similar to an existing feature in kimi. Key changes include:

  • New helper functions (isCompleteHTML, getPureContent) in utils.ts for processing HTML.
  • Integration of an HTML preview button in markdown.tsx that conditionally renders based on the language.
  • A new HTML preview component (HTMLPreviewBtn) with a fullscreen modal for rendering HTML content.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
web/app/components/base/utils.ts Added helper functions for HTML detection and content cleanup.
web/app/components/base/markdown.tsx Integrated HTML preview button and updated code block handling.
web/app/components/base/html-preview-button/index.tsx Implemented the HTML preview component with modal functionality.
Files not reviewed (1)
  • web/app/components/base/html-preview-button/style.module.css: Language not supported

Comment on lines 2 to 3
// simple check
const completeHTMLRegex = /<\s*html\s*[^>]*>[\s\S]*<\/html\s*>/i
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider enhancing the regex pattern in isCompleteHTML to cover potential edge cases (e.g., HTML documents with DOCTYPE declarations) or document that this is a simple check intended for basic use.

Suggested change
// simple check
const completeHTMLRegex = /<\s*html\s*[^>]*>[\s\S]*<\/html\s*>/i
/**
* A simple check to determine if the input string is a complete HTML document.
* This function supports optional <!DOCTYPE> declarations and comments before the <html> tag.
* Note: This is not a full HTML validator and may not handle all edge cases.
*/
const completeHTMLRegex = /^(?:<!DOCTYPE\s+html\s*[^>]*>\s*)?(?:<!--[\s\S]*?-->\s*)*<\s*html\s*[^>]*>[\s\S]*<\/html\s*>/i

Copilot uses AI. Check for mistakes.

>
<iframe
srcDoc={content}
sandbox="allow-scripts"
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Evaluate if including additional sandbox flags, such as allow-same-origin, may be necessary for proper rendering of relative resources in the preview, while ensuring that security implications remain acceptable.

Suggested change
sandbox="allow-scripts"
sandbox="allow-scripts allow-same-origin"

Copilot uses AI. Check for mistakes.

@asrguru20
Copy link

this is very good feature that if Dify got it It would be great I hope this pull merge soon thanks to LeeeeeeM

@asrguru20
Copy link

Summary

support HTML preview just like kimi

feat: #19159

Screenshots

2025-04-30 16 48 56 2025-04-30 16 48 56

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

cannot wait to have this in Dify

@crazywoola
Copy link
Member

@asrguru20 I think you can try this https://marketplace.dify.ai/plugins/svcvit/artifacts as well.

@asrguru20
Copy link

@asrguru20 I think you can try this https://marketplace.dify.ai/plugins/svcvit/artifacts as well.

Thanks crazywoola

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants