# Discourse中代码块格式问题——红色文本和意外高亮

**URL:** <https://meta.discourse.org/t/issue-with-code-block-formatting-in-discourse-red-text-and-unintended-highlighting/321315>\
**Category:** Product Support\
**Tags:** code\
**Created:** [2024 年8 月 12 日 18:09 UTC](https://meta.discourse.org/t/issue-with-code-block-formatting-in-discourse-red-text-and-unintended-highlighting/321315 "2024-08-12T18:09:22Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![alex10](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alex10/32/575949_2.png) [@alex10](https://meta.discourse.org/u/alex10)\
发布日期： [2024 年8 月 12 日 18:09 UTC](https://meta.discourse.org/t/issue-with-code-block-formatting-in-discourse-red-text-and-unintended-highlighting/321315/1 "2024-08-12T18:09:22Z")

</div>

我在 Discourse 中遇到了代码块格式化问题。在发布 Python 代码时，代码的某些部分（例如 URL 和路径）会显示为红色或以意外方式格式化，如下图所示：

 ![Screenshot 2024-08-12 at 10.57.15 AM](https://global.discourse-cdn.com/meta/original/4X/5/0/5/5058e6bc4c259ce755d3893896e45d2bfe380edd.png)

**问题描述**

- 当我使用三个反引号创建代码块发布 Python 代码时，文本的特定部分（如 URL 或路径中的下划线）会显示为红色或格式错误。
- 我尝试过转义字符、使用 HTML 实体以及通过不指定语言来移除语法高亮，但问题仍然存在。

**代码示例**

以下是导致问题的代码片段（Python）：

import degirum as dg  
zoo = dg.connect(dg.CLOUD, “[https://cs.degirum.com](https://cs.degirum.com)”, “”)  
model = zoo.load\_model(“mobilenet\_v2\_ssd\_coco–300x300\_quant\_n2x\_orca\_1”)  
result = model(“[https://docs.degirum.com/images/samples/TwoCats.jpg](https://docs.degirum.com/images/samples/TwoCats.jpg)”)  
display(result.image\_overlay)

**我尝试过的方法**

- 使用反斜杠转义下划线。
- 使用 HTML 实体替换下划线。
- 通过在代码块中不指定 `python` 来移除语法高亮。
- 将代码作为纯文本发布，不进行任何格式化。

**设置信息**

- 在设置中，以下是高亮显示的语言：
- bash, c, cpp, csharp, css, diff, go, graphql, ini, java, javascript, json, kotlin, lua, makefile, markdown, objectivec, perl, php, php-template, plaintext, python, python-repl, r, ruby, rust, scss, shell, sql, swift, typescript, xml, yaml, wasm

**寻求支持**

- 是否有其他人遇到过此问题？
- 有没有推荐的方法可以防止 Discourse 错误解析代码的某些部分？
- 是否有任何设置或配置我应该检查，这些设置或配置可能会影响代码块的渲染？

---

_[View the full topic](https://meta.discourse.org/t/issue-with-code-block-formatting-in-discourse-red-text-and-unintended-highlighting/321315)._
