Jump to content

Template:Markup/doc: Difference between revisions

Created page with "{{Documentation subpage}} <!-- Categories where indicated at the bottom of this page, please. --> {{TOC right |limit=2}} This template is used to present markup or code side by side with the output it renders. ==Usage== Each pair of {{tl|Markup}}'s arguments should be two copies of some wikitext markup, with the first of the pair enclosed in {{xtag|nowiki}} tags. The template produces output in two columns, the first showing the markup and the second showing how it..."
>Rusty.perrin
(Link to source on wikipedia)
 
(Created page with "{{Documentation subpage}} <!-- Categories where indicated at the bottom of this page, please. --> {{TOC right |limit=2}} This template is used to present markup or code side by side with the output it renders. ==Usage== Each pair of {{tl|Markup}}'s arguments should be two copies of some wikitext markup, with the first of the pair enclosed in {{xtag|nowiki}} tags. The template produces output in two columns, the first showing the markup and the second showing how it...")
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
{{tc}}
<!-- Categories where indicated at the bottom of this page, please. -->
<!-- Categories and interwikis go at the bottom of this page. -->
{{TOC right |limit=2}}
 
This template is used to present markup or code side by side with the output it renders.


==Usage==
==Usage==
This template is used to present markup or code side by side with the rendered output.
Each pair of {{tl|Markup}}'s arguments should be two copies of some [[wikitext]] markup, with the first of the pair enclosed in {{xtag|nowiki}} tags. The template produces output in two columns, the first showing the markup and the second showing how it is rendered. The template accepts up to 40 unnamed parameters, resulting in up to 20 rows of examples.


Parameters:
This:
* unnamed 1: Content of row 1, column 1
<pre>
* unnamed 2: Content of row 1, column 2
{{markup|&lt;nowiki>'''Bold text'''&lt;/nowiki>|'''Bold text'''}}
:through
</pre>
* unnamed 39: Content of row 20, column 1
* unnamed 40: Content of row 20, column 2


* '''t1''': Title of column one; defaults to ''Markup''
Produces this:
* '''t2''': Title of column two; defaults to ''Renders as''
{{markup|<nowiki>'''Bold text'''</nowiki>|'''Bold text'''}}
* '''title''': Title of table; defaults to none
* '''notitle''': When set, suppresses table and column titles
* '''margin''': set table left margin in em


