简体   繁体   English

Atlassian Confluence:自定义代码宏 - 画笔语法中的分号导致错误

[英]Atlassian Confluence: custom code macro - semicolon in brush syntax causes error

I tried to write a custom code macro syntax for a language that uses semicolon as a comment character.我尝试为使用分号作为注释字符的语言编写自定义代码宏语法。

This shows how to do this: http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/这显示了如何做到这一点:http: //alexgorbatchev.com/SyntaxHighlighter/manual/brushes/

My regex looks like this:我的正则表达式如下所示:

{ regex: new RegExp(';(.*)$', 'gm'), css: 'comments' },

But this not only makes the line with the semicolon green, it also does funny things to other lines:但这不仅使带有分号的行变成绿色,而且还对其他行做了一些有趣的事情:

exten => s,n,Hangup becomes exten =>; s,n,Hangup exten => s,n,Hangup变为exten =>; s,n,Hangup exten =>; s,n,Hangup ( Note: it added a semicolon after the right angle bracket! ) where everything behind the semicolon is green! exten =>; s,n,Hangup注意:它在右尖括号后添加了一个分号! )分号后面的所有内容都是绿色的!

Why is this?为什么是这样? How ist the right syntax for comments with semicolons?带分号的注释的正确语法如何?

I know this question is old, but I had the same problem for days now and finally found the solution to fix this, so I wanted to share it with everyone having the same issue.我知道这个问题很老了,但是我这几天都遇到了同样的问题,终于找到了解决这个问题的解决方案,所以我想与遇到同样问题的每个人分享。

The Code Block Macro from Confluence uses the <![CDATA[ content ]]> tag to store the code inside the macro in the database. Confluence 的代码块宏使用<![CDATA[ content ]]>标签将代码存储在数据库中的宏中。 The rendering process then tries to render the page and hands over the CDATA tag and its content to the macro.呈现过程然后尝试呈现页面并将 CDATA 标记及其内容移交给宏。 Neither Confluence nor the macro want < , > and & to be rendered as html tags, so they convert them to the html-code &lt; Confluence 和宏都不希望<>&被呈现为 html 标签,因此它们将它们转换为 html 代码&lt; , &gt; , &gt; and &amp;&amp; . .

And now we run in the problem with the RegExp现在我们遇到了 RegExp 的问题

{ regex: new RegExp(';(.*)$', 'gm'), css: 'comments' },

The expression finds the ;表达式找到; from the html-code elements and wraps them into a code tag with the 'comments' class.从 html-code 元素中提取并将它们包装到带有“comments”类的代码标记中。 Then the matches get put together and you will find the result you got.然后将匹配放在一起,您将找到您得到的结果。 Because the assembling works with positions and offsets, the > won't get replaced instead the new code tag will just be added.因为组装使用位置和偏移量, >不会被替换,而是只会添加新的代码标签。

To fix this, you can just catch the &lt;要解决这个问题,你可以抓住&lt; , &gt; , &gt; and &amp;&amp; before your RegExp so these elements won't be matches twice.在您的 RegExp 之前,因此这些元素不会匹配两次。

this.regexList = [
{ regex: new RegExp('(\\&lt;|<)|(\\&gt;|>)|(\\&amp;|\\&)', 'gm'), css: 'plain' },
{ regex: new RegExp(';(.*)$', 'gm'), css: 'comments' }];

The same effect happens when you paste a non-breakable-space as the character and not as the html-code &nbsp;当您将不可破坏的空格粘贴为字符而不是 html 代码&nbsp;时,会发生相同的效果。 inside the Code-Block-Macro.在代码块宏内。 I couldn't find a way to fix this, because they get converted when used in a normal text editor to a "normal" space.我找不到解决此问题的方法,因为它们在普通文本编辑器中使用时会转换为“普通”空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM