Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
些在線圖文編輯器不支持直接插入代碼塊,但可以直接粘貼 HTML 格式的高亮代碼塊。
花了一點(diǎn)時(shí)間研究了一下各家的編輯器,規(guī)則卻各不相同。有的要求代碼塊被包含于 <code> ... </code> 或者 <pre> <code> ... </code> </pre> , 有些要求 class 屬性里包含 "code" 關(guān)鍵詞,或者要求代碼塊里必須包含至少一個(gè) <br> 。如果不符合這些要求,不是變成普通文本,就是丟失換行縮進(jìn),或者丟失顏色樣式。
所以,這就難了。先得找個(gè)支持代碼高亮的編輯器,仔細(xì)地選擇并復(fù)制代碼塊,復(fù)制完還得編輯剪貼板里的 HTML 。這就不如干脆寫個(gè)轉(zhuǎn)換工具了。
因?yàn)闉g覽器操作系統(tǒng)剪貼板可能不太方便,下面用 aardio 寫一個(gè)工具軟件。
先看軟件成品演示:
軟件用法:
1、輸入編程語(yǔ)言名稱(支持自動(dòng)完成)。
2、然后在輸入框中粘貼要轉(zhuǎn)換的編程代碼。
3、點(diǎn)擊「復(fù)制高亮代碼塊」按鈕。
然后我們就可以打開在線圖文編輯器直接粘貼生成的高亮代碼塊了。
下面是這個(gè)軟件的 aardio 源代碼:
import win.ui;
/*DSG{{*/
var winform = win.form(text="HTML 代碼塊生成工具 - 本工具使用 aardio 語(yǔ)言編寫";right=1055;bottom=674;bgcolor=16777215)
winform.add(
button={cls="button";text="復(fù)制高亮代碼塊";left=633;top=609;right=1000;bottom=665;bgcolor=16777215;color=14120960;db=1;dr=1;font=LOGFONT(h=-14);note="可在網(wǎng)頁(yè)編輯器直接粘貼";z=4};
cmbLangs={cls="combobox";left=262;top=625;right=446;bottom=651;db=1;dl=1;edge=1;items={"javascript"};mode="dropdown";z=2};
editCode={cls="edit";left=1;top=4;right=1052;bottom=599;db=1;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=5};
static={cls="static";text="請(qǐng)選擇語(yǔ)言:";left=70;top=629;right=248;bottom=649;align="right";db=1;dl=1;transparent=1;z=3};
webCtrl={cls="custom";text="自定義控件";left=8;top=10;right=1048;bottom=604;db=1;dl=1;dr=1;dt=1;hide=1;z=1}
)
/*}}*/
import web.view;
var wb = web.view(winform.webCtrl);
import win.clip.html;
wb.export({
onHighlight = function(html,background,foreground){
html = `<pre class="code" style="overflow-x:auto;text-align:left;box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;padding:10px;border-radius:3px;background-color:`+background+`;color:`+foreground+`;white-space:pre;word-break:break-all;display:block;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps: normal;font-family: "Consolas", Consolas, "Liberation Mono", Menlo, Courier, monospace"><code>`
+ html + `</code></pre>`;
html,count = string.replace(html,'\n',"<br>");
if(!count){
html = string.replace(html,`\</code\>\</pre\>$`,`<br></code></pre>`);
}
var cb = win.clip.html();
cb.write(html);
winform.setTimeout(
function(){
winform.editCode.show(true);
winform.webCtrl.show(false);
winform.text = "HTML 代碼塊生成工具 - 已復(fù)制高亮代碼塊到剪貼板,可在網(wǎng)頁(yè)直接粘貼";
},1000);
};
setLanguages = function(langs){
winform.languages = langs;
}
})
winform.cmbLangs.onEditChange = function(){
var text = string.lower(winform.cmbLangs.text);
var items = table.filter( winform.languages : {}, lambda(v) string.startWith(v,text) );
winform.cmbLangs.autoComplete(items);
}
winform.cmbLangs.editBox.disableInputMethod();
import web.prism;
import wsock.tcp.asynHttpServer;
var httpServer = wsock.tcp.asynHttpServer();
httpServer.run(web.prism,{
["/index.html"] = /*****
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link href="prism.css" rel="stylesheet" />
</head>
<body>
<pre id="code-pre"><code id="code" class="lang-javascript"></code></pre>
<script src="prism.js"></script>
<script>
function computedColorStyle(element, options = {}) {
Array.prototype.forEach.call(element.children,child => {
computedColorStyle(child, options);
});
const computedStyle = getComputedStyle(element);
element.style["color"] = computedStyle.getPropertyValue("color");
}
highlight = function(code,language){
var html = Prism.highlight(code, Prism.languages[language], language);
var codeEle = document.getElementById("code");
codeEle.innerHTML = html;
computedColorStyle(codeEle);
const computedStyle = getComputedStyle(codeEle);
onHighlight(codeEle.innerHTML
,getComputedStyle(document.getElementById("code-pre")).getPropertyValue("background-color")
,computedStyle.getPropertyValue("color"));
}
setLanguages( Object.keys(Prism.languages) );
</script>
</body>
</html>
*****/
});
wb.go( httpServer.getUrl("/index.html"));
winform.button.oncommand = function(id,event){
winform.text = "HTML 代碼塊生成工具 - 本工具使用 aardio 語(yǔ)言編寫"
winform.editCode.show(false);
winform.webCtrl.show(true);
wb.xcall("highlight",winform.editCode.text,winform.cmbLangs.text);
}
winform.show();
win.loopMessage();
打開 aardio 創(chuàng)建工程,然后復(fù)制粘貼上面的代碼到 main.aardio 里面就可以直接運(yùn)行,或生成獨(dú)立 EXE 文件:
這個(gè)軟件的原理:
1、首先通過(guò) WebView2 調(diào)用 Prism.js 高亮代碼。為了可以內(nèi)存加載 Prism.js ( 支持生成獨(dú)立 EXE ),我寫了一個(gè) aardio 擴(kuò)展庫(kù) web.prism 。關(guān)于 WebView2 請(qǐng)參考:放棄 Electron,擁抱 WebView2!JavaScript 快速開發(fā)獨(dú)立 EXE 程序
2、因?yàn)?Prism.js 生成的 HTML 代碼塊都是使用 class 屬性指定樣式,所以我們需要調(diào)用 getComputedStyle 獲取最終渲染的字體顏色屬性。
3、最后在 JavaScript 里調(diào)用 aardio 函數(shù)處理生成的 HTML 代碼塊,aardio 的任務(wù)是將 HTML 修改為更合適直接粘貼的格式,并盡可能地處理各圖文編輯器的兼容問(wèn)題。然后調(diào)用 win.clip.html 將處理好的 HTML 復(fù)制到系統(tǒng)剪貼板:
import win.clip.html;
var cb = win.clip.html();
cb.write(html);
然后只要愉快地粘貼代碼塊就可以。
如果是 aardio 代碼不需要用這個(gè)工具,在 aardio 編輯器里右鍵直接點(diǎn)『 復(fù)制全部到 HTML 代碼塊 』就可以了:
RL也被稱為網(wǎng)址。
URL 可以由單詞組成,比如 "w3school.com.cn",或者是因特網(wǎng)協(xié)議(IP)地址:192.168.1.253。
大多數(shù)人在網(wǎng)上沖浪時(shí),會(huì)鍵入網(wǎng)址的域名,因?yàn)槊Q比數(shù)字容易記憶。
URL(Uniform Resource Locator)
當(dāng)您點(diǎn)擊 HTML 頁(yè)面中的某個(gè)鏈接時(shí),對(duì)應(yīng)的<a>標(biāo)簽指向萬(wàn)維網(wǎng)上的一個(gè)地址。
統(tǒng)一資源定位器(URL)用于定位萬(wàn)維網(wǎng)上的文檔(或其他數(shù)據(jù))。
網(wǎng)址,比如 http://www.w3school.com.cn/html/index.asp,遵守以下的語(yǔ)法規(guī)則:
scheme://host.domain:port/path/filename
解釋:
scheme 定義因特網(wǎng)服務(wù)的類型。最常見的類型是 http
host 定義域主機(jī)(http 的默認(rèn)主機(jī)是 www)
domain 定義因特網(wǎng)域名,比如 w3school.com.cn
:port 定義主機(jī)上的端口號(hào)(http 的默認(rèn)端口號(hào)是 80)
path 定義服務(wù)器上的路徑(如果省略,則文檔必須位于網(wǎng)站的根目錄中)。
filename 定義文檔/資源的名稱
編者注:URL 的英文全稱是 Uniform Resource Locator,中文也譯為"統(tǒng)一資源定位符"。
URL Schemes
以下是其中一些最流行的 scheme:
Scheme 訪問(wèn) 用于...
http 超文本傳輸協(xié)議 以 http:// 開頭的普通網(wǎng)頁(yè)。不加密。
https 安全超文本傳輸協(xié)議 安全網(wǎng)頁(yè)。加密所有信息交換。
ftp 文件傳輸協(xié)議 用于將文件下載或上傳至網(wǎng)站。
file 您計(jì)算機(jī)上的文件。
URL編碼
URL只能使用ASCII字符集來(lái)通過(guò)因特網(wǎng)進(jìn)行發(fā)送。
由于URL常常會(huì)包含ASCII集合之外的字符,URL 必須轉(zhuǎn)換為有效的ASCII格式。
URL編碼使用"%"其后跟隨兩位的十六進(jìn)制數(shù)來(lái)替換非ASCII字符。
URL不能包含空格。URL編碼通常使用+來(lái)替換空格。
URL編碼表參考
http://www.w3school.com.cn/tags/html_ref_urlencode.html
下是一些常用的HTML網(wǎng)頁(yè)源代碼示例,這些示例可用作HTML文檔的基礎(chǔ):
1、創(chuàng)建一個(gè)簡(jiǎn)單的HTML文檔結(jié)構(gòu):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"content="width=device-width,initial-scale=1.0">
<title>My Web Page</title>
</head>
<body>
<h1>Hello,World!</h1>
<p>This is a simple HTML webpage.</p>
</body>
</html>
2、插入圖片:
<img src="image.jpg"alt="Description of the image">
3、創(chuàng)建超鏈接:
<a href="https://www.example.com">Visit Example.com</a>
4、創(chuàng)建無(wú)序列表:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
5、創(chuàng)建有序列表:
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
6、創(chuàng)建表格:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1,Cell 1</td>
<td>Row 1,Cell 2</td>
</tr>
<tr>
<td>Row 2,Cell 1</td>
<td>Row 2,Cell 2</td>
</tr>
</table>
7、插入段落:
<p>This is a paragraph of text.</p>
8、插入換行符:
<p>This is some text.<br>This is on a new line.</p>
9、創(chuàng)建一個(gè)文本輸入框:
<input type="text"name="username"placeholder="Enter your username">
10、插入按鈕:
<button type="button">Click me</button>
這些示例代碼只是HTML的基礎(chǔ),HTML具有更豐富的功能和標(biāo)記選項(xiàng),可以根據(jù)需要進(jìn)行擴(kuò)展和定制。請(qǐng)根據(jù)您的具體需求,使用這些示例作為起點(diǎn),構(gòu)建您自己的網(wǎng)頁(yè)。
【名揚(yáng)銀河企業(yè)網(wǎng)站系統(tǒng)】
【免費(fèi)】提供企業(yè)【網(wǎng)站源碼】,簡(jiǎn)單易用,無(wú)須擁有代碼基礎(chǔ)。
歡迎留言或私信我們咨詢。
以上內(nèi)容由【名揚(yáng)銀河】企業(yè)網(wǎng)站系統(tǒng)原創(chuàng)發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。