公文中二級標題的一般以(X)標注(其中X為由"一二三四五六七八九十"中的字符組成的字符串),用楷體字加粗。
首先我們要判斷一段文字是否包含二級標題,最簡單的方法?就是判斷文字中的頭一個字符是否為(或(,如果是就包含二級標題,否則就不包含二級標題。即:
var t = p[0];
if (t=='(' || t=='(' )
{
//alert(t);
return 2;//二級標題
}
但是有些人可能會用㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩來做序號,而且4級標題(x)(其中x為0~9組成的字符串)也是以(或(開頭的。
所以我們寫了一個isIncludeSecondaryTitle()來進行判斷,并修改getTitleLevel()函數(shù),加入二級標題的判斷:
//Is a secondary title serial number with parenthesis是帶小括號的二級標題序號嗎?
function isT2SNwithParenthesis(p)
{
var t = p[0];
if (t == '(')
{
t = p.indexOf(')');
if ((-1 != t) && ((p.substring(1,t)).isCnNum()))
{
return true;
}
}//if
if (t == '(')
{
t= p.indexOf(')');
if ((-1 != t) && (p.substring(1,t).isCnNum()))
{
return true;
}
}//if
return false;//二級標題
}//isSNwithParenthesis(p)
//Is the paragraph with secondary title?二級標題
function isIncludeSecondaryTitle(p)
{
var t = p[0];//t = p.substring(0, 1);
if (-1!= "㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩".indexOf(t))
{
return true;
}
if (isT2SNwithParenthesis(p))
{
return true;//二級標題
}
return false;
}//isIncludeSecondaryTitle(p)
//功能:獲取文字串的標題級別
//輸入:p:文字串
//輸出:1:一級標題,2:二級標題,3:三級標題,0:其它
function getTitleLevel(p)
{
taDbg.value += "\n---getTitleLevel:" + p;
var t = p[0];//t = p.substring(0, 1);
if (t=='(' || t=='(' )
{
//alert(t);
return 2;//二級標題
}
if (isIncludePrimaryTitle(p))//一級標題
{
return 1;
}
//三級標題
/*
return 3;
*/
return 0;
}//getTitleLevel(p)
需要注意的是,這里我們沒有考慮以序號中的小括號一個為中文小括號,另一個為英文小括號的情況,如()【注:左邊為中文小括號,右邊為英文小括號】或()【注:左邊為英文小括號,右邊為中文小括號】。
然后我們修改setParaFmt(),調用?setParaTitle2()來完成二級標題段落的排版。
//功能:設置段落格式set paragraph format
//輸入:p:段落文字
//輸出:設置格式的文本
function setParaFmt(p)
{
switch (getTitleLevel(p))
{
case 1:
t = setParaTitle1(p);//一級標題
break;
case 2:
t = setParaTitle2(p);//二級標題
break;
/*
case 3:
t = setParaTitle3(p);//三級標題
break;
*/
default: //main text正文
t = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em;font-family:' + mtfn + '; font-size:'+ mtfs + 'pt;">' + p;
}//switch
return t;
}
//功能:設置二級標題set paragraph format with secondary title
//輸入:t:文字
//輸出:格式化字符串
function setParaTitle2(t)
{
taDbg.value += "\n---setParaTitle2:" + t;
var r;
if (ptIsALine(t)) //標題是否單獨成行
{
//return '<p style="font-family:' + fn + ';font-size:' + fs +'pt; text-align:' + ta + '; line-height:' + rs + 'pt;">' + s;
r = '<p style="font-family:' + st2fn + ';font-size:' + st2fs +'pt; line-height:' + rs + 'pt; text-indent: '+ sn +'em;' + (st2Strong ? 'font-weight: bold;' : '') + '">' + t;
}
else
{
//標題不單獨成行
var n = t.indexOf('。');
r = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em; font-size:' + st2fs +'pt; font-family:' + mtfn + '"><span style="font-family:' + st2fn + (st2Strong ? ';font-weight: bold;' : '') + '" >' + t.substring(0, n) + '</span>' + t.substring(n);
}
return r;
}//setParaTitle2(t)
在setParaTitle2()中我們調用ptIsALine()來判斷段落是否只含標題。
//功能:標題是否單獨成行 Is paragraph title a single line?
//輸入:t:文字
//輸出:true:是獨立標題行,false:不是獨立標題行
function ptIsALine(t)
{
var r = false;
var n = t.indexOf('。');
if (n==(t.length-1))//句號是否位于段末
{
r = true;//有且只有一個'。'
}
else
{
if (!t.isEndWithPunctuation())//未以標點符號結尾
{
r = true;
}
}
return r;
}
由于ptIsALine()只檢測中文句號,所以在測試中我們會發(fā)現(xiàn)以問號結尾的二級標題沒有被識別出來。
通常表示一個語句結束的標點符號有:。?。俊?,我們都必須都考慮進去。
因此,我們需要修改ptIsALine()代碼,如下:
String.prototype.isEnPunctuation = function()
{
/*
var reg = /[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/;
return (reg.test(c)) ? true : false;
*/
return (/[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/.test(this)) ? true : false;
}
//功能:判斷是否為中文或英文標點符號
String.prototype.isPunctuation = function()
{
//return ((/[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/.test(this)) || (/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/.test(this))) ? true : false;
return (this.isEnPunctuation() || this.isCnPunctuation()) ? true : false;
}
//功能:是否以標點符號結束Is aunctuation at the end of the string
String.prototype.isEndWithPunctuation = function()
{
/*
var c = this.substring(this.length-1);
return c.isPunctuation();
*/
return this.substring(this.length-1).isPunctuation();
}
var sStatementEndPunctuation = '。!?….!?';//語句結束符號
//功能:獲取段落文字中的第一個語句結束符號位置
//輸入:p:字符串
//輸出:第一個語句結束符號位置
function getFirstPunctuationPos(p)
{
//taDbg.value += '\n ---getFirstPunctuationPos(' + p + ')\n';
var r = p.length, n;
for (var i = 0; i < sStatementEndPunctuation.length; i++)
{
n = p.indexOf(sStatementEndPunctuation[i]);
if ( (-1 != n) && (n < r) )
{
r = n;
//taDbg.value += '\n' + sStatementEndPunctuation[i] + ': n=' + n + ' r=' + r;
}
}
return r;
}//getFirstPunctuationPos(p)
//功能:判斷字符串是否只有一句話
//輸入:p:字符串
//輸出:true:是一句話;false:不是一句話
function isAstatement(p)
{
var n = getFirstPunctuationPos(p);
return ((( -1 != n) && (n == p.length-1)) ? true : false);
}
//功能:標題是否單獨成行 Is paragraph title a single line?
//輸入:t:文字
//輸出:true:是獨立標題行,false:不是獨立標題行
function ptIsALine(t)
{
return (!t.isEndWithPunctuation()) ? true : isAstatement(t) ;
} //ptIsALine(t)
如果段落除了二級標題,還有其他內容的話,我們需要把二級標題文字按二級標題格式設置,其他內容按正文格式設置。因為二級標題文字語句的結束標點符號,可能是句號,也可能是問號、感嘆號……,所以我們還要對setParaTitle1()和setParaTitle2()作相應的修改:
//功能:設置一級標題set paragraph format with primay title
//輸入:t:文字
//輸出:格式化字符串
function setParaTitle1(t)
{
var r;
if (ptIsALine(t)) //標題是否單獨成行
{
//return '<p style="font-family:' + fn + ';font-size:' + fs +'pt; text-align:' + ta + '; line-height:' + rs + 'pt;">' + s;
r = '<p style="font-family:' + pt1fn + ';font-size:' + pt1fs +'pt; line-height:' + rs + 'pt; text-indent: '+ sn +'em;">' + t;
}
else
{
//標題不單獨成行
var n = getFirstPunctuationPos(t);//t.indexOf('。');
r = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em; font-family:' + mtfn + '"><span style="font-family:' + pt1fn + ';font-size:' + pt1fs +'pt;" >' + t.substring(0, n) + '</span>' + t.substring(n);
}
taDbg.value += "\n---setParaTitle1:" + r;
return r;
} //setParaTitle1(t)
//功能:設置二級標題set paragraph format with secondary title
//輸入:t:文字
//輸出:格式化字符串
function setParaTitle2(t)
{
taDbg.value += "\n---setParaTitle2:" + t;
var r;
if (ptIsALine(t)) //標題是否單獨成行
{
//return '<p style="font-family:' + fn + ';font-size:' + fs +'pt; text-align:' + ta + '; line-height:' + rs + 'pt;">' + s;
r = '<p style="font-family:' + st2fn + ';font-size:' + st2fs +'pt; line-height:' + rs + 'pt; text-indent: '+ sn +'em;' + (st2Strong ? 'font-weight: bold;' : '') + '">' + t;
}
else
{
//標題不單獨成行
var n = getFirstPunctuationPos(t);
r = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em; font-size:' + st2fs +'pt; font-family:' + mtfn + '"><span style="font-family:' + st2fn + (st2Strong ? ';font-weight: bold;' : '') + '" >' + t.substring(0, n) + '</span>' + t.substring(n);
}
return r;
}//setParaTitle2(t)
代碼運行效果如下:
?其中(二)影視網(wǎng)站風險大!?因為序號左邊小括號為英文小括號,右邊括號為中文小括號,所以沒有按二級標題來設置格式。文章來源:http://www.zghlxwxcb.cn/news/detail-564667.html
完整代碼如下:文章來源地址http://www.zghlxwxcb.cn/news/detail-564667.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>公文一鍵排版</title>
<meta name="author" content="purpleendurer" >
<meta name="description" content="公文一鍵排版">
<script type="text/javascript">
const aFontName = [
"方正小標宋簡體",//0
"黑體",//1
"微軟雅黑",//2
"仿宋_GB2312",//3
"仿宋",//4
"楷體_GB2312",//5
"楷體",//6
"宋體",//7
"Arial",//8
"Wingdings 2"http://9
];
//sId:select control id, iDefSel:default selected
function showFontNameSel(sId, iDefSel)
{
document.write('<select id="', sId, '" width="50">');
for (var i = 0; i < aFontName.length; i++)
{
document.write('<option value="', aFontName[i], '"');
document.write(i==iDefSel ? ' selected>' : '>');
document.write(aFontName[i],'</option>');
}
document.write('</select>');
}
const aFontSize = [
['初號', 42],//0
['小初', 36],//1
['一號', 26],//2
['小一', 24],//3
['二號', 22],//4
['小二', 18],//5
['三號', 16],//6
['小三', 15],//7
['四號', 14],//8
['小四', 12],//9
['五號', 10.5], //10
['小五', 9],//11
['六號', 7.5],//12
['小六', 6.5],//13
['七號', 5.5],//14
['八號', 5]//15
];
//sId:select control id, iDefSel:default selected
function showFontSizeSel(sId, iDefSel)
{
document.write('<select id="', sId, '">');
for (var i = 0; i < aFontSize.length; i++)
{
document.write('<option value="',aFontSize[i][1], '"');
document.write(i==iDefSel ? ' selected>' : '>');
document.write(aFontSize[i][0],'</option>');
}
document.write('</select>');
}
const aAlign = [
["左對齊","left"],//0
["居中對齊","center"],//1
["右對齊","right"],//2
["兩端分散對齊","justify"]//3
];
//sId:select control id, iDefSel:default selected
function showAlignSel(sId, iDefSel)
{
document.write('<select id="', sId, '">');
for (var i = 0; i < aAlign.length; i++)
{
document.write('<option value="',aAlign[i][1], '"');
document.write(i==iDefSel ? ' selected>' : '>');
document.write(aAlign[i][0],'</option>');
}
document.write('</select>');
}
function showSrc()
{
if (btnShowSrc.value=="顯示源碼")
{
edRichBody.innerText = edRichBody.innerHTML;
btnShowSrc.value = "顯示預覽";
btnShowSrc.style.background = "cyan";
}
else
{
edRichBody.innerHTML = edRichBody.innerText;
btnShowSrc.value = "顯示源碼";
btnShowSrc.style.background = "yellow";
}
}
function stripPattribs(s)
{
var i = s.indexOf('>');
return ((-1 != i) ? s.substr(i+1) : s);
}
String.prototype.stripHTML = function()
{
var reTag = /<(?:.|\s)*?>/g;
//var reTag = /<[^>]+>/gi; //過濾所有html標簽,但不包括html標簽內的內容
return this.replace(reTag,"");
}
String.prototype.trim = function()
{//去除首尾空格
return this.replace(/(^\s*)|(\s*$)/g, "");
/*var t = this.replace(/(^\s*)|(\s*$)/g, "");
return t =t.replace(/(^ *)|( *$)/g, ""); */
}
function getClearInfoArray()
{
taDbg.value += "\n---getClearInfoArray()\n";
var s = edRichBody.innerHTML;
var t = s.split('<p');
for (var i=0; i < t.length; i++)
{
taDbg.value += "\nt[" + i + "]=" + t[i];
}
while (t[0].length==0 || t[0]=='></p>')
{
taDbg.value += "\nshift: " + t[0];
t.shift();
}
while (t[t.length-1].length==0 || t[t.length-1]=='></p>')
{
taDbg.value += "\npop: " + t[t.length-1];
t.pop();
}
for (var i=0; i < t.length; i++)
{
t[i] = stripPattribs(t[i]);
t[i] = t[i].stripHTML();
//以下兩句順序不能顛倒
t[i] = t[i].replace(/ /ig, ''); //去除空格代碼
t[i] = t[i].trim(); //去除首尾空格
}
while (t[t.length-1].length==0 || t[t.length-1]=='></p>')
{
taDbg.value += "\npop: " + t[t.length-1];
t.pop();
}
taDbg.value += "\n---\n";
for (var i=0; i < t.length; i++)
{
taDbg.value += "\nt[" + i + "]=" + t[i];
}
return t;
}
function clearDocFmt()
{
var s = '<p>' + getClearInfoArray().join('</p><p>');
edRichBody.innerHTML = s;
}
//判斷是否為中文標點符號
String.prototype.isCnPunctuation = function()
{
/*
var reg = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/;
return (reg.test(this)) ? true : false;
*/
return (/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/.test(this)) ? true : false;
}
//判斷是否為英文標點符號
String.prototype.isEnPunctuation = function()
{
/*
var reg = /[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/;
return (reg.test(c)) ? true : false;
*/
return (/[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/.test(this)) ? true : false;
}
//功能:判斷是否為中文或英文標點符號
String.prototype.isPunctuation = function()
{
//return ((/[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/.test(this)) || (/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/.test(this))) ? true : false;
return (this.isEnPunctuation() || this.isCnPunctuation()) ? true : false;
}
//功能:是否以標點符號結束Is aunctuation at the end of the string
String.prototype.isEndWithPunctuation = function()
{
/*
var c = this.substring(this.length-1);
return c.isPunctuation();
*/
return this.substring(this.length-1).isPunctuation();
}
var sStatementEndPunctuation = '。!?….!?';//語句結束符號
//功能:獲取段落文字中的第一個語句結束符號位置
//輸入:p:字符串
//輸出:第一個語句結束符號位置
function getFirstPunctuationPos(p)
{
//taDbg.value += '\n ---getFirstPunctuationPos(' + p + ')\n';
var r = p.length, n;
for (var i = 0; i < sStatementEndPunctuation.length; i++)
{
n = p.indexOf(sStatementEndPunctuation[i]);
if ( (-1 != n) && (n < r) )
{
r = n;
//taDbg.value += '\n' + sStatementEndPunctuation[i] + ': n=' + n + ' r=' + r;
}
}
return r;
}//getFirstPunctuationPos(p)
//功能:判斷字符串是否只有一句話
//輸入:p:字符串
//輸出:true:是一句話;false:不是一句話
function isAstatement(p)
{
/*
for (var i = 0; i < sStatementEndPunctuation.length; i++)
{
var n = p.indexOf(sStatementEndPunctuation[i]);
if (n !=-1 && n == p.length-1)
{
return true;
}
}
return false;
*/
var n = getFirstPunctuationPos(p);
return ((( -1 != n) && (n == p.length-1)) ? true : false);
}
//功能:標題是否單獨成行 Is paragraph title a single line?
//輸入:t:文字
//輸出:true:是獨立標題行,false:不是獨立標題行
function ptIsALine(t)
{
/*
var r = false;
var n = t.indexOf('。');
if (n==(t.length-1)) //句號是否位于段末
{
r = true;//有且只有一個'。'
}
else
{
if (!t.isEndWithPunctuation())//未以標點符號結尾
{
r = true;
}
}
return r;
*/
/*
if (!t.isEndWithPunctuation())//未以標點符號結尾
{
return true;
}
return (isAstatement(t));
*/
return (!t.isEndWithPunctuation()) ? true : isAstatement(t) ;
} //ptIsALine(t)
//功能:設置一級標題set paragraph format with primay title
//輸入:t:文字
//輸出:格式化字符串
function setParaTitle1(t)
{
var r;
if (ptIsALine(t)) //標題是否單獨成行
{
//return '<p style="font-family:' + fn + ';font-size:' + fs +'pt; text-align:' + ta + '; line-height:' + rs + 'pt;">' + s;
r = '<p style="font-family:' + pt1fn + ';font-size:' + pt1fs +'pt; line-height:' + rs + 'pt; text-indent: '+ sn +'em;">' + t;
}
else
{
//標題不單獨成行
var n = getFirstPunctuationPos(t);//t.indexOf('。');
r = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em; font-family:' + mtfn + '"><span style="font-family:' + pt1fn + ';font-size:' + pt1fs +'pt;" >' + t.substring(0, n) + '</span>' + t.substring(n);
}
taDbg.value += "\n---setParaTitle1:" + r;
return r;
} //setParaTitle1(t)
//功能:設置二級標題set paragraph format with secondary title
//輸入:t:文字
//輸出:格式化字符串
function setParaTitle2(t)
{
taDbg.value += "\n---setParaTitle2:" + t;
var r;
if (ptIsALine(t)) //標題是否單獨成行
{
//return '<p style="font-family:' + fn + ';font-size:' + fs +'pt; text-align:' + ta + '; line-height:' + rs + 'pt;">' + s;
r = '<p style="font-family:' + st2fn + ';font-size:' + st2fs +'pt; line-height:' + rs + 'pt; text-indent: '+ sn +'em;' + (st2Strong ? 'font-weight: bold;' : '') + '">' + t;
}
else
{
//標題不單獨成行
var n = getFirstPunctuationPos(t);
r = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em; font-size:' + st2fs +'pt; font-family:' + mtfn + '"><span style="font-family:' + st2fn + (st2Strong ? ';font-weight: bold;' : '') + '" >' + t.substring(0, n) + '</span>' + t.substring(n);
}
return r;
}//setParaTitle2(t)
//是否為只包含一二三四五六七八九十的字符串
String.prototype.isCnNum = function()
{
//[\u4e00|\u4e8c|\u4e09|\u56db|\u4e94|\u516d|\u4e03|\u516b|\u4e5d|\u5341] = [一二三四五六七八九十]
return (/^[\u4e00|\u4e8c|\u4e09|\u56db|\u4e94|\u516d|\u4e03|\u516b|\u4e5d|\u5341]+$/.test(this));
}
//Is the paragraph with primary title?一級標題
function isIncludePrimaryTitle(p)
{
var t = p.indexOf('、');
return ((-1 != t) && (p.substring(0,t).isCnNum())) ? true : false;
//return /^[\u4e00|\u4e8c|\u4e09|\u56db|\u4e94|\u516d|\u4e03|\u516b|\u4e5d|\u5341]+[\u3001]{1}/.test(p); //可匹配“ 十一、三四”中的“十一、”
//return /^\s*[\u4e00|\u4e8c|\u4e09|\u56db|\u4e94|\u516d|\u4e03|\u516b|\u4e5d|\u5341]+[\u3001]{1}/.test(p); //可匹配“ 十一、三四”或“ 十一、三四”中的“十一、”
//(\b[\u4e00|\u4e8c|\u4e09|\u56db|\u4e94|\u516d|\u4e03|\u516b|\u4e5d|\u5341])*[\u3001]{1},可匹配“十一、三四”中的頓號
//\b[\u4e00|\u4e8c|\u4e09|\u56db|\u4e94|\u516d|\u4e03|\u516b|\u4e5d|\u5341]*[\u3001]{1},可匹配“a十一、三四”中的“十一、”
}//isIncludePrimaryTitle(p)
//Is a secondary title serial number with parenthesis是帶小括號的二級標題序號嗎?
function isT2SNwithParenthesis(p)
{
var t = p[0];
if (t == '(')
{
t = p.indexOf(')');
if ((-1 != t) && ((p.substring(1,t)).isCnNum()))
{
return true;
}
}//if
if (t == '(')
{
t= p.indexOf(')');
if ((-1 != t) && (p.substring(1,t).isCnNum()))
{
return true;
}
}//if
return false;//二級標題
}//isSNwithParenthesis(p)
//Is the paragraph with secondary title?二級標題
function isIncludeSecondaryTitle(p)
{
var t = p[0];//t = p.substring(0, 1);
if (-1!= "㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩".indexOf(t))
{
return true;
}
if (isT2SNwithParenthesis(p))
{
return true;//二級標題
}
return false;
}//isIncludeSecondaryTitle(p)
//功能:獲取文字串的標題級別
//輸入:p:文字串
//輸出:1:一級標題,2:二級標題,3:三級標題,0:其它
function getTitleLevel(p)
{
taDbg.value += "\n---getTitleLevel:" + p;
if (isIncludeSecondaryTitle(p))
{
//alert(t);
return 2;//二級標題
}
if (isIncludePrimaryTitle(p))//一級標題
{
return 1;
}
//三級標題
/*
return 3;
*/
return 0;
}//getTitleLevel(p)
//功能:設置段落格式set paragraph format
//輸入:p:段落文字
//輸出:設置格式的文本
function setParaFmt(p)
{
switch (getTitleLevel(p))
{
case 1:
t = setParaTitle1(p);//一級標題
break;
case 2:
t = setParaTitle2(p);//二級標題
break;
/*
case 3:
t = setParaTitle3(p);//三級標題
break;
*/
default: //main text正文
t = '<p style="line-height:' + rs + 'pt; text-indent: '+ sn +'em;font-family:' + mtfn + '; font-size:'+ mtfs + 'pt;">' + p;
}//switch
return t;
}
function setDocTitle(s)
{
taDbg.value += "\n--- setDocTitle("+ s + ");" ;
return '<p style="font-family:' + dtfn + ';font-size:' + dtfs +'pt; text-align:' + dtta + '; line-height:' + rs + 'pt;">' + s;
}
function getArg()
{
// 排版內容包括公文標題
cbDocTilte = document.getElementById('cbDocTilte').checked;
//標題字體名 document title font name
dtfn = document.getElementById('selDocTitleFontName').value;
//alert(fn);
//標題字號 document title font size
dtfs = document.getElementById('selDocTitleFontSize').value;
//alert(fs);
//標題對齊方式 document title text align
dtta = document.getElementById('selDocTitleAlign').value;
//一級標題字號 primary title font name
pt1fn = document.getElementById('selPrimaryTitleFontName').value;
//一級標題字號 primary titlefont size
pt1fs = document.getElementById('selPrimaryTitleFontSize').value;
//二級標題字號 psecondary title font name
st2fn = document.getElementById('selSecondaryTitleFontName').value;
//二級標題字號 secondary title font size
st2fs = document.getElementById('selSecondaryTitleFontSize').value;
//二級標題字體加粗 secondary title strong
st2Strong = document.getElementById('cbSecondaryTitleStrong').checked;
//三級標題字體加粗 third title strong
tt3Strong = document.getElementById('cbThirdTitleStrong').checked;
//正文字體名稱
mtfn = document.getElementById('selMainTextFontName').value;
//正文字體字號
mtfs = document.getElementById('selMainTextFontSize').value;
//行距 row spacing
rs = document.getElementById('tbRowSp').value;
//首行行首空格數(shù)
sn = document.getElementById('tbLeadSpNum').value;
}// getArg()
function setDocFmt()
{
taDbg.value += "\n---setDocFmt()\n";
getArg();
var t = getClearInfoArray();
//標題
if (cbDocTilte)
{
t[0] = setDocTitle(t[0]) + '</p><p style="line-height:"' + rs +'"> ';
}
for (var i = (cbDocTilte ? 1: 0); i < t.length; i++)
{
t[i] = setParaFmt(t[i]);
}
edRichBody.innerHTML = t.join('');
}//setDocFmt()
</script>
</head>
<body>
<fieldset style="width: 1100px;">
<legend>實時編輯區(qū)</legend>
<!--
<iframe id="editor" width="600px" height="200px" style="border: solid 1px;" src="http://nyncj.hechi.gov.cn"></iframe>
//-->
<iframe id="editor" width="1200px" height="400px" style="border: solid 1px;"></iframe>
</fieldset>
<p>
<input type="button" id="btnclearDocFmt" value="清除格式" onclick="clearDocFmt()" />
<input type="button" id="btnsetDocFmt" value="一鍵排版" onclick="setDocFmt()" />
<input type="button" id="btnShowSrc" value="顯示源碼" onclick="showSrc()" style="background:yellow; border-radius: 25px;" />
<input type="button" id="btnB" value="B" title="加粗/正常" style="font-weight:bolder" onclick="execCmd('bold',false,null)" />
<input type="button" id="btnItalic" value="I" title="斜體/正常" style="font-weight:bolder;font-style:italic" onclick="execCmd('italic',false,null)" />
</p>
<fieldset style="width: 1200px;">
<legend>參數(shù)設置</legend>
公文標題:<input type="checkbox" checked id="cbDocTilte">排版內容包括公文標題
<script>
showFontNameSel("selDocTitleFontName", 0);
document.write(' ');
showFontSizeSel("selDocTitleFontSize", 4);
document.write(' ');
showAlignSel("selDocTitleAlign", 1);
</script>
<p>正文一級標題:
<script>
showFontNameSel("selPrimaryTitleFontName", 1);
document.write(' ');
showFontSizeSel("selPrimaryTitleFontSize", 6);
</script>
</p>
<p>正文二級標題:
<script>
showFontNameSel("selSecondaryTitleFontName", 5);
document.write(' ');
showFontSizeSel("selSecondaryTitleFontSize", 6);
</script>
<input type="checkbox" checked id="cbSecondaryTitleStrong">粗體
</p>
<p>正文三級標題:
<input type="checkbox" checked id="cbThirdTitleStrong">粗體
</p>
<p>正文:
<script>
showFontNameSel("selMainTextFontName", 3);
document.write(' ');
showFontSizeSel("selMainTextFontSize", 6);
document.write(' ');
</script>
行距(行間距):<input type="text" id="tbRowSp" value="28" size="2"><!-- row spacing//--> 段落首行行首空格數(shù):<input type="text" id="tbLeadSpNum" value="2" size="2">
</P>
</fieldset>
<!--
<input type="text" id="path" value="https://www.google.com.hk/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" />
<input type="button" id="insert_img" value="插入圖片" />
//-->
<p>調試信息</p>
<textarea id="taDbg" style="width: 1225px; height: 200px">調試信息</textarea>
<script type="text/javascript">
const edRich = document.getElementById("editor");
const taDbg = document.getElementById("taDbg");
const btnShowSrc = document.getElementById("btnShowSrc");
//排版內容是否包括公文標題
var cbDocTilte; // = document.getElementById('cbDocTilte').value;
//標題字體名 document title font name
var dtfn; // = document.getElementById('selDocTitleFontName').value;
//標題字號 document title font size
var dtfs; // = document.getElementById('selDocTitleFontSize').value;
//標題對齊方式 document title text align
var dtta;// = document.getElementById('selDocTitleAlign').value;
//一級標題字號 font name
var pt1fn; // = document.getElementById('selPrimaryTitleFontName').value;
//一級標題字號 font size
var pt1fs; // = document.getElementById('selPrimaryTitleFontSize').value;
//二級標題字號 psecondary title font name
var st2fn; // = document.getElementById('selSecondaryTitleFontName').value;
//二級標題字號 secondary title font size
var st2fs; // = document.getElementById('selSecondaryTitleFontSize').value;
//二級標題字體加粗 secondary title strong
var st2Strong; // = document.getElementById('cbSecondaryTitleStrong').value;
//三級標題字體加粗 third title strong
var tt3Strong; // = document.getElementById('cbThirdTitleStrong').value;
//行距 row spacing
var rs; // = document.getElementById('tbRowSp').value;
//首行行首空格數(shù)
var sn; // = document.getElementById('tbLeadSpNum').value;
//正文字體名稱
var mtfn; // = document.getElementById('selMainTextFontName').value;
//正文字體字號
var mtfs; // = document.getElementById('selMainTextFontSize').value;
var edRichDoc;
var edRichBody;
//var edRichHTML;
if (typeof(edRich) !="undefined")
{
edRichDoc = edRich.contentWindow.document;
edRichDoc.designMode = "on";
edRichDoc.contentEditable = true;
edRichBody = edRichDoc.body;
//edRichHTML = edRichDoc.body.innerHTML;
//edRich.contentWindow.document.body.innerHTML = '<a href="ttp://nyncj.hechi.gov.cn">abc</a>';
//edRichHTML = '<a ;
edRichBody.innerHTML = '<p><a >http://blog.csdn.net/purpleendurer</a></p><p></p><p style="font-family:方正小標宋簡體;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:方正小標宋簡體;mso-hansi-font-family:黑體;color:black">SQL</span><span style="font-size:22.0pt;font-family:方正小標宋簡體;mso-hansi-font-family:黑體;color:black">注入基礎<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;font-family:黑體;color:black">一、<span lang="EN-US">SQL</span>注入分類<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>:當<span lang="EN-US">web</span>應用向后臺數(shù)據(jù)庫傳遞<span lang="EN-US">SQL</span>語句進行數(shù)據(jù)庫操作時,如果對用戶輸入的參數(shù)沒有經過嚴格的過濾,那么用戶可以構造特殊的<span lang="EN-US">sq1</span>語句,從而帶入到數(shù)據(jù)庫中執(zhí)行,獲取或修改數(shù)據(jù)庫中的數(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"><b><span lang="EN-US" style="font-size:16.0pt;font-family:楷體_GB2312;color:black">(</span></b><b><span style="font-size:16.0pt;font-family:楷體_GB2312;color:black">二)影視網(wǎng)站風險大!<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 style="font-size:16.0pt;font-family:仿宋_GB2312;color:black">例如很多影視網(wǎng)站泄露<span lang="EN-US">VIP</span>會員密碼大多就是通過<span lang="EN-US">SQL</span>注入漏洞暴露的,這類網(wǎng)站特別容易受到<span lang="EN-US">SQL</span>注入攻擊。<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"><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 style="font-size:16.0pt;font-family:宋體;color:black"> 加強……<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:宋體;color:black">(四)本章小結。<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 style="font-size:16.0pt;font-family:宋體;color:black">要……</span></p><p style="text-align:center">㈤習題</p>';
}
else
{
window.alert("undefined");
}
function replaceStr(s1,s2)
{
try
{
var r = document.body.createTextRange();
if (r.findText(s1))
{
r.expand('charactor');
r.select();
r.text = s2;
r.scrollIntoView();
}
else
{
alert('"'+s+'" not found!');
}
}
catch (e)
{
alert(e.description);
}
}
function showSrc()
{
if (btnShowSrc.value=="顯示源碼")
{
edRichBody.innerText = edRichBody.innerHTML;
btnShowSrc.value = "顯示預覽";
btnShowSrc.style.background = "cyan";
}
else
{
edRichBody.innerHTML = edRichBody.innerText;
btnShowSrc.value = "顯示源碼";
btnShowSrc.style.background = "yellow";
}
}
function execCmd(cmd,f,v)
{
edRichDoc.execCommand(cmd,f,v);
}
</script>
</body>
</html>
到了這里,關于用html+javascript打造公文一鍵排版系統(tǒng)5:二級標題排版的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!