textmate 代码片段_使用PHP在TextMate中的PRE标签内格式化代码

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) 。 任务完成! 我经常在自己的博客中使用它-也许您也可以。

翻译自: https://davidwalsh.name/format-code-pre-tags

textmate 代码片段

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值