mirror of
https://gitee.com/huanghongxun/HMCL-docs.git
synced 2025-12-15 00:42:39 +08:00
修复 Alert 前缀删除时会避免破坏 HTML 结构的问题 (#372)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
077b92be1d
commit
09fe4f3bdb
@ -9,13 +9,8 @@ contributors:
|
||||
|
||||
## Terracotta | 陶瓦联机
|
||||
|
||||
<!--{% comment %}-->
|
||||
> [!TIP]
|
||||
> <!--{% endcomment %}-->
|
||||
> 欢迎您填写<a href="https://f.kdocs.cn/ksform/w/write/njMwdtgD?channel=mdlsjp" data-delay="10" data-redirect>反馈表单</a>。
|
||||
<!----{{'>'}}
|
||||
{: .notice--success }
|
||||
<!---->
|
||||
|
||||
我们注意到了 EasyTier 项目。它提供了一种简单、安全、去中心化的异地组网方案,足以承载 Minecraft 的联机需求。
|
||||
在 EasyTier 开发团队的帮助下,我们决定重新在启动器内提供联机服务。
|
||||
|
||||
@ -15,14 +15,17 @@ Jekyll::Hooks.register [:pages, :documents], :post_convert do |doc|
|
||||
next unless first_child
|
||||
next unless first_child.name == "p"
|
||||
|
||||
text = first_child.text.downcase
|
||||
inner_html = first_child.inner_html.downcase
|
||||
|
||||
# 遍历所有 alert 类型
|
||||
alert_type.each do |type, data|
|
||||
prefix = "[!#{type}]"
|
||||
prefix_with_newline = "#{prefix}\n"
|
||||
|
||||
# 情况一:完整匹配 [!type] 形式 <p>[!NOTE]</p>
|
||||
if text == "[!#{type}]"
|
||||
if inner_html == prefix
|
||||
# 将 alert 类型对应的 class 加入 blockquote
|
||||
item['class'] = [item['class'], data["class_name"]].compact.join(" ")
|
||||
item["class"] = [item["class"], data["class_name"]].compact.join(" ")
|
||||
|
||||
# 将 <p> 替换为 <div> 并插入标题
|
||||
first_child.name = "div"
|
||||
@ -30,13 +33,13 @@ Jekyll::Hooks.register [:pages, :documents], :post_convert do |doc|
|
||||
break
|
||||
|
||||
# 情况二:段落以 [!type]\n 开头 <p>[!NOTE]\n\n other content</p>
|
||||
elsif text.start_with? "[!#{type}]\n"
|
||||
elsif inner_html.start_with? prefix_with_newline
|
||||
# 将 alert 类型对应的 class 加入 blockquote
|
||||
item['class'] = [item['class'], data["class_name"]].compact.join(" ")
|
||||
item["class"] = [item["class"], data["class_name"]].compact.join(" ")
|
||||
# 在原段落前插入标题 <div><strong>提示</strong></div><p>[!NOTE]\n\n other content</p>
|
||||
first_child.add_previous_sibling "<div><strong>#{data["title"]}</strong></div>"
|
||||
# 移除段落内容开头的 [!type]\n <div><strong>提示</strong></div><p>\n other content</p>
|
||||
first_child.content = first_child.content.sub(/\A#{Regexp.escape("[!#{type}]\n")}/i, "")
|
||||
first_child.inner_html = first_child.inner_html[prefix_with_newline.length..-1] || ""
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user