如何在 TextMate 中启用 markdown 代码折叠?
我想在 textmate 中启用 markdown 的代码折叠。
具体来说,我希望任何标题(前面有一个或多个“#”字符的文本)成为在其与下一个标题和/或水平规则之间切换块的行。示例:
# Level 1 Heading - I'd like the block below to fold
The text I'd like to fold away
## Level 2 Heading
More text...
BBEdit 似乎对于 Markdown 来说做得很好。 TextMate 支持代码折叠,对于用成对(且缩进相同)花括号表示块的语言来说效果很好。
我知道 TextMate 提供了两个可以在语言语法文件中设置的变量,但我需要更多的正则表达式人才才能弄清楚。以下是当前代码折叠设置的 Markdown 语言语法中的内容:
foldingStartMarker = '(?x)
(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?>
|<!--(?!.*-->)
|\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/)))
)';
foldingStopMarker = '(?x)
(</(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)>
|^\s*-->
|(^|\s)\}
)';
非常感谢任何帮助!
I would like to enable code folding for markdown in textmate.
Specifically, I would like any headings (text preceded by one or more '#' characters) to be the line that would toggle blocks between it and the next heading and/or horizontal rule. Example:
# Level 1 Heading - I'd like the block below to fold
The text I'd like to fold away
## Level 2 Heading
More text...
BBEdit seems to do this just fine for markdown. TextMate supports code folding just fine for languages that denote blocks with paired (and identically indented) curly braces.
I know TextMate offers two variables you can set in the language grammar file, but I'd need more talent with regular expressions than I possess to figure it out. Following is what currently resides in the markdown language grammar for the code folding settings:
foldingStartMarker = '(?x)
(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?>
|<!--(?!.*-->)
|\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/)))
)';
foldingStopMarker = '(?x)
(</(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)>
|^\s*-->
|(^|\s)\}
)';
Any help greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TextMate 根本无法做到这一点。
TextMate 的语言解析器逐行读取文件。这意味着为了折叠代码,需要有一个开始标记和一个结束标记。如
和
。在这种情况下,由于除了下一节的开头之外,节的结尾没有被任何其他内容标记,因此逐行解析器无法返回并说空行应该标记代码折叠块的结尾。
这有道理吗?
TextMate flat-out can't do this.
TextMate's language parser reads files on a line-by-line basis. Which means that in order for code to be folded there needs to be a start marker AND an end marker. Like
<ul>
and</ul>
. In this case, since the end of a section is not marked by anything other than the start of the next section, the line-by-line parser cannot go back and say an empty line should mark the end of a code folded block.Does that make sense?
在 Macromates 博客 上,他们解释了如何为 Markdown 启用基本代码折叠。只要您在标题中使用“#”符号,就可以在标题级别折叠。
On the Macromates blog, they explain how to enable basic code folding for markdown. This lets you fold at the header level so long as you're using the "#" symbol for your headers.