一、實(shí)踐發(fā)現(xiàn)了bug和不足
?
今天用了公文一鍵排版系統(tǒng)對(duì)幾個(gè)PDF文件格式的材料進(jìn)行文字識(shí)別后再重新排版,處理效果還是相當(dāng)不錯(cuò)的,節(jié)約了不少的時(shí)間。
但是也發(fā)現(xiàn)了三個(gè)需要改進(jìn)的地方:
(一)發(fā)現(xiàn)了兩個(gè)bug:
1.二級(jí)標(biāo)題排版格式中css的text-indent屬性的單位忘記從em改為pt,結(jié)果排版時(shí)二級(jí)標(biāo)題顯示幾乎變成居中了。
2.存儲(chǔ)溫馨提示信息的變量a初始值設(shè)為null,結(jié)果在輸出a時(shí)null也被當(dāng)成字符串符顯示了,應(yīng)設(shè)為為""。
這兩個(gè)均已debug了。
(二)文字識(shí)別經(jīng)常將標(biāo)點(diǎn)符號(hào)識(shí)別為半角的符號(hào),排版出來(lái)不夠美觀。
(三)文字識(shí)別會(huì)添加一些空格,排版出來(lái)不夠美觀。
二、明確了改進(jìn)方向
針對(duì)上面發(fā)現(xiàn)的不足,決定給一鍵排版系統(tǒng)增加兩項(xiàng)功能:
-
半角標(biāo)點(diǎn)符號(hào)和全角標(biāo)點(diǎn)符號(hào)相互轉(zhuǎn)換的功能按鈕。
-
刪除空格的的功能按鈕
三、實(shí)現(xiàn)半角標(biāo)點(diǎn)符號(hào)和全角標(biāo)點(diǎn)符號(hào)相互轉(zhuǎn)換
先實(shí)現(xiàn)上面列的第1項(xiàng)功能。
在網(wǎng)上搜索了一下,已經(jīng)有網(wǎng)友做過(guò)分析,并分享了實(shí)現(xiàn)這個(gè)功能的代碼。
擁有全角與半角之分的ASCII字符范圍:0x20~0x7E。
除了空格(0x20)外,其他的字符中,全角與半角均相差:0xFFE0。全角空格的代碼為:0x03000 。
因此,在全角與半角的字符轉(zhuǎn)換中,除空格需要特殊處理外:
全角 = 半角 + 0xFEE0
半角 = 全角? - 0xFFE0
半角字符的代碼范圍:
在網(wǎng)友們分享的代碼基礎(chǔ)上做了一點(diǎn)改進(jìn)。
<!DOCTYPE HTML>
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="PurpleEndurer">
<title>公文一鍵排版系統(tǒng)</title>
</head>
<body>
<fieldset style="width: 1100px;">
<legend>實(shí)時(shí)編輯區(qū)</legend>
<iframe id="editor" width="1200px" height="400px" style="border: solid 1px;"></iframe>
</fieldset>
<p>
全角和半角字符轉(zhuǎn)換:
<input type="button" id="btnHalf2Full" value="半角轉(zhuǎn)全角" onclick="edRichBody.innerText=half2Full(edRichBody.innerText)" style="background:blue; color:white; border-radius: 25px;" />
<input type="button" id="btnFull2Half" value="全角轉(zhuǎn)半角" onclick="edRichBody.innerText=full2Half(edRichBody.innerText)" style="background:green; color:white; border-radius: 25px;" />
</p>
<script>
const edRich = document.getElementById("editor");
var edRichDoc;
var edRichBody;
if (typeof(edRich) != "undefined")
{
edRichDoc = edRich.contentWindow.document;
edRichDoc.designMode = "on";
edRichDoc.contentEditable = true;
edRichBody = edRichDoc.body;
edRichBody.innerHTML = '<p><a >http://blog.csdn.net/purpleendurer</a></p><p></p><p style="font-family:方正小標(biāo)宋簡(jiǎn)體;font-size:22pt; text-align:center; line-height:28pt;"><p align="center" style="text-align:center;text-indent:24.0pt;line-height:28.0pt"><span lang="EN-US" style="font-size:22.0pt;font-family:方正小標(biāo)宋簡(jiǎn)體;mso-hansi-font-family:黑體;color:black">SQL</span><span style="font-size:22.0pt;font-family:方正小標(biāo)宋簡(jiǎn)體;mso-hansi-font-family:黑體;color:black">注入基礎(chǔ)<span lang="EN-US"><o:p></o:p></span></span></p><p style="text-indent:2em;">河池市××局、 市×× 局: </p><p style="text-indent:24.0pt;line-height:28.0pt;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px"><span style="font-size:16.0pt;font-family:黑體;color:black">一、<span lang="EN-US">SQL</span>注入分類(lèi)<span lang="EN-US"><o:p></o:p></span></span></p><p style="text-indent:24.0pt;line-height:28.0pt;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px"><b><span style="font-size:16.0pt;font-family:楷體_GB2312;color:black">(一)什么是<span lang="EN-US">SQL</span>注入<span lang="EN-US">?<o:p></o:p></span></span></b></p><p style="text-indent:24.0pt;line-height:28.0pt;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px"><span lang="EN-US" style="font-size:16.0pt;font-family:仿宋_GB2312;color:black">SLQ</span><span style="font-size:16.0pt;font-family:仿宋_GB2312;color:black">注入<span lang="EN-US">(</span>英文<span lang="EN-US">: Sqlinject)</span>:當(dāng)<span lang="EN-US">web</span>應(yīng)用向后臺(tái)數(shù)據(jù)庫(kù)傳遞<span lang="EN-US">SQL</span>語(yǔ)句進(jìn)行數(shù)據(jù)庫(kù)操作時(shí),如果對(duì)用戶(hù)輸入的參數(shù)沒(méi)有經(jīng)過(guò)嚴(yán)格的過(guò)濾,那么用戶(hù)可以構(gòu)造特殊的<span lang="EN-US">sq1</span>語(yǔ)句,從而帶入到數(shù)據(jù)庫(kù)中執(zhí)行,獲取或修改數(shù)據(jù)庫(kù)中的數(shù)據(jù)。<span lang="EN-US"><o:p></o:p></span></span></p><p style="text-indent:24.0pt;line-height:28.0pt;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px"><span style="font-size:16.0pt;color:black"> 1.加強(qiáng)技術(shù)學(xué)習(xí)。一要<span lang="EN-US"><o:p></o:p></span></span></p><p style="text-indent:24.0pt;line-height:28.0pt;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px"><span style="font-size:16.0pt;color:black"> 2.強(qiáng)化安全保障。一要。<span lang="EN-US"><o:p></o:p></span></span></p><p>附件:河池市××關(guān)于××××××××××××××××××××××××××××××××××××××××××××××××××的通知</p><p>附件:河池市××關(guān)于××的通知</p><p>附件:河池市××關(guān)于××的通知。</p><p>附件:1.河池市××關(guān)于××的通 知</p><p>附件:1.河池市××關(guān)于××××的通 知 </p><p>2.河池市××關(guān)于×× ××的通 知 </p><p>3.河池市××關(guān)于×× ××的通 知</p><p>測(cè)試1</p><p style="text-indent:24.0pt;line-height:28.0pt;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px">河池市××××局</p><p>2023年7月22日</p><p>測(cè)試2</p><p>廣西壯族自治區(qū)河池市××××局</p><p>2023年7月22日</p><p>測(cè)試3</p><p>河池市××局</p><p>2023年7月22日</p><p>測(cè)試4</p><p>河池市×局</p><p>2023年7月22日</p><p>附件</p><p>附件標(biāo)題</p><p>附件:</p><p>附件標(biāo)題</p><p>附 件</p><p>附件標(biāo)題</p>';
}
else
{
window.alert("undefined");
}
//功能:半角字符轉(zhuǎn)全角字符
//輸入:p=待轉(zhuǎn)換的字符串
//輸出:轉(zhuǎn)換后的字符串
//更新:20230803創(chuàng)建
function half2Full(p)
{
var r = ""; //result
for (var i = 0; i < p.length; i++)
{
var c = p.charCodeAt(i);
if (c >= 0x0021 && c <= 0x007E)
{
if (c==0x0020) //處理空格
{
c = 0x03000;
}
else
{
//全角與半角相差(除空格外):65248(十進(jìn)制)
c += 65248;
}
}//if
r += String.fromCharCode(c);
}//for
return r;
}//half2Full(p)
//功能:全角字符轉(zhuǎn)半角字符
//輸入:p=待轉(zhuǎn)換的字符串
//輸出:轉(zhuǎn)換后的字符串
//更新:20230803創(chuàng)建
function full2Half(p)
{
var r = ""; //result
for(var i = 0; i < p.length; i++)
{
var c = p.charCodeAt(i);
if (c >= 0xFF01 && c <= 0xFF5E)
{
if (c==0x03000) //處理空格
{
c = 0x0020;
}
else
{
//全角與半角相差(除空格外):65248(十進(jìn)制)
c -= 65248;
}//if
}
r += String.fromCharCode(c);
}//for
//alert(r);
return r;
}//full2Half(p)
</script>
</body>
</html>
效果如下圖:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-635380.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-635380.html
下一步我們將增加一些轉(zhuǎn)換選項(xiàng),比如英文字母、阿拉伯?dāng)?shù)字、標(biāo)點(diǎn)符號(hào)、空格。
到了這里,關(guān)于用html+javascript打造公文一鍵排版系統(tǒng)13:增加半角字符和全角字符的相互轉(zhuǎn)換功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!