Code blocks are generally used to
represent code of programming (java, c, Python etc.,), markup languages (HTML,
XML etc.,). You can add a code block using spaces (or) tabs. Markdown wraps the
code blocks inside both <pre>, <code> tags.
How
to produce a code block in markdown code?
Indent every line of the block by at
least 4 spaces or 1 tab.
hello_world.md
# Java Hello World program public class HelloWorld{ public static void main(String args[]){ System.out.println("Hello World"); } }
<?xml version='1.0' encoding='utf-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h1 id="java-hello-world-program">Java Hello World program</h1> <pre> <code>public class HelloWorld{ public static void main(String args[]){ System.out.println("Hello World"); } }</code> </pre> </body> </html>
How to indicate span of code.
Use backtick
quotes (`) to indicate span of code.
hello_world.md
> `System.out.println()` is used to print statement to the console. > `Integer.parseInt(String str)` converts a string to integer.
Following is
the preview for above markdown file.
How to put a code block in list item?
To put a
code block within a list item, the code block needs to be indented twice — 8
spaces or two tabs.
hello_world.md
# 1. Java class HelloWorld{ public static void main(String args[]){ System.out.println("Hello Markdown") } } # 2. Python print ('hello world') # 3. C++ #include<iostream> using namespace std; int main(){ cout << "Hello World!"; return 0; }
Following is
the preview for above file.
Note
Within a
code block, ampersands (&) and angle brackets (< and >) are
automatically converted into HTML entities
No comments:
Post a Comment