Code

Redmine would not be a good project hosting and issue tracking tool without the ability to embed code in Wiki content. Furthermore, Redmine also allows you to highlight the syntax of embedded code.

Sometimes, for example, when you describe a class or a function, you may need to place a piece of code inline. There are two syntax rules that you can use in such cases.

First, you can enclose the code in the @ marker, as follows:

@Redmine::WikiFormatting@

Note

In Markdown, you should enclose the inline code in ` (grave accent).

Alternatively, you can use the HTML <code> tag for this, as follows:

<code>Redmine::WikiFormatting</code>

Both these rules produce the same result, but the <code> tag additionally allows you to specify which programming language is used by the code:

<code class="Lang">...</code>

Here, Lang should be replaced with the language name. The currently supported values of this parameter are C, CPlusPlus (C++), CSS, Clojure, Delphi (Object Pascal), Diff (used to view differences in Redmine), ERB (eRuby), Groovy, HAML, HTML, JSON, Java, JavaScript, PHP, Python, Ruby, SQL, XML, and YAML.

Besides inline code, it is often necessary to embed blocks of code. This also can be done in several ways in Redmine.

First, it is enough just to add more spaces before each line of code, as follows:

The code block:
    module Test
      class Klass
      end
    end

Note

For Textile, a single space is enough, but for Markdown you will need to add at least four spaces.

Note, however, that, as with most other block rules, such a block must be separated from other paragraphs by an empty line.

Alternatively, you can use the HTML <pre> tag:

<pre>
module Test
  class Klass
  end
end
</pre>

Note

For Markdown, you can use ~~~ as the first line and the last line of the code block.

Both of these methods produce the block of code, but the latter can also be modified to use syntax highlighting. Thus, to make the syntax of the code inside the <pre> tag highlighted, you can add the <code> tag, which has been described earlier, as follows:

<pre><code class="ruby">
    def self.included(base)
        base.send(:include, InstanceMethods)
        base.class_eval do
            unloadable

            alias_method_chain :repository_field_tags, :add
            alias_method_chain :subversion_field_tags, :add
            alias_method_chain :mercurial_field_tags,  :add
            alias_method_chain :git_field_tags,        :add
            alias_method_chain :bazaar_field_tags,     :add
        end
    end
</code></pre>

This markup will be rendered as shown in the following screenshot:

Code

Note

To enable syntax highlighting in Markdown, just add the language name after the ~~~ marker in the first line of the code block, like this:

~~~ ruby
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset