CodeHighlighter Extension for MediaWiki

WordPress용 Code Highlighter를 만들어보고 내친김에 MediaWiki용도 만들어보았다. ((CodeHighlighter MediaWiki Extension Site)) ((Screenshots)) 역시 MediaWiki쪽이 작성이 용이했는데 이유는 MediaWiki는 내용이 아직 wiki syntax일때 extension이 동작하기 때문에 html tag나 escape character같은 것에 신경을 쓰지 않아도 되고 또한 tag 이름만 정하면 알아서 tag내의 attribute까지 parsing해주기 때문이었다.

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

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

만약 code 태그안에 lang이라는 속성이 없으면 그냥 pre 태그로 치환된다.

Comments

  1. We like the code highlighter module very much. And seem to have corrected the issue with the nested pre statements when highlighting. Two lines in the extension is all we changed:

    First set the font-family to monospace (not neccessary, but makes text line up a bit better)
    $geshi->set_overall_style('font-family:monospace;font-size....

    Then use this option to geshi:
    $geshi->set_header_type(GESHI_HEADER_DIV);

    So far we have not seen any other problems with this method.

    ReplyDelete
  2. Thanks. I tested and it worked. :-)

    But it has a drawback. The border is not displayed. Usually, a theme has a style about pre tag. But if we use DIV option, the user should modify their css.

    But your solution is great if the user can modify the css. I will comment your solution to the extension site. Thanks again~

    ReplyDelete
  3. I just installed Code Highlighter and it works just fine, but only after I renamed CodeHighlighter.php to codehighlighter.php . Without doing that, Mediawiki would yield an error message about the "require("extensions/codehighlighter.php");".

    Perhaps this is only relevant for case sensitive operating systems. My Mediawiki runs on an Ubuntu server. Changing the line to

    require("extensions/CodeHighlighter.php");

    would probably do no harm.

    Thanks for the nice extension!

    ReplyDelete

Post a Comment

Popular Posts