Code strings |…|

Code strings are used to mark computer code within lines of text. This can be an instruction in a programming language, a mark in an easy markup language like Aneamal, a shell command, a keyboard shortcut, a byte sequence …

Code strings are usually printed in a monospaced font. Therefore they are also used in other contexts where a monospaced font is desirable, e.g. for length comparisons in nucleic acid sequences such as GATTACA.

The related code block markup can be used for code that deserves more space.

How to

Mark both the start and the end of a code string in your text with a vertical bar like in the examples below.

Inside a code string no phrase markup is interpreted except the backslash \ which marks a literal character.

Note that a code string can not stand at the very beginning of a paragraph. It would be confused for a code block there. However, you can put a code string into a bare string at the start of a paragraph like in the second example below.

Examples

The arrow |->| marks a link in Aneamal.

The arrow -> marks a link in Aneamal.

In the following example the code string is wrapped in backticks `…` which mark a bare string, because a code string can not stand at the very beginning of a paragraph.

`|sleep(1)|` delays the program execution in PHP.

sleep(1) delays the program execution in PHP.

In the following example the code string does not actually represent computer code. It is utilized to demonstrate that the word little has more characters than large. This would not be apparent in a proportional font.

Oddly, |little| is longer than |large|.

Oddly, little is longer than large.

For developers

When Aneamal is translated to HTML, a processed code string is turned into an HTML code element, so the examples become:

The arrow <code>-&gt;</code> marks a link in Aneamal.
<code>sleep(1)</code> delays the program execution in PHP.
Oddly, <code>little</code> is longer than <code>large</code>.

Browsers usually render the code element with a monospace font by default, but you can make this explicit with CSS. You can specify font families of your choice, but it is advisable to include the generic family monospace in the font declaration as well. This will guarantee that the code is displayed in a monospace font even when your preferred font families are not available.

Note that some browsers automatically display the generic monospace font with reduced font size. You can prevent this behaviour by adding the generic family in CSS twice:

code {
	font-family: "Source Code Pro", monospace, monospace;
}