[GH-ISSUE #14067] issue: Issues related to Markdown rendering of non-English chat content #87869

Closed
opened 2026-05-15 12:20:14 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Yu-QX on GitHub (May 20, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/14067

Check Existing Issues

  • I have searched the existing issues and discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Pip Install

Open WebUI Version

v0.6.5

Ollama Version (if applicable)

No response

Operating System

Windows 11

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have listed steps to reproduce the bug in detail.

Expected Behavior

Render different language properly.

Actual Behavior

When rendering chat content that includes Chinese, the application exhibits a noticeable anomaly, leading to the following phenomena:

  1. In sentences containing \(……\) formulas, if there are no English punctuation marks before or after, the display is abnormal. This issue commonly occurs with Chinese parentheses (\(……\)) and Chinese enumeration commas \(……\)、\(……\), while periods and commas do not have similar problems.
  2. In sentences with **……** bold formatting, encountering Chinese punctuation causes anomalies. This issue commonly arises in structures like **中文名称(English name)**中文内容 (directly followed by Chinese text).

Only common issues are reported here; the actual affected content may be more extensive. Testing shows that these rendering issues can be resolved by inserting an English space in the affected parts.

Since I frequently use this application as a note-taking tool, I hope to resolve display issues for all historical chat records. Rendering preprocessing is one solution. Before rendering, run the following code:

import re

def process_markdown(
        txt: str, 
        marking_symbols: list = [("\(","\)"), ("\[","\]"), "**", "*", "~~", "`", "$$", "$"],
        leagel_characters: str = ".,!?* 。,:"
    ):
    """
    Process the given text to make it rendered correctly in Markdown.
    
    :param txt: The text to be processed
    :param marking_symbols: A list of symbols used for marking, including both single and paired symbols
    :param leagel_characters: Characters that are allowed to appear before or after the marked text without adding a space
    :return: The processed text
    """
    result = ""

    # Split the input text into lines for processing
    for line in txt.split("\n"):
        line = " " + line + " " # in case nothing lies before/after the symbol
        # Iterate through each type of marking symbol
        for symbol in marking_symbols:
            if isinstance(symbol, str): start_sym, end_sym = symbol, symbol
            elif isinstance(symbol, tuple): start_sym, end_sym = symbol
            # Construct the regex pattern to match the marking symbols, ensuring they are not part of other symbols
            pattern = rf'(?<!{re.escape(start_sym)})({re.escape(start_sym)}[^{re.escape(end_sym)}]+{re.escape(end_sym)})(?!{re.escape(end_sym)})'
            parts = re.split(pattern=pattern, string=line)
            if len(parts) >= 3:
                line = parts[0]
                for i in range(1, len(parts)):
                    part = parts[i]
                    if   i % 2 != 0:
                        if line[-1] not in leagel_characters: line += " "
                    else:
                        if part[ 0] not in leagel_characters: line += " "
                    line += part
        line = line[1:-1] # remove the first and last character
        result += line + "\n"
    
    # Remove the last newline
    result = result[:-1]

    return result


if __name__ == "__main__":
    import pyperclip
    original = pyperclip.paste()
    processed = process_markdown(original)
    print("Original:\n", len(original))
    print("Processed:\n", len(processed))
    pyperclip.copy(processed)

This solution has been effective in all tested cases.

Steps to Reproduce

  1. Use a model that can speak different languages (deepseek series, especially);
  2. Ask it something about math or physics in Chinese;
  3. Try a few times if not succeeded.

You can also just type and send something like:

### Part 1: 加粗

**中文**加粗可以正常显示;

**中文(English)**加粗不能正常显示;

**中文(English)** 加粗可以正常显示。

---

### Part 2: 公式

Formula\(1+1\)cannot be displayed correctly;

Formula \(1+1\) can be displayed correctly.

公式\(1+1\)不能正常显示;

公式 \(1+1\) 可以正常显示;

Formula (\(1+1\)) can be displayed correctly.

Formula ( \(1+1\) ) can also be displayed correctly.

公式(例如 \(1+1\))不能正常显示;

公式(例如 \(1+1\) )可以正常显示。

公式(例如 \(1+1\)、\(1+2\) )不能正常显示;

公式(例如 \(1+1\),\(1+2\) )可以正常显示;

公式(例如 \(1+1\) 、 \(1+2\) )可以正常显示;

......

The following two pictures are among the cases.


Image
Image

Logs & Screenshots

Image Image

Additional Information

Although I'm not using the latest version, the issue seems to persist in the later versions since I haven't read about any changes in the rendering process. And the problem has been there since I installed the app last year. I used to correct it by hand.

Meanwhile, I am aware that adding a function will help. But that is only addressing the symptoms without tackling the underlying issue.

Originally created by @Yu-QX on GitHub (May 20, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/14067 ### Check Existing Issues - [x] I have searched the existing issues and discussions. - [ ] I am using the latest version of Open WebUI. ### Installation Method Pip Install ### Open WebUI Version v0.6.5 ### Ollama Version (if applicable) _No response_ ### Operating System Windows 11 ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [ ] I am using the latest version of **both** Open WebUI and Ollama. - [ ] I have included the browser console logs. - [ ] I have included the Docker container logs. - [x] I have listed steps to reproduce the bug in detail. ### Expected Behavior Render different language properly. ### Actual Behavior When rendering chat content that includes Chinese, the application exhibits a noticeable anomaly, leading to the following phenomena: 1. In sentences containing `\(……\)` formulas, if there are no English punctuation marks before or after, the display is abnormal. This issue commonly occurs with Chinese parentheses `(\(……\))` and Chinese enumeration commas `\(……\)、\(……\)`, while periods and commas do not have similar problems. 2. In sentences with `**……**` bold formatting, encountering Chinese punctuation causes anomalies. This issue commonly arises in structures like `**中文名称(English name)**中文内容 (directly followed by Chinese text)`. Only common issues are reported here; the actual affected content may be more extensive. Testing shows that these rendering issues can be resolved by inserting an English space in the affected parts. Since I frequently use this application as a note-taking tool, I hope to resolve display issues for all historical chat records. Rendering preprocessing is one solution. Before rendering, run the following code: ```python import re def process_markdown( txt: str, marking_symbols: list = [("\(","\)"), ("\[","\]"), "**", "*", "~~", "`", "$$", "$"], leagel_characters: str = ".,!?* 。,:" ): """ Process the given text to make it rendered correctly in Markdown. :param txt: The text to be processed :param marking_symbols: A list of symbols used for marking, including both single and paired symbols :param leagel_characters: Characters that are allowed to appear before or after the marked text without adding a space :return: The processed text """ result = "" # Split the input text into lines for processing for line in txt.split("\n"): line = " " + line + " " # in case nothing lies before/after the symbol # Iterate through each type of marking symbol for symbol in marking_symbols: if isinstance(symbol, str): start_sym, end_sym = symbol, symbol elif isinstance(symbol, tuple): start_sym, end_sym = symbol # Construct the regex pattern to match the marking symbols, ensuring they are not part of other symbols pattern = rf'(?<!{re.escape(start_sym)})({re.escape(start_sym)}[^{re.escape(end_sym)}]+{re.escape(end_sym)})(?!{re.escape(end_sym)})' parts = re.split(pattern=pattern, string=line) if len(parts) >= 3: line = parts[0] for i in range(1, len(parts)): part = parts[i] if i % 2 != 0: if line[-1] not in leagel_characters: line += " " else: if part[ 0] not in leagel_characters: line += " " line += part line = line[1:-1] # remove the first and last character result += line + "\n" # Remove the last newline result = result[:-1] return result if __name__ == "__main__": import pyperclip original = pyperclip.paste() processed = process_markdown(original) print("Original:\n", len(original)) print("Processed:\n", len(processed)) pyperclip.copy(processed) ``` This solution has been effective in all tested cases. ### Steps to Reproduce 1. Use a model that can speak different languages (deepseek series, especially); 2. Ask it something about math or physics in Chinese; 3. Try a few times if not succeeded. You can also just type and send something like: ```txt ### Part 1: 加粗 **中文**加粗可以正常显示; **中文(English)**加粗不能正常显示; **中文(English)** 加粗可以正常显示。 --- ### Part 2: 公式 Formula\(1+1\)cannot be displayed correctly; Formula \(1+1\) can be displayed correctly. 公式\(1+1\)不能正常显示; 公式 \(1+1\) 可以正常显示; Formula (\(1+1\)) can be displayed correctly. Formula ( \(1+1\) ) can also be displayed correctly. 公式(例如 \(1+1\))不能正常显示; 公式(例如 \(1+1\) )可以正常显示。 公式(例如 \(1+1\)、\(1+2\) )不能正常显示; 公式(例如 \(1+1\),\(1+2\) )可以正常显示; 公式(例如 \(1+1\) 、 \(1+2\) )可以正常显示; ...... ``` The following two pictures are among the cases. [ <img width="716" alt="Image" src="https://github.com/user-attachments/assets/107f4bdc-9163-4bf5-be9d-f957c0142594" /> <img width="743" alt="Image" src="https://github.com/user-attachments/assets/2dd04f0f-8af3-45cf-a14b-73d458f8ae1e" /> ](url) ### Logs & Screenshots <img width="716" alt="Image" src="https://github.com/user-attachments/assets/943723c1-dc7f-47bf-9d7b-96524b8a38ef" /> <img width="743" alt="Image" src="https://github.com/user-attachments/assets/9a47197d-d1d5-431c-830a-74f952003294" /> ### Additional Information Although I'm not using the latest version, the issue seems to persist in the later versions since I haven't read about any changes in the rendering process. And the problem has been there since I installed the app last year. I used to correct it by hand. Meanwhile, I am aware that adding a function will help. But that is only addressing the symptoms without tackling the underlying issue.
GiteaMirror added the bug label 2026-05-15 12:20:14 -05:00
Author
Owner

@Yu-QX commented on GitHub (May 20, 2025):

Oh, the code should be further modified to prevent further strange behaviors. It currently doesn't consider something like unclosed symbols.

<!-- gh-comment-id:2893846325 --> @Yu-QX commented on GitHub (May 20, 2025): Oh, the code should be further modified to prevent further strange behaviors. It currently doesn't consider something like unclosed symbols.
Author
Owner

@tjbck commented on GitHub (May 20, 2025):

Model output issue not following the standard Markdown/LaTeX format, with that being said, PR welcome here.

<!-- gh-comment-id:2894675514 --> @tjbck commented on GitHub (May 20, 2025): Model output issue not following the standard Markdown/LaTeX format, with that being said, PR welcome here.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#87869