[英]Can a CodeMirror 'mode' replace tags with colors?
I want to display an ansi
document (Unix terminal transcripts with escape codes to apply colors) in CodeMirror
, but there is no mode
for that. 我想在CodeMirror
显示ansi
文档(带有转义码的Unix终端脚本,以应用颜色),但是没有任何mode
。
I could try to make my own mode, and although it seems quite complicated, I haven't found any mode to use as a template that actually removes certain characters from the original content. 我可以尝试创建自己的模式,尽管看起来很复杂,但是我还没有找到任何可作为模板从实际内容中删除某些字符的模式。
I need to remove the escape characters and use them to mark the start or end of a color. 我需要删除转义字符,并使用它们来标记颜色的开始或结束。
Is this at all possible? 这是可能吗? Or does CodeMirror
by design lack the possibility to do this (remove characters in a mode
)? 还是CodeMirror
设计上没有做到这一点的可能性(以mode
删除字符)?
Any other ideas? 还有其他想法吗?
This is possible, but awkward. 这是可能的,但是很尴尬。 A mode won't do this (as you noticed, it doesn't remove characters -- you could style them display: none
, but that'll cause other problems. 一种模式不会执行此操作(如您所注意到的,它不会删除字符-您可以设置它们的display: none
样式display: none
,但这会引起其他问题。
An addon that listens for "change"
events and uses markText
1 to style and hide pieces of the document could work. 侦听"change"
事件并使用markText
1设置样式和隐藏文档片段的插件可以工作。 But making it clever (only updating the parts that change, rather than re-coloring the whole document on every change) requires some complexity. 但是,使其变得聪明(仅更新更改的部分,而不是对每次更改重新着色整个文档)需要一定的复杂性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.