Skip to main content

Yet Another CodeHighlighter Plugin

WordPress를 사용하여 코딩에 관한 글을 쓰려다가 DokuWiki에서 사용하던 것과 유사한 syntax highlighter가 있었으면 하는 생각에 몇개 찾아보다가 결국 원하는 플러그인을 찾지 못해 하나 만들어보았다. ((CodeHighlighter WordPress Plugin Site)) ((Screenshot: <pre lang="cpp">
struct D : public B
{
int i, j;
std::string s;
};
D d;
d.i = 1;
d.s = "code";
))

GeSHi Site 라이브러리를 사용하였는데 알고보니 DokuWiki의 code 태그가 이 라이브러리를 사용한 것이었다.

사용법은 pre 태그안에 lang이라는 속성을 다음과 같이 추가로 지정하면 된다.
<pre lang="cpp">

추가로 원하는 라인을 강조하고 싶다면 다음과 같이 em 속성을 추가한다.
<pre lang="cpp" em="2,3">

추가

찾아보니 WP-Dokuwiki라는 플러그인이 있다. 이 플러그인은 DokuWiki의 모든 문법을 WordPress상에서 제공한다. 물론 GeSHi를 사용하는 code 태그도 지원한다.

테마에 맞게 몇군데 수정을 가하고 WP-Dokuwiki를 사용하게 되었다.

