PROJET AUTOBLOG


benimarine

Site original : benimarine

⇐ retour index

Posting Source Code

samedi 8 juin 2013 à 17:35

While WordPress.com doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

 

1
2
3
4
#button {
    font-weight: bold;
    border: 2px solid #fff;
}

 

To accomplish the above, just wrap your code in these tags:

 

 your code here
 

 

The language (or lang) parameter controls how the code is syntax highlighted. The following languages are supported:

 

 

If the language parameter is not set, it will default to “text” (no syntax highlighting).

 

Code in between the source code tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

 

Configuration Parameters

 

The shortcodes also accept a variety of configuration parameters that you may use to customize the output. All are completely optional.

 

 

Here’s some examples of the above parameters in action:

 

8
9
10
11
This line is not highlighted.
This line is highlighted.
This line is highlighted.
This line is not highlighted.

 

 

 

0001
<strong>This</strong> is a short snippit of <code>code</code> with padlinenumbers set to 4.

 

And here’s a larger code block to see it all in action. It is set to the PHP language with “htmlscript” enabled and line number 12 highlighted.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>WordPress.com Code Example</title>
</head>
<body>
    <h1>WordPress.com Code Example</h1>
    <p><?php echo 'Hello World!'; ?></p>
    <p>This line is highlighted.</p>
    <p>This line is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long.</p>
    <div class="foobar">
        This    is  an
        example of  smart
        tabs.
    </div>
    <p><a href="http://wordpress.com/">WordPress.com</a></p>
</body>
</html>