其他代码用法 topics-code1

5. 显示代码

Note

我们可以在配置文件指定highlight_langeuage=”c,python”

5.1. 使用codeblock

#include<stdio.h>
int main()
{
    printf("%s\n","aaaa");
    return 0;
}

5.2. 显示行号

1#include<stdio.h>
2int main()
3{
4    printf("%s\n","aaaa");
5    return 0;
6}

5.3. 突出特定行

def some_function():
    interesting = False
    print 'This line is highlighted.'
    print 'This one is not...'
    print '...but this one is.'

5.4. 引用一个文件

 1import sys
 2    print("test")
 3
 4def test2():
 5    print("test")
 6
 7def test3():
 8    print("test")
 9
10def test4():
11    print("test")

5.5. diff2个文件

--- /home/docs/checkouts/readthedocs.org/user_builds/my-study-restructuredtext/checkouts/latest/source/Sphinx标记结构/test2.py
+++ /home/docs/checkouts/readthedocs.org/user_builds/my-study-restructuredtext/checkouts/latest/source/Sphinx标记结构/test.py
@@ -1,12 +1,13 @@
 import sys
-import os
 
 def test1():
-    print("test3")
+    print("test")
 
 def test2():
-    print("test2")
+    print("test")
 
+def test3():
+    print("test")
 
 def test4():
-    print("test4")+    print("test")

5.6. 带一个copy代码的button

不多BB上链接 让代码可以用户快速copy