[PR #8909] feat: add Typewriter tool for converting Markdown text into HTML, PDF and DOCX files #26221

Closed
opened 2026-02-21 20:38:57 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/8909

State: closed
Merged: No


Checklist:

Important

Please review the checklist below before submitting your pull request.

  • Please open an issue before creating a PR or link to an existing issue
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Description

  • Introducing a new tool Typewriter for generating binary file
    • convert Markdown text to HTML file
      • using markdown library to convert markdown text into HTML file
    • convert Markdown text to PDF file
      • firstly using markdown library to convert markdown text into HTML file , then convert HTML into PDF by xhtml2pdf library
      • for the generated PDF file:
    • convert Markdown text to HTML file
      • only text paragraph with limited style support

Workflow with the introduced Typewriter tool:
image

Raw markdown text before converting:

# English
The Moon is a celestial body that orbits the Earth, with a diameter of about 3,474 kilometers.

# 月球
月球是一个围绕地球运行的星球,直径约为3474公里。

# 繁体中文
月球是一個圍繞地球運行的星球,直徑約為3474公里。

# 日本語
月は地球の周りを回る天体で、直径は約3474キロメートルです。

# Português
A Lua é um corpo celeste que orbita a Terra, com um diâmetro de cerca de 3.474 quilômetros.

Conversations for saved HTML:
image

Saved HTML file viewed in Google Chrome:
image

Conversation for saving PDF:
image

Saved PDF file viewed in Adobe Acrobat Reader 2024:
image

Saved DOCX file viewed in Microsoft Office for Mac 2024 16.89.1 (24091630):
image

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

Testing Instructions

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B
**Original Pull Request:** https://github.com/langgenius/dify/pull/8909 **State:** closed **Merged:** No --- # Checklist: > [!IMPORTANT] > Please review the checklist below before submitting your pull request. - [x] Please open an issue before creating a PR or link to an existing issue - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods # Description - Introducing a new tool `Typewriter` for generating binary file - convert Markdown text to HTML file - using `markdown` library to convert markdown text into HTML file - convert Markdown text to PDF file - firstly using `markdown` library to convert markdown text into HTML file , then convert HTML into PDF by `xhtml2pdf` library - for the generated PDF file: - limitation in fonts: the font support varies in different PDF viewers(Adobe Acrobat Reader, Chrome, MacOS Preview and etc.), since each PDF viewer embeds different font families - the suggested font list according to `xhtml2pdf`: https://xhtml2pdf.readthedocs.io/en/latest/reference.html#font - convert Markdown text to HTML file - only text paragraph with limited style support Workflow with the introduced Typewriter tool: <img width="1389" alt="image" src="https://github.com/user-attachments/assets/d0f7d9bc-e629-49c1-afa2-b3bb2a4eea21"> Raw markdown text before converting: ``` # English The Moon is a celestial body that orbits the Earth, with a diameter of about 3,474 kilometers. # 月球 月球是一个围绕地球运行的星球,直径约为3474公里。 # 繁体中文 月球是一個圍繞地球運行的星球,直徑約為3474公里。 # 日本語 月は地球の周りを回る天体で、直径は約3474キロメートルです。 # Português A Lua é um corpo celeste que orbita a Terra, com um diâmetro de cerca de 3.474 quilômetros. ``` Conversations for saved HTML: <img width="421" alt="image" src="https://github.com/user-attachments/assets/56820859-e106-4fea-b8e3-0504279ce6a3"> Saved HTML file viewed in Google Chrome: <img width="845" alt="image" src="https://github.com/user-attachments/assets/5f491248-a248-42dd-8018-d093a4643b45"> Conversation for saving PDF: <img width="419" alt="image" src="https://github.com/user-attachments/assets/260ccc2c-0000-47a6-bc30-a8ea355e2f5e"> Saved PDF file viewed in Adobe Acrobat Reader 2024: <img width="745" alt="image" src="https://github.com/user-attachments/assets/0e0c6581-8f2a-4ceb-aead-f9c1132c6eee"> Saved DOCX file viewed in Microsoft Office for Mac 2024 16.89.1 (24091630): <img width="816" alt="image" src="https://github.com/user-attachments/assets/7cab5a69-ff74-4719-acec-51e596bf79b9"> ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [ ] Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement - [ ] Dependency upgrade # Testing Instructions Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Test A - [ ] Test B
yindo added the pull-request label 2026-02-21 20:38:57 -05:00
yindo closed this issue 2026-02-21 20:38:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#26221