textmate 代码片段
Creating blog posts has been greatly sped up by the use of TextMate. I've created a bunch of blog formatting commands to do various operations on posts including adding paragraph tags, formatting headings, and generating content based on string templates. One of my favorites is a PHP function that html-entitizes (your word of the day) code with PRE tags.
使用TextMate大大加快了创建博客帖子的速度。 我创建了许多博客格式化命令来对帖子进行各种操作,包括添加段落标签,格式化标题以及基于字符串模板生成内容。 我最喜欢的是一个PHP函数,HTML的实体化与PRE标记代码( 您一天的话 )。
PHP (The PHP)
function replace_angles($matches) {
return str_replace($matches[1],htmlentities($matches[1]),$matches[0]);
}
$file = file_get_contents('php://stdin');
$file = preg_replace_callback('/<pre.*?>(.*?)<\/pre>/imsu',replace_angles, $file);
echo $file;
The first step is reading in the buffer's contents. The next step is using PHP to extract the PRE code and replace it with htmlentities(code). Mission accomplished! I use this frequently within my blog -- maybe you can too.
第一步是读取缓冲区的内容。 下一步是使用PHP提取PRE代码并将其替换为htmlentities(code) 。 任务完成! 我经常在自己的博客中使用它-也许您也可以。
textmate 代码片段