Thursday, March 29, 2012

Posting Source Code - Đăng tải mã nguồn lên wordpress

Chào các bạn, trong quá trình sử dụng wordprees từ ban đâu tôi gặp khó khăn trong việc đư mã nguồn lên giao diện của wordpress vì wordpress sẽ hiểu các ký tự gõ vào là thẻ của ngôn ngữ HTML. và sau khi tìm hiểu tôi tìm được thông tin từ wordpress cho phép đưa mã nguồn lên như bên dưới.
[sourcecode language="css"]
#button {
font-weight: bold;
border: 2px solid #fff;}
[/sourcecode]
Vậy làm sao để thực hiện được ?
Chỉ đơn giản đặt mã nguồn vào giữa thẻ sourcecode và chỉ định language="ngô ngữ sử dụng". Ví dụ với đoạn mã nguồn trên khi đăng thông tin ta viết như sau:


Với thể SOURCECODE hỗ trợ các ngô ngữ sau:
•actionscript3,bash,clojure,coldfusion,cpp,csharp,css,delphi,erlang,fsharp,diff,groovy,html,javascript,java,javafx,matlab (keywords only),objc,perl,php,text,powershell,python,r,ruby,scala,sql,vb,xml

Ngoài ra chúng ta còn có thể cấu hình ở các thuộc tính của thẻ sourcecode để thực hiện một số công việc hữu ích.
Ví dụ: autolinks (true/false) — Cho phép tự kiểm tra và chuyển đổi địa chỉ liên kết.
Bạn tham khảo thêm tại
[sourcecode language="html" autolinks="true"]
http://en.support.wordpress.com/code/posting-source-code/
[/sourcecode]

Ví dụ code html và highlight dòng 12

[sourcecode language="html" autolinks="true" highlight="12"]
<!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>
[/sourcecode]

No comments:

Post a Comment

Translate