gpt4 book ai didi

html - emacs 是否为 html 模式提供隐藏显示

转载 作者:行者123 更新时间:2023-12-04 18:08:15 24 4
gpt4 key购买 nike

emacs 是否具有 html 的隐藏-显示代码折叠功能?我在使用 org 模式时拥有它,但似乎无法在 nXML/html 端找到它。

最佳答案

我为 mhtml-mode 编写了这个并且它工作得很好,它可以通过标签折叠 HTML 以及嵌入式 CSS 和 JS。只需将它添加到您的 emacs 配置文件中,您就可以开始了。

;; When called this automatically detects the submode at the current location.
;; It will then either forward to end of tag(HTML) or end of code block(JS/CSS).
;; This will be passed to hs-minor-mode to properly navigate and fold the code.
(defun mhtml-forward (arg)
(interactive "P")
(pcase (get-text-property (point) `mhtml-submode)
(`nil (sgml-skip-tag-forward 1))
(submode (forward-sexp))))

;; Adds the tag and curly-brace detection to hs-minor-mode for mhtml.
(add-to-list 'hs-special-modes-alist
'(mhtml-mode
"{\\|<[^/>]+?"
"}\\|</[^/>]*[^/]>"
"<!--"
mhtml-forward
nil))

正则表达式分解:

  • "{\\|<[^/>]+?" : 匹配 {或任何开始的 HTML 标签。它匹配但不包括结束 >在开始标签中。这允许 <script><style>标记被视为 HTML 标记而不是 JS 或 CSS。

  • "}\\|</[^/>]*[^/]>" : 匹配 }或结束标记。

关于html - emacs 是否为 html 模式提供隐藏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21342120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com