Geshi 与 Markdown
我正在尝试让 GeSHi 与 Markdown 一起使用。
Geshi 的一个简单用法如下:
$geshi = new GeSHi($message, 'c');
print $geshi->parse_code();
上面的代码接收整个消息并将其转换为突出显示的代码
我也有我的 Markdown 函数
print Markdown($message);
我试图使用回调函数来 preg_match
从 markdown 返回的标签,并对返回值运行
geshi->parse_code();
函数
这是我的代码
print preg_replace_callback(
'/<pre.*?>(.*?[<pre.*?>.*<\/pre>]*)<\/pre>/gism',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'$geshi = new GeSHi($matches[0], \'php\'); return $geshi->parse_code()'
),
Markdown($blog_res['message']));
我走在正确的轨道上吗?
我的正则表达式正确吗?它适用于http://gskinner.com/RegExr/
感谢您的帮助
Im trying to get GeSHi to work with markdown.
A simple use for Geshi is as follows:
$geshi = new GeSHi($message, 'c');
print $geshi->parse_code();
The above code takes in the whole of message and turns it into Highlighted code
I also have my Markdown Function
print Markdown($message);
I was trying to use call back function to preg_match
the <pre>
tags returned from markdown and run the geshi->parse_code();
function on the returned values
Here is my code
print preg_replace_callback(
'/<pre.*?>(.*?[<pre.*?>.*<\/pre>]*)<\/pre>/gism',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'$geshi = new GeSHi($matches[0], \'php\'); return $geshi->parse_code()'
),
Markdown($blog_res['message']));
Am i on the right track?
Is My Regex right? it works on http://gskinner.com/RegExr/
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了便于将来参考,您可能需要查看我的插件:
https://github.com/drm/Markdown_Geshi< /a>
它基于常规 Markdown 插件,添加了一个用 shebang 标记的块来突出显示代码,如下所示:
效果很好,我经常在自己的博客上使用它。
for future reference, you might want to check out my plugin for this:
https://github.com/drm/Markdown_Geshi
It is based on the regular markdown plugin adding a block marked with a shebang to highlight code, like this:
Works pretty well and I use it on my own blog regularly.
它是正则表达式 :(
而不是
use (删除全局标志)
但是如果您使用 markdown,您必须记住补偿自己的
code
块,因此您只需要替换格式为并省略
Hello
MyCode
因此您需要以下内容it was the regex :(
instead of
use (remove the global flag)
But if you are using markdown, you have to remember to compensate for the
code
blocks that are on thier own therefore you need to replace only the ones that are in the format of<pre><code>...MyCode</code></pre>
and leave outHello <code>MyCode</code>
Therefore you need the following我知道您希望扩展 Markdown,添加对 GeSHi 语法突出显示的支持。 Beautify 可以做到这一点以及更多。例如,它可以用 DOT 渲染图形。
Beautify 处理 GeSHi 代码块的方法与 drm/Markdown_Geshi 不同,因为使用了“栅栏”。例如:
我不确定这个问题活跃时 Beautify 是否还在,但它似乎值得在答案中提及。
I understand that you [were] looking to extend Markdown, adding support for GeSHi syntax highlighting. Beautify does this and more. For example, it can render graphs in DOT.
Beautify's approach to GeSHi code blocks differs from drm/Markdown_Geshi in that "fences" are used. For example:
I'm not sure if Beautify was around back when this question was active, but it seemed worthy of mention in an answer.