Habari - RN Code Escape Plugin

I'm planning to migrate this WordPress blog to Habari. Some issues must be solved before actual migration take place. One of the issues is display source code in posts and comments.

Currently I'm using Code Auto Escape. Based on the code of Code Auto Escape, I've finished my first Habari plugin - RN Code Escape.

The function is similar as Code Auto Escape, but much more simple. It escape the characters "&", "<", "="">" within <code>...</code> tag into HTML entities &amp;, &lt;, &gt; automatically so that the source code can be pasted directly within <code>...</code> tag without the need to escape those characters manually.

Usage
For single line of code in post, just enclosed it with <code>...</code> tag. For multiple lines of code, enclose them with <pre><code>...</code></pre>

In comment, no need to add <pre>...</pre> tag for mutilple lines, it will be inserted automatically.

Changelog

  • Version 0.6 - Fix the problem of adding additional <pre>...</pre> tag for multiple lines of code in post
  • Version 0.7 - Fix the Atom feed problem for not shown all the content of code block

Download here (downloaded 507 times)

我在計劃將這個 blog 由 WordPress 轉至 Habari,在未真正實行前,有數個問題需要解決的,其中一個是在 post 和 comment 中直接顯示 source code。

現時我是使用 Code Auto Escape 的,參考了它的 source code,我寫了我第一個 Habari plugin - RN Code Escape。

功能和 Code Auto Escape 大同小異,只是更為簡單而已,它會將 <code>...</code> block 內的字符 "&"、"<"、">" 自動轉換成 HTML entities &amp;, &lt;, &gt;,這樣就可以直接將 source code 貼上,而不用自行將這些字符人手 escape。

使用方法
在文中如想貼一行的 source code 時,只需用 <code>...</code> 包圍著便可,如果是多行的 source code 時,就需使用 <pre><code>...</code></pre> 來包圍。

在留言中,就算是多行的 source code 也不用 <pre>...</pre> tag 的,它會自動加上去的。

更新

  • Version 0.6 - 修正了在 post 中多行 source code 時加入額外 <pre>...</pre> tag 的問題
  • Version 0.7 - 修正了 code block 不能在 Atom feed 正常顯示的問題

下載連結(已經下載了 507 次)

6 Responses to “Habari - RN Code Escape Plugin”

  1. 3191

    Hi, tried it here, it works OK (both 0.1.1 and rev 716)

    It would be better if you have time later to add features to allow rendering of text.

    Good work.

  2. 3203

    @sfong15:Syntax highlight or rendering text function in this plugin is not my first priority. I would like to reproduce the basic functionalities of this blog in Habari. Now, related posts, related tags for post, latest comments plugins are basically completed. Popular tag is in progress. Tag cloud, timesince plugins are planned. You can have a look in my testing Habari blog.

    Those all the plugins mentioned are relatively simple. Knowing the SQL statement and some PHP can do the job. I'm also considering about email alert after comment left, but it need much more knowledge about the action/filter hook of Habari and email handling in PHP. This is a much more difficult task for me.

  1. 5951 Because I Learn » Blog Archive » Testing code escape plugin
  2. 3293 Habari 0.2 Developer Review : 博客湾
  3. 3089 Habari 0.2 Developer Review - Nicky's blog
  4. 3240 在DreamHost上安装Habari - iHao Press™

Leave a Reply