The ''Markup'' cell is pre-formatted with {{tag|pre|o}} to retain newlines and spaces, but styled to allow content to wrap within the cell. It is usually desirable to escape the content of the ''Markup'' cell so that the markup is displayed by wrapping the markup in {{xtag|nowiki}}. It is technically not possible to add this feature to the template.
In many cases, the markup for both columns are identical, but there are instances where this may need to differ. If none of these issues apply, then you may use {{tls|mra}} to save yourself from copying the code twice.
* Header markup such as {{code|1===}} will show in the page table of contents; to avoid this, use {{tlx|fake heading}} in the markup for the second column (see example [[#A complex example|below]]).
* Some templates will place the page in a maintenance category, which is usually undesired. For example.
** Instead of {{tlx|citation needed}}, use {{tlx|fake citation needed}} in the second column.
* Some templates may have error checking that places the page in a maintenance category.
** <s>{{cs1}} templates with errors: add {{para|template doc demo|true}} to the template in the second column.</s>
** To avoid this and the associated red error messages make sure that each example on the page uses different sources.
* HTML entities are parsed in the first cell, even with {{xtag|nowiki}} tags. To work around this, replace the <code>&</code> with <code>&amp;amp;</code> in the first column (see example [[#With HTML entities|below]]).


In the ''Renders as'' cell, the content is usually the unescaped markup copied from the ''Markup'' cell. There are instances where this may differ:
It is advisable to begin both copies of the markup with a [[newline]]; this is necessary if the first line of the markup must start on a new line (such as #, *  or ;).
* If the first line includes wikimarkup that must start on a new line such as #, *  or ; then use {{tl|crlf2}} before the first line; see examples below.
* Header markup such as {{code|1===}} will show in the page table of contents; use {{tlx|fake heading}}.
* When using {{tlx|reflist}} with no other parameters, use {{tlx|reflist|close}} to ensure that the reference list is closed.
* Some templates will place the page in a maintenance category, which is usually undesired:
** Instead of {{tlx|citation needed}}, use {{tlx|fake citation needed}}.
* Some template may have error checking that places the page in a maintenance category. Suppress the category as possible:
** {{cs1}} templates can suppress the maintenance category by setting {{para|template doc demo|true}}.


==Limitations==
==Examples==
If you don't wrap the content of the markup cell in {{xtag|nowiki}}, then any template markup will not be escaped, it will be expanded.


This example shows the markup for <nowiki>{{tl|tag}}</nowiki>:
===Multiple rows===
 
{{markup
{{markup|t1=Renders as|t2=Expected rendering
|<nowiki>'''Bold text'''</nowiki>|'''Bold text'''
|{{tl|tag}}
|<nowiki>''Italic text''</nowiki>|''Italic text''
|<nowiki>{{tl|tag}}</nowiki>
|<nowiki>[[Internal link]]</nowiki>|[[Internal link]]
|<nowiki>
{{cite book|ref=none|last=Smith|year=2021|title=Smith's book}}
</nowiki>|
{{cite book|ref=none|last=Smith|year=2021|title=Smith's book}}
|<nowiki>
<score>\relative c' { c( b~ c b c b c b c~ c)}</score>
</nowiki>|
<score>\relative c' { c( b~ c b c b c b c~ c)}</score>
}}
}}


HTML entities are parsed in the markup cell
===With custom title and column headers===
{{markup|t1=Nowikied markup shows as |t2=Expected markup
{{Markup
|<nowiki>&nbsp;&ndash;</nowiki>
| title=How to write about foxes and dogs in Wikipedia.
|&amp;nbsp;&amp;ndash;
|t1=Write this in wikitext|t2=and this will appear in the article.
| The quick brown [[fox]] jumps over the lazy [[dog]]. | The quick brown [[fox]] jumps over the lazy [[dog]].
}}
}}


To work around this, replace the <code>&</code> with <code>&amp;amp;</code> thus <code>&amp;amp;nbsp;</code> will show as <code>&amp;nbsp;</code>
===A complex example===
 
==Examples==


'''Simple examples:'''
In this example, {{tl2|Markup}}'s second argument here uses {{tl2|fake heading}} (to avoid headings appearing in the table of contents) and {{tl2|fake citation needed}} (to avoid adding this page to the maintenance list).
{{markup
|<nowiki>'''Bold text'''</nowiki>|'''Bold text'''
|<nowiki>''Italic text''</nowiki>|''Italic text''
}}


'''Complex example:'''
{{Markup
Note that the second argument to {{tl2|markup}} uses {{tl2|fake heading}} and {{tl2|fake citation needed}}.
| <nowiki>The quick brown fox jumps over the lazy dog.{{#tag:ref|A footnote.<ref>A reference for the footnote.</ref>|group=nb}} The cow jumped over the moon.{{fact}}
{{markup
|<nowiki>The quick brown fox jumps over the lazy dog.{{#tag:ref|A footnote.<ref>A reference for the footnote.</ref>|group=nb}} The cow jumped over the moon.{{fact}}


==Notes==
== Notes ==
{{Reflist|group=nb}}
{{reflist|group=nb}}


==References==
== References ==
{{Reflist}}
{{reflist}}
</nowiki>
</nowiki>
|The quick brown fox jumps over the lazy dog.{{#tag:ref|A footnote.<ref>A reference for the footnote.</ref>|group=nb}} The cow jumped over the moon.{{fake citation needed}}
| The quick brown fox jumps over the lazy dog.{{#tag:ref|A footnote.<ref>A reference for the footnote.</ref>|group=nb}} The cow jumped over the moon.{{fake citation needed}}


{{fake heading|sub=3|Notes}}
{{fake heading|sub=2|Notes}}
{{Reflist|group=nb}}
{{reflist|group=nb}}


{{fake heading|sub=3|References}}
{{fake heading|sub=2|References}}
{{Reflist|close}}
{{reflist|close}}
}}
}}


'''Multiple rows:'''
===With HTML entities===
HTML entities are parsed in the markup cell. To work around this, replace the <code>&</code> with <code>&amp;amp;</code> in the first column.
<pre>
{{Markup| &lt;nowiki>&amp;amp;ndash;</nowiki> | &amp;ndash;}}
</pre>
renders as:
{{Markup| <nowiki>&amp;ndash;</nowiki> | &ndash;}}
 
===With the glyphs "|" and "="===
If the markup contains the [[Glyph|glyph]]s <code>[[Vertical bar{{!}}|]]</code> or <code>[[Equals sign|=]]</code> they need to be replaced by the [[Help:Magic words#Other|magic words]] <code>[[:mw:Help:Magic_words#Other|<nowiki>{{!}}</nowiki>]]</code> or <code>[[:mw:Help:Magic_words#Other|<nowiki>{{=}}</nowiki>]]</code>. If not they are being interpreted for the Template:Markup itself as a separator between the parameters or between the parameter name and value! So as an example use:
<pre>
{{markup
|&lt;nowiki>use <code>|lang = en</code></nowiki>
|use <code>{{!}}lang {{=}} en</code>
}}
</pre>
which renders as:
{{markup
{{markup
|The quick brown fox jumps over the lazy dog.
|<nowiki>use <code>|lang = en</code></nowiki>
|The quick brown fox jumps over the lazy dog.
|use <code>{{!}}lang {{=}} en</code>
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
|The quick brown fox jumps over the lazy dog.
}}
}}


'''With title:'''
===More examples===
{{markup|title=Foxes and dogs
 
|The quick brown fox jumps over the lazy dog.
{{Markup|<nowiki>
|The quick brown fox jumps over the lazy dog.
{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}
</nowiki>|
{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}
|<nowiki>
{{code|lang=html|{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}}}
</nowiki>|
{{code|lang=html|{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}}}
}}
}}


When a template is enclosed within {{tl|code}}, it shows the rendered HTML:
==Typing aid: template {{tl|mra}}==
{{tl|mra}} will duplicate the source text automatically, saving you the trouble of copying the text and adding {{xtag|nowiki}} tags to the first case.
 
This:
<pre>{{subst:mra|'''Bold text'''|''Italic text''}}</pre>
 
Will produce this:
<pre>{{markup|
&lt;nowiki>'''Bold text'''</nowiki>|'''Bold text'''|
&lt;nowiki>''Italic text''</nowiki>|''Italic text''}}</pre>


{{markup
Which renders as:
|<nowiki>{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}</nowiki>
{{markup|
|{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}
<nowiki>'''Bold text'''</nowiki>|'''Bold text'''|
|<nowiki>{{code|{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}}}</nowiki>
<nowiki>''Italic text''</nowiki>|''Italic text''}}
|{{code|{{cite book |last=White |first=T. H. |title=The Book of Merlyn |year=1977}}}}
}}


==See also==
==See also==
* {{tl|Markup HTML Rendered}} for three-column Wikitext, HTML, and Rendered output
* {{tl|Markup2}} for bulleted and indented markup.
* {{tl|Markupv}} for the vertical presentation (above/below) of markup/code and its output.
* {{tl|Automarkup}} does not require to write the code samples twice.


<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
== TemplateData ==
<!-- Categories and interwikis go here: -->
{{TemplateData header}}
[[Category:Template test cases| Testcases side by side]]
<templatedata>
{
"description": " ",
"paramOrder": [
"margin-left",
"width",
"style",
"noheaders",
"title",
"tag",
"colheaderstyle",
"col1headerstyle",
"col1",
"col2headerstyle",
"col2",
"col1style",
"col2style",
"codestyle",
"outputstyle",
"1",
"2",
"3",
"4",
"39",
"40"
],
"params": {
"1": {
"description": "row 1, first column (markup/code)'s content.",
"type": "string"
},
"2": {
"description": "row 1, second column (output)'s content.",
"type": "string"
},
"3": {
"description": "row 2, first column's content (etc).",
"type": "string"
},
"4": {
"description": "row 2, second column's content (etc).",
"type": "string"
},
"39": {
"description": "First column's content in last possible row.",
"type": "string"
},
"40": {
"description": "Second column's content in last possible row.",
"type": "string"
},
"width": {
"description": "To set the table's overall width.",
"type": "string",
"default": "auto"
},
"margin-left": {
"description": "To set a margin on the table's lefthand side.",
"type": "string",
"default": "0"
},
"style": {
"description": "For CSS styles amending the table's overall appearance.",
"type": "string"
},
"title": {
"description": "Title above table.",
"type": "string",
"default": "none"
},
"tag": {
"description": "Tag to use for markup. The default is pre and syntaxhighlight only works with single rows of text.",
"type": "string",
"default": "pre",
"suggestedvalues": ["pre","syntaxhighlight"]
},
"noheaders": {
"description": "Set (as e.g. noheaders=on) to suppress the columns' headings and table's title.",
"type": "string"
},
"col1": {
"description": "First column (markup/code)'s heading.",
"type": "string",
"default": "\"Markup\""
},
"col2": {
"description": "Second column (output)'s heading.",
"type": "string",
"default": "\"Renders as\""
},
"codestyle": {
"description": "Use CSS style code to change the appearance of content (text) in the Markup column.",
"type": "string",
"aliases": [
"markupstyle"
],
"label": "Markup text style",
"example": "white-space: nowrap;"
},
"outputstyle": {
"description": "Use CSS style code to change the appearance of content (text) in the Renders-as column.",
"type": "string",
"label": "Output text style",
"example": "white-space: nowrap;"
},
"col1headerstyle": {
"description": "For CSS styling to amend the appearance of the first column's heading. Overrides (but does not replace) colheaderstyle.",
"type": "string"
},
"col2headerstyle": {
"description": "For CSS styling to amend the appearance of the second column's heading. Overrides (but does not replace) colheaderstyle.",
"type": "string"
},
"colheaderstyle": {
"description": "For CSS styling to amend the appearance of each column's heading.",
"type": "string"
},
"col1style": {
"label": "Column 1 Style",
"description": "For CSS styles to amend the appearance of the markup column (e.g. width of the column).",
"example": "width:20em;",
"type": "string",
"default": "none"
},
"col2style": {
"label": "Column 2 Style",
"description": "For CSS styles to amend the appearance of the output column (e.g. the background colour).",
"example": "background-color:#fff;",
"type": "string",
"default": "none"
        }
}
}
</templatedata>
<includeonly>{{Sandbox other|
| <!-- Categories below this line, please: -->
[[Category:Documentation assistance templates]]
[[Category:Template namespace templates]]
[[Category:Template namespace templates]]
[[Category:Documentation assistance templates]]
[[Category:Template test cases| ]]
 
}}</includeonly>
}}</includeonly>