Javascript 如何用span标记替换特定的文本换行字符?
期望的行为 将Javascript 如何用span标记替换特定的文本换行字符?,javascript,regex,markdown-it,Javascript,Regex,Markdown It,期望的行为 将::text:替换为text 例如,给定如下字符串: Here is a ::test span:: and another ::span::, colons in this context eg: http://somelink.com are not effected. 如何将::字符替换为打开和关闭标记,如下所示: Here is a <span>test span</span> and another <span>span<
::text:
替换为text
例如,给定如下字符串:
Here is a ::test span:: and another ::span::, colons in this context eg:
http://somelink.com are not effected.
如何将::
字符替换为打开和关闭
标记,如下所示:
Here is a <span>test span</span> and another <span>span</span>, colons
in this context eg: http://somelink.com are not effected.
这是一个测试范围和另一个范围,冒号
在这种情况下,例如:http://somelink.com 不受影响。
我尝试过的
实际上,我试图复制以下行为:
这是一个非常有用的插件,因为它似乎有一个bug(我不知道如何修复),它已经:
代码中有一个错误导致创建两次span标记
::spanned:: => <span><span>spanned</span></span>
::跨距::=>跨距
另外,像http:
这样的输入被转换成http::
编辑:
我刚刚在这里遇到了类似的问题,可能会有答案
使用regex
/::([^::]+)::/g这似乎很简单:
var s='这里有一个::test span::和另一个::span::冒号,在这个上下文中例如:http://somelink.com 未生效。”;
log(s.replace(/::([^::]+)::/g,“$1”)代码>使用正则表达式/::([^::]+)::/g这似乎很简单:
var s='这里有一个::test span::和另一个::span::冒号,在这个上下文中例如:http://somelink.com 未生效。”;
log(s.replace(/::([^::]+)::/g,“$1”)代码>这是一个非常简单的方法。这个对我有用:(::)([\w\s]+)(::)
用$2
替换它
::text::=>text
::跨距::=>跨距
下面是一个::test span::和另一个::span::冒号,在这个上下文中例如:
http://somelink.com 不受影响。
=>
这是一个测试跨距和另一个跨距,冒号在这里
上下文,例如:
http://somelink.com 不受影响。
这是一个非常简单的方法。这个对我有用:(::)([\w\s]+)(::)
用$2
替换它
::text::=>text
::跨距::=>跨距
下面是一个::test span::和另一个::span::冒号,在这个上下文中例如:
http://somelink.com 不受影响。
=>
这是一个测试跨距和另一个跨距,冒号在这里
上下文,例如:
http://somelink.com 不受影响。
但是我认为这个字符:
应该转义,我错了吗?但是我认为这个字符:
应该转义,我错了吗?
::text:: => <span>text</span>
::spanned:: => <span>spanned</span>
Here is a ::test span:: and another ::span::, colons in this context eg:
http://somelink.com are not effected.
=>
Here is a <span>test span</span> and another <span>span</span>, colons in this
context eg:
http://somelink.com are not effected.