Help:Formatting: Difference between revisions

Jump to navigation Jump to search
→‎Differentiating good and bad code snippets: Examples of bad code can be highlighted using the css attribute style="background: #ffdddd;"
m (→‎Headings and subheadings: Clarification and spelling)
(→‎Differentiating good and bad code snippets: Examples of bad code can be highlighted using the css attribute style="background: #ffdddd;")
Line 623: Line 623:
args.setStringValue("filename", "output.profile");
args.setStringValue("filename", "output.profile");
globals->get_commands()->execute("profiler-start", &args);
globals->get_commands()->execute("profiler-start", &args);
</syntaxhighlight>
|}
==== Differentiating a bad and a good code snippet ====
One can make examples of bad code, for example with common coding errors or bad coding practices, stand out by adding the cascading style sheets (CSS) attribute <code>style="background: #ffdddd;"</code> which will give the background color a pink tint instead of the default gray <code>#dddddd</code>.
When illustrating comparisons between a good and a bad way of doing something the good example can be given a green tint with <code>#ddffdd</code>.  ''Only use the green tint when comparing against a snippet of bad code.''
{| class="wikitable" width="100%"
! Description
! width="30%" | What you type
! width="30%" | What you get
|-
| Highlighting bad coding practices or common errors
|
<pre style="white-space: pre-wrap;">A common pitfall is forgetting a slash in a closing tag:
<?xml version="1.0" encoding="UTF-8"?>
<syntaxhighlight lang="xml" style="background: #ffdddd;">
<PropertyList>
  <!-- Contents -->
<PropertyList>  <!-- Note missing slash -->
</syntaxhighlight>
</pre>
|
A common pitfall is forgetting a slash in a closing tag:
<syntaxhighlight lang="xml" style="background: #ffdddd;">
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
  <!-- Contents -->
<PropertyList>  <!-- Note missing slash -->
</syntaxhighlight>
|-
| Good and bad examples next to each other
|
<pre style="white-space: pre-wrap;">Bad [[PropertyList XML File|property-list XML file]] (missing an XML header).
<syntaxhighlight lang="xml" style="background: #ffdddd;">
<PropertyList>
  <!-- Contents -->
</PropertyList>
</syntaxhighlight>
Do it like this instead:
<syntaxhighlight lang="xml" style="background: #ddffdd;">
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
  <!-- Contents -->
</PropertyList>
</syntaxhighlight>
</pre>
|
Bad [[PropertyList XML File|property-list XML file]] (without an XML header)
<syntaxhighlight lang="xml" style="background: #ffdddd;">
<PropertyList>
  <!-- Contents -->
</PropertyList>
</syntaxhighlight>
Do it like this instead:
<syntaxhighlight lang="xml" style="background: #ddffdd;">
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
  <!-- Contents -->
</PropertyList>
</syntaxhighlight>
</syntaxhighlight>
|}
|}

Navigation menu