Templat:Codebits
{{{1}}} |
||||
---|---|---|---|---|
|
Notes for Use
suntingUse
suntingTemplate name Codebits.
Used to display preformatted code lines, and to include notes. The methods used are to enclose the code blocks in either poem tags or the line-numbered version of the source tags in an attempt to regain some control over the widths of preformatted text lines. In case it is not obvious, both of these methods at the very least allow single line spacing and the wrapping of long lines: two essential factors for listing code.
The iwidth option sets the ititial width of the box, and the cwidth option sets the width of the content, when the box is open, and as a result, decides the wrapping width for long code lines within the content. This is regardless of whether the content text is surrounded with the poem tags or the line-numbered source tags, or is simply unformatted text. (See two examples below).
If contents are either an image or text in pre tags, then the open-width will extend to accommodate the contents. The use of the pre-wrap value of the CSS white-space property will in time allow the pre tags to wrap long lines, but not all browsers can use it at present.(8 Dec 2008).
Although the source tags deactivate code themselves, the poem tags need an inside set of nowiki tags for any code that would otherwise run. The example below shows how to arrange the content parameter for use with the poem tags:
An example of the drop control's use can be seen below:
Table Code Block |
||||
---|---|---|---|---|
|
Another format, that colors code, numbers the lines, and wraps any long code lines, uses the source tag extensions. The colors are selected for many languages and needs to be specified within the leading tag. Interestingly, the language can be specified as text, to take advantage of line numbering for unlisted languages. See Pre-Formatted Text for more details. The following example shows how to use the source tags for code coloring and the numbering of lines:
The coloured code can be seen in the dropbox below:
Source Tag Code Coloring |
||||
---|---|---|---|---|
|
Limitations
suntingBear in mind that the use of <pre></pre> tags might still be needed for some applications. If the block of text itself has these same tags within it, then the literals should be used to replace the ones within the text. (ie: use these instead; <pre> and </pre>). This avoids the corrupted functioning which would otherwise result. A similar method can be used to make literals for most other tags, such as nowiki, poem, and source, etc., should they ever need to be shown as inoperative text.
Parameters
sunting- Heading
- 1; the top heading on the drop-box - (Arial, Bold, in 400 pixel initial width)
- Content
- 2; the code text entry - (Courier, 400 pixels wide, left)
- Notes
- 3; the notes block - (Arial, 400 pixels wide, justified)
Options
sunting- iwidth
- initial width of the container,(default 300px)
- cwidth
- width of the open box; this sets the wrapping point for long lines. (Default 600px)
- align
- horizontal alignment of container (default left)