Comments

  1. Are you still working on this plugin?
    I get this error when I activate it :(
    I am running Wordpress 1.5.1.2
    What am I doing wrong?
    Help me please!

    ReplyDelete
  2. Hi,

    how can I post source code which includes php and html statements?
    When I try it like this:

    ...code...

    then the html tags kill my layout
    does not work, too.

    ReplyDelete
  3. I should also note that i am using the latest 2.x version that is stable

    ReplyDelete
  4. I am noticing that when i have the CODE

    when i use a for loop it does not work properly, for instance if i have

    for($i = 0; $i

    ReplyDelete
  5. This plugin works nicely, but I can't get it to highlight PHP code of all things. It behaves as though it isn't finding the php.php file in geshi ... very strange. It highlights bash and SQL code.

    Thoughts?

    ReplyDelete
  6. Sorry. This plugin is not supported any more. Actually, I'm using the dokuwiki plugin for code highlighting in this WP. It supports almost all dokuwiki syntaxes that are very usuful to write technical articles. For example, it supports code highlighting, footnote, indentaion for reference , etc.

    Highlighting PHP code is not easy because it can have html codes with <. So I think your problem is not from geshi but from your php code itself. Sorry again~

    ReplyDelete
  7. Hi, Even though you no longer support this plugin, here is a patch for your users. If found that if you have a variable increment like '++pos' in C++ or any other language for that matter that the ++ was stripped of...

    Patch is as follows:


    --- codehighlighter.php 2006-11-06 20:17:32.000000000 +0100
    +++ /Users/arjenw/Desktop/codehighlighter/codehighlighter.php 2006-05-24 01:43:46.000000000 +0200
    @@ -35,7 +35,7 @@
    if ($matches[4] != null) {
    $em = explode(",", $matches[4]);
    }
    - $code = rawurldecode($matches[5]);
    + $code = urldecode($matches[5]);
    $tabstop = 2;

    if ($lang != null) {

    ReplyDelete
  8. [...] For my wordpress installation I looked around for a decent code highlighter without too much fuss. I found codehighlighter to be sufficient for my needs. The original author is no longer maintaining the package, so besides posting a patch there I am also putting it up here for anyone running into the same problem. [...]

    ReplyDelete

Post a Comment

Popular posts from this blog

1의 개수 세기 - 해답

벌써 어제 말한 내일이 되었는데 답을 주신 분이 아무도 없어서 좀 뻘쭘하네요. :-P 그리고 어제 문제에 O(1)이라고 적었는데 엄밀히 얘기하자면 O(log 10 n)이라고 적었어야 했네요. 죄송합니다. ... 문제를 잠시 생각해보면 1~n까지의 수들 중 1의 개수를 얻기 위해서는 해당 숫자 n의 각 자리의 1의 개수가 모두 몇개나 될지를 구해서 더하면 된다는 사실을 알 수 있습니다. 예를 들어 13이라는 수를 생각해 보면 1~13까지의 수에서 1의 자리에는 1이 모두 몇개나 되는지와 10의 자리에는 모두 몇개나 되는지를 구해 이 값을 더하면 됩니다. 먼저 1의 자리를 생각해 보면 1, 11의 두 개가 있으며 10의 자리의 경우, 10, 11, 12, 13의 네 개가 있습니다. 따라서 2+4=6이라는 값을 구할 수 있습니다. 이번엔 234라는 수에서 10의 자리를 예로 들어 살펴 보겠습니다. 1~234라는 수들 중 10의 자리에 1이 들어가는 수는 10, 11, ..., 19, 110, 111, ... 119, 210, 211, ..., 219들로 모두 30개가 있음을 알 수 있습니다. 이 규칙들을 보면 해당 자리수의 1의 개수를 구하는 공식을 만들 수 있습니다. 234의 10의 자리에 해당하는 1의 개수는 ((234/100)+1)*10이 됩니다. 여기서 +1은 해당 자리수의 수가 0이 아닌 경우에만 더해집니다. 예를 들어 204라면 ((204/100)+0)*10으로 30개가 아닌 20개가 됩니다. 이런 방식으로 234의 각 자리수의 1의 개수를 구하면 1의 자리에 해당하는 1의 개수는 ((234/10)+1)*1=24개가 되고 100의 자리에 해당하는 개수는 ((234/1000)+1)*100=100이 됩니다. 이들 세 수를 모두 합하면 24+30+100=154개가 됩니다. 한가지 추가로 생각해야 할 점은 제일 큰 자리의 수가 1인 경우 위의 공식이 아닌 다른 공식이 필요하다는 점입니다. 예를 들어 123에서 100의 자리에 해당하는 1의 개수는 ((123/1...

CodeHighlighter plugin test page.

This post is for testing CodeHighlighter plugin which uses GeSHi as a fontifier engine. ((Those code blocks are acquired from Google Code Search .)) ((For more supported languages, go CodeHighlighter plugin or GeSHi homepage.)) C++ (<pre lang="cpp" lineno="1">) class nsScannerBufferList { public: /** * Buffer objects are directly followed by a data segment. The start * of the data segment is determined by increment the |this| pointer * by 1 unit. */ class Buffer : public PRCList { public: Buffer() { ++index_; } PHP (<pre lang="php" lineno="4">) for ($i = 0; $i $value = ord( $utf8_string[ $i ] ); if ( $value < 128 ) { // ASCII $unicode .= chr($value); } else { if ( count( $values ) == 0 ) { $num_octets = ( $value } $values[] = $value; Lisp (<pre lang="lisp">) ;;; Assignment (define-caller-pattern setq ((:star var fo...

C++ of the Day #43 - SQLite3 C++ wrapper #1

The Definitive Guide to SQLite 를 읽다가 공부 겸 해서 C++ wrapper를 만들어 보았습니다. 최대한 C++ 냄새(?)가 나도록 만들어 보았습니다. :-) ((SQLite는 복잡한 관리가 필요없이 사용가능한, 파일이나 메모리 기반의, 라이브러리로 제공되는, 약 250kb 용량의, 대부분의 SQL92문을 지원하는, open source RDB입니다.)) 이 wrapper를 사용하기 위해서는 (당연하게도!) sqlite3 와 (당연하게도?) boost 라이브러리가 필요합니다. 사용 예들을 살펴보는 것으로 설명을 대신합니다. 이번 글에서는 다음과 같은 contacts 테이블이 test.db에 존재한다고 가정합니다. CREATE TABLE contacts ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, phone TEXT NOT NULL, UNIQUE(name, phone) ); Command 먼저 test.db 파일을 사용하기 위해 다음과 같이 파일 이름을 주어 connection 객체를 생성합니다. 생성과 동시에 test.db와 연결이 이루어집니다. ((생성자외에 open() 함수를 사용할 수도 있습니다.)) sqlite3pp::connection conn("test.db"); 다음은 contacts 테이블에 정보를 추가하는 가장 간단한 방법입니다. connection 클래스에서 제공하는 execute 함수를 사용합니다. ((executef 함수를 사용하면 printf와 같은 문법을 사용하여 query문을 작성할 수 있습니다.)) conn.execute("INSERT INTO contacts (name, phone) VALUES ('user', '1234')"); 위와 동일한 작업을 parameterized query를 사용하여 할 수도 있습니다. ((step()함수가 실제 query문을 수행하는 함수입니다. ...