Code Formatting Module

Code Formatting plugin Moduleは、{code}マクロにあなたが新しい言語を加えることを可能にします。
コード・マクロが起動される場合は常に、マクロは利用可能なフォーマットpluginsにサポートされた言語と「言語」パラメーターを照合し、ソース・コードをフォーマットするためにそのpluginを使用します。

Code Formatting Plugins

下に、コード片の例を紹介します。
   <atlassian-plugin name="My Formatter" key="confluence.extra.formatters">
       ...
       <codeformatter name="ruby" key="ruby" class="com.example.confluence.formatters.RubyFormatter">
           <description>Code formatter for the Ruby programming language</description>
       </codeformatter>
       ...
   </atlassian-plugin>

クラス属性は、利用可能なフォーマッタに加えられるクラスを定義します。
このクラスはcom.atlassian.renderer.v2.macro.code.SourceCodeFormatterを実装している必要があります。

The SourceCodeFormatter Interface

次の簡単なインターフェイスを実装する必要があります。
   package com.atlassian.renderer.v2.macro.code;

   /**
    * Strategy for converting a block of source code into pretty-printed HTML. SourceCodeFormatters MUST be forgiving:
    * they will be dealing with user-supplied input, so they can't afford to blow up on bad data.
    */
   public interface SourceCodeFormatter
   {
       /**
        * Inform the CodeMacro which languages this formatter supports. So if someone writes {code:java}, then only
        * the formatter that returns "java" from this method will be used to format it.
        *
        * @return an array of languages that this formatter supports
        */
       String[] getSupportedLanguages();

       /**
        * Convert source code into HTML.
        *
        * @param code the source code as a string
        * @param language the programming language that it is believed this code is written in
        * @return the source code formatted as HTML
        */
       String format(String code, String language);
   }

Formatter Priority

There is no concept of priority for formatters. If two formatters are installed and both return the same value from getSupportedLanguages(), one will be selected pretty much at random. If you want to avoid this behaviour, deactivate formatters that you no longer want to use.

タグ:

+ タグ編集
  • タグ:
最終更新:2012年07月03日 10:01