Skip to content

Commit 09fe4f3

Browse files
authored
修复 Alert 前缀删除时会避免破坏 HTML 结构的问题 (#372)
1 parent 077b92b commit 09fe4f3

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

_multiplayer/feedback.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ contributors:
99

1010
## Terracotta | 陶瓦联机
1111

12-
<!--{% comment %}-->
1312
> [!TIP]
14-
> <!--{% endcomment %}-->
1513
> 欢迎您填写<a href="https://f.kdocs.cn/ksform/w/write/njMwdtgD?channel=mdlsjp" data-delay="10" data-redirect>反馈表单</a>。
16-
<!----{{'>'}}
17-
{: .notice--success }
18-
<!---->
1914
2015
我们注意到了 EasyTier 项目。它提供了一种简单、安全、去中心化的异地组网方案,足以承载 Minecraft 的联机需求。
2116
在 EasyTier 开发团队的帮助下,我们决定重新在启动器内提供联机服务。

_plugins/auto-alert.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,31 @@
1515
next unless first_child
1616
next unless first_child.name == "p"
1717

18-
text = first_child.text.downcase
18+
inner_html = first_child.inner_html.downcase
1919

2020
# 遍历所有 alert 类型
2121
alert_type.each do |type, data|
22+
prefix = "[!#{type}]"
23+
prefix_with_newline = "#{prefix}\n"
24+
2225
# 情况一:完整匹配 [!type] 形式 <p>[!NOTE]</p>
23-
if text == "[!#{type}]"
26+
if inner_html == prefix
2427
# 将 alert 类型对应的 class 加入 blockquote
25-
item['class'] = [item['class'], data["class_name"]].compact.join(" ")
28+
item["class"] = [item["class"], data["class_name"]].compact.join(" ")
2629

2730
# 将 <p> 替换为 <div> 并插入标题
2831
first_child.name = "div"
2932
first_child.inner_html = "<strong>#{data["title"]}</strong>"
3033
break
3134

3235
# 情况二:段落以 [!type]\n 开头 <p>[!NOTE]\n\n other content</p>
33-
elsif text.start_with? "[!#{type}]\n"
36+
elsif inner_html.start_with? prefix_with_newline
3437
# 将 alert 类型对应的 class 加入 blockquote
35-
item['class'] = [item['class'], data["class_name"]].compact.join(" ")
38+
item["class"] = [item["class"], data["class_name"]].compact.join(" ")
3639
# 在原段落前插入标题 <div><strong>提示</strong></div><p>[!NOTE]\n\n other content</p>
3740
first_child.add_previous_sibling "<div><strong>#{data["title"]}</strong></div>"
3841
# 移除段落内容开头的 [!type]\n <div><strong>提示</strong></div><p>\n other content</p>
39-
first_child.content = first_child.content.sub(/\A#{Regexp.escape("[!#{type}]\n")}/i, "")
42+
first_child.inner_html = first_child.inner_html[prefix_with_newline.length..-1] || ""
4043
break
4144
end
4245
end

0 commit comments

Comments
 (0)