diff options
author | 2025-01-07 12:36:05 +0800 | |
---|---|---|
committer | 2025-01-07 12:36:05 +0800 | |
commit | 4d88ef666eee1b6f191f6e85b00acf8d5a2d1899 (patch) | |
tree | 68391846bae84f9546b0d089c012afc336a6e6bd /code/MyCodes.html | |
parent | 11e64c5804b696f170b9d5d881befbabc4a4e85c (diff) | |
download | myweb-new_highlightjs.tar.gz myweb-new_highlightjs.zip |
highlight don't use auto-detect but given languagenew_highlightjs
In this commit, lot's of things is changed. Hope they all runs
currectly.
Now highlight.js is supporting more and more proguam languages, but
the auto detection always go wrong, even for common languages like c,
bash, python, makefile.
Use Given Language
------------------
As you know, I always write markdown and convert to html by pandoc. In
the old, "```cpp" in markdown will be deleted first to keep the embeded
code clean and not highlighted, then I can use highlight.js. But this
causes that html document doesn't know the language.
This time, md2html.sh is changed: pandoc use "--no-highlight"
argument to keep code clean, and it will output like this:
```html
<pre class="cpp"><code>...</code></pre>
```
Although there may be other tags between `<code></code>`, it's clear
that `<pre class="xxx"><code>` is nested tightly, except some space
characters or \n.
Then, sed deal with the whole doc(not line by line), replace `<pre
class="xxx"><code>` with `<pre><code class="language-xxx">`. That's it!
Math Formula
------------
Math formular is also a problem during convertion by pandoc. In the old
it's dealed menually. Now pandoc use "--mathjax=none", then formula is
no longer showed by pandoc, but only `<span class="math xxx">\( formula \)</span>`.
And the math tool I used will deal with it.
Mermaid picture
----------------
pandoc doesn't support convert mermaid in markdown to html picture.
Let's have a warning!
Diffstat (limited to 'code/MyCodes.html')
-rw-r--r-- | code/MyCodes.html | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/code/MyCodes.html b/code/MyCodes.html new file mode 100644 index 0000000..0fc370f --- /dev/null +++ b/code/MyCodes.html | |||
@@ -0,0 +1,237 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> | ||
3 | |||
4 | <head> | ||
5 | <meta charset="utf-8" /> | ||
6 | <meta name="generator" content="pandoc" /> | ||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | ||
8 | <title>我的实用代码</title> | ||
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | ||
11 | </head> | ||
12 | |||
13 | <body> | ||
14 | <div class="pandoc"> | ||
15 | <div class="main"> | ||
16 | <header id="title-block-header"> | ||
17 | <p class="title">我的实用代码</p> | ||
18 | </header> | ||
19 | <p>这里是英(C)语(yǔ)科(yán)听力部分。该部分有第一、第二两节。</p> | ||
20 | <p>请注意,回答听力部分时,请先将答案写在试卷上,听力部分结束前,你将有两分钟的时间将试卷上的答案转移到答题卡上。</p> | ||
21 | <p>听力考试,现在开始!</p> | ||
22 | <h1 id="光标隐藏函数">光标隐藏函数</h1> | ||
23 | <pre><code class="language-c">void HideCursor(void) | ||
24 | { | ||
25 | CONSOLE_CURSOR_INFO cursor_info = {1, 0}; | ||
26 | SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); | ||
27 | }</code></pre> | ||
28 | <h1 id="show_bytes">show_bytes</h1> | ||
29 | <pre><code class="language-cpp">#include <bits/stdc++.h> | ||
30 | using namespace std; | ||
31 | typedef unsigned char* bite_pointer; | ||
32 | typedef int T;//数据类型为int,可更改 | ||
33 | void show_bites(bite_pointer p,size_t len) | ||
34 | { | ||
35 | size_t i; | ||
36 | cout<<"In machine order:"; | ||
37 | for(i=0;i<len;i++) | ||
38 | { | ||
39 | printf("%.2x ",p[i]); | ||
40 | } | ||
41 | printf("\n"); | ||
42 | cout<<"In person order: "; | ||
43 | for(i=len-1;i>0;i--) | ||
44 | { | ||
45 | printf("%.2x ",p[i]); | ||
46 | } | ||
47 | printf("%.2x ",p[i]); | ||
48 | printf("\n"); | ||
49 | } | ||
50 | int main() | ||
51 | { | ||
52 | int a; | ||
53 | cout<<"Please input the data in type \"int\":"; | ||
54 | cin>>a; | ||
55 | show_bites((bite_pointer)&a,sizeof(T)); | ||
56 | return 0; | ||
57 | }</code></pre> | ||
58 | <h1 id="界面设计和上色">界面设计和上色</h1> | ||
59 | <p>注意:<strong>本内容请勿改动任何参数!</strong></p> | ||
60 | <pre><code class="language-c">#include <windows.h> | ||
61 | #include <conio.h> | ||
62 | #include <time.h> | ||
63 | |||
64 | int wide=60,high=30;//宏常量定义,数据可变 | ||
65 | HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//写在主函数或调用函数内部,用于定义hout并进行初始化 | ||
66 | system("mode con cols=80 lines=40 ");//运行框大小限制 | ||
67 | |||
68 | void gotoxy(HANDLE hout,int x,int y) | ||
69 | { | ||
70 | HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
71 | COORD pos; | ||
72 | pos.X = x; | ||
73 | pos.Y = y; | ||
74 | SetConsoleCursorPosition(hout,pos); | ||
75 | } | ||
76 | int color(int c)//设置颜色 | ||
77 | { | ||
78 | SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c); | ||
79 | return 0; | ||
80 | }//颜色有若干种 | ||
81 | //两个调用函数</code></pre> | ||
82 | <p>设置某句子的位置用<code>gotoxy(hout,wide*k,high*m)</code>,就是在 wide 的 k 倍,high 的 m 倍的位置。 | ||
83 | 句子上色用<code>color(c)</code>,c 为指定颜色序号。 | ||
84 | 输出后的停顿用<code>void Sleep(int t)</code>函数,在<code><windows.h></code>中,t 代表暂停的毫秒数。 使用时每个句子前都要用 gotoxy | ||
85 | 指定位置,用 color 上色。 合起来如下:</p> | ||
86 | <pre><code class="language-c"> gotoxy(hout,wide/5,high/6); | ||
87 | color(6); | ||
88 | printf("本计算器仅支持5个及以下的矩阵,分别名为A~E(大写)。"); | ||
89 | Sleep(200); | ||
90 | gotoxy(hout,wide/5,high/6+1); | ||
91 | color(6); | ||
92 | printf("每个矩阵阶数不超过5*5。"); | ||
93 | Sleep(200);</code></pre> | ||
94 | <h1 id="关于音乐效果">关于音乐效果</h1> | ||
95 | <pre><code class="language-c">#include<windows.h> | ||
96 | #include<mmsystem.h> | ||
97 | #pragma comment(lib."Winmm.lib") //头文件 | ||
98 | PlaySound(TEXT("音乐名.wav"),NULL,SND_FILENAME | SND_ASYNC | SND_LOOP);//开始播放 | ||
99 | PlaySound(NULL,NULL,SND_FILENAME);//结束播放</code></pre> | ||
100 | <p>注意:音频必须使用<strong>wav</strong>格式,必须放在<strong>跟代码同一个文件夹</strong>,如果不然,音乐名处<strong>应当使用其绝对地址或相对地址</strong>。 | ||
101 | </p> | ||
102 | <h1 id="震动心形设计">震动心形设计</h1> | ||
103 | <pre><code class="language-c">#define I 20 | ||
104 | #define R 340 | ||
105 | |||
106 | int wide=80,high=40;//宏常量定义,数据可变 | ||
107 | system("title xxx");//运行框名称修改,主函数第一句 | ||
108 | system("mode con cols=80 lines=40 ");//运行框大小限制 | ||
109 | |||
110 | void draw_color()//整体颜色震动效果函数 | ||
111 | { | ||
112 | char cl[20]; | ||
113 | srand((unsigned int)time(NULL)); | ||
114 | int k = rand() % strlen(back_color); | ||
115 | strcpy(cl, Color); | ||
116 | cl[len] = back_color[k]; | ||
117 | srand((unsigned int)time(NULL)); | ||
118 | k = rand() % strlen(font_color); | ||
119 | cl[len + 1] = font_color[k]; | ||
120 | cl[len + 2] = '\0'; | ||
121 | system(cl); | ||
122 | }</code></pre> | ||
123 | <p>颜色震动使用方法实例:</p> | ||
124 | <pre><code class="language-c">for(i=0;i<6;i++,lower+=3) | ||
125 | { | ||
126 | puts(data[i+15]); | ||
127 | for(j=0;j<wait;j++) | ||
128 | { | ||
129 | draw_color(); | ||
130 | Sleep(200); | ||
131 | } | ||
132 | Sleep(200); | ||
133 | } | ||
134 | void draw_heart(int wait)//心形设计函数,传入参数为0即可 | ||
135 | { | ||
136 | int i,j,e,a; | ||
137 | for(i=1,a=I;i<I/2;i++,a--) | ||
138 | { | ||
139 | for(j=(int) ( I-sqrt(I*I-(a-i)*(a-i)) );j>0;j--) | ||
140 | { | ||
141 | printf(" "); | ||
142 | } | ||
143 | for(e=1;e<=2*sqrt(I*I-(a-i)*(a-i));e++) | ||
144 | { | ||
145 | printf("\3"); | ||
146 | } | ||
147 | for(j=(int)( 2*( I-sqrt(I*I-(a-i)*(a-i)) ) );j>0;j--) | ||
148 | { | ||
149 | printf(" "); | ||
150 | } | ||
151 | for(e=1;e<=2*sqrt(I*I-(a-i)*(a-i));e++) | ||
152 | { | ||
153 | printf("\3"); | ||
154 | } | ||
155 | printf("\n"); | ||
156 | if(wait&&i%2) | ||
157 | { | ||
158 | draw_color(); | ||
159 | Sleep(80); | ||
160 | } | ||
161 | } | ||
162 | for(i=1;i<80;i++) | ||
163 | { | ||
164 | if(i==20) | ||
165 | { | ||
166 | for(int j=0;j<40;j++) | ||
167 | { | ||
168 | printf("\3"); | ||
169 | } | ||
170 | i+=40; | ||
171 | } | ||
172 | printf("\3"); | ||
173 | } | ||
174 | printf("\n"); | ||
175 | for(i=1;i<=R/2;i++) | ||
176 | { | ||
177 | if(i%2||i%3) | ||
178 | { | ||
179 | continue; | ||
180 | } | ||
181 | for(j=(int) ( R-sqrt(R*R-i*i) );j>0;j--) | ||
182 | { | ||
183 | printf(" "); | ||
184 | } | ||
185 | for(e=1;e<=2*( sqrt(R*R-i*i) - (R-2*I) );e++) | ||
186 | { | ||
187 | printf("\3"); | ||
188 | } | ||
189 | printf("\n"); | ||
190 | if(wait) | ||
191 | { | ||
192 | draw_color(); | ||
193 | Sleep(80); | ||
194 | } | ||
195 | } | ||
196 | }</code></pre> | ||
197 | <h1 id="给代码加行号的代码">给代码加行号的代码</h1> | ||
198 | <pre><code class="language-c">#include<stdio.h> | ||
199 | |||
200 | int main(void) | ||
201 | { | ||
202 | FILE *fpIn; | ||
203 | // 输入文件的指针 | ||
204 | FILE *fpOut; | ||
205 | // 输出文件的指针 | ||
206 | char str[1000]; | ||
207 | // 用来存储从文件中读取出的”一行“字符串信息 | ||
208 | int row = 1; | ||
209 | fpIn = fopen("文件名.cpp", "r"); | ||
210 | /* 以只读和文本格式打开需要的.cpp文件 | ||
211 | *这里的文件名无所谓大小写 | ||
212 | */ | ||
213 | fpOut = fopen("文件名.txt", "w"); | ||
214 | // 以创建方式(也叫写方式)打开文件名.txt文件 | ||
215 | fgets(str, 81, fpIn); | ||
216 | /* 从文件中读取一行信息,保存到str数组中。 | ||
217 | *这里要注意的是这个81, | ||
218 | *一般情况下,编写文本格式文件的人,都习惯遇到行尾就敲回车, | ||
219 | *所以,一般情况下,文本文件一行最多80个字符。 | ||
220 | *如果,一行不够80个字符,这个函数会自动只读到'\n'就结束了。 | ||
221 | */ | ||
222 | while(!feof(fpIn)) | ||
223 | { // 判断上一次fgets()是否正常(即,没有遇到文件尾部) | ||
224 | fprintf(fpOut, "%4d %s", row, str); | ||
225 | // 在读入的每一行信息前,加入0000到9999的行号(应该够用了吧),呵呵呵呵 | ||
226 | row++; // 行号加一 | ||
227 | fgets(str, 81, fpIn); // 读取下一行 | ||
228 | } | ||
229 | fclose(fpIn); // 关闭文件 | ||
230 | fclose(fpOut); | ||
231 | }</code></pre> | ||
232 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | ||
233 | </div> | ||
234 | </div> | ||
235 | </body> | ||
236 | |||
237 | </html> \ No newline at end of file | ||