📄 jtextile.java
字号:
codepre = false;
notextile = false;
}
if(!preg_match("<.[^<]*?>",textSplit[i]) && codepre == false)
{
textSplit[i] = preg_replace(glyph_search,glyph_replace,textSplit[i]);
}
//# convert htmlspecial if between <code>
if (codepre == true && notextile == false){
textSplit[i] = htmlspecialchars(textSplit[i],ENT_NOQUOTES);
textSplit[i] = replace(textSplit[i],"<pre>","<pre>");
textSplit[i] = replace(textSplit[i],"<code>","<code>");
textSplit[i] = replace(textSplit[i],"<notextile>","<notextile>");
}
if(notextile == true)
{
textSplit[i] = replace(textSplit[i],"\n","({)(})");
}
//# each line gets pushed to a new array
out.append( textSplit[i]);
}
text = out.toString();
}
//### Block level formatting
//# deal with forced breaks; this is going to be a problem between
//# <pre> tags, but we'll clean them later
//////!!! not working
//text = preg_replace("(\\S)(_*)([[:punct:]]*) *\n([^#*\\s])", "$1$2$3<br />$4", text);
//text = preg_replace("(\\S)(_*)([:punct:]*) *\\n([^#*\\s])", "$1$2$3<br />$4", text);
text = preg_replace("(\\S)(_*)([:punct:]*) *\\n([^#*\\s])", "$1$2$3<br />$4", text);
//# might be a problem with lists
text = replace(text,"l><br />", "l>\n");
boolean pre = false;
String[] block_find = {
"^\\s?\\*\\s(.*)", //# bulleted list *
"^\\s?#\\s(.*)", //# numeric list #
"^bq\\. (.*)", //# blockquote bq.
"^bq\\((\\S+?)\\). (.*)", //# blockquote bq(cite-url).
"^h(\\d)\\(([\\w]+)\\)\\.\\s(.*)", //# header hn(class). w/ css class
"^h(\\d)\\. (.*)", //# plain header hn.
"^p\\(([[:alnum:]]+)\\)\\.\\s(.*)", //# para p(class). w/ css class
"^p\\. (.*)", //# plain paragraph
"^([^\\t ]+.*)" //# remaining plain paragraph
};
/*
String[] block_find = {
"/^\\s?\\*\\s(.*)/", // # bulleted list *
"/^\\s?#\\s(.*)/", // # numeric list #
"/^bq\\. (.*)/", // # blockquote bq.
"/^h(\\d)\\(([[:alnum:]]+)\\)\\.\\s(.*)/", // # header hn(class). w/ css class
"/^h(\\d)\\. (.*)/", // # plain header hn.
"/^p\\(([[:alnum:]]+)\\)\\.\\s(.*)/", // # para p(class). w/ css class
"/^p\\. (.*)/i", // # plain paragraph
"/^([^\\t ]+.*)/i" // # remaining plain paragraph
};
*/
String[] block_replace = {
"\t<liu>$1</liu>$2",
"\t<lio>$1</lio>$2",
"\t<blockquote>$1</blockquote>$2",
"\t<blockquote cite=\"$1\">$2</blockquote>$3",
"\t<h$1 class=\"$2\">$3</h$1>$4",
"\t<h$1>$2</h$1>$3",
"\t<p class=\"$1\">$2</p>$3",
"\t<p>$1</p>",
"\t<p>$1</p>$2"
};
StringBuffer blockBuffer = new StringBuffer();
String list = "";
// This done to ensure that lists close after themselves
text += " \n";
//# split the text into an array by newlines
String[] bList = text.split("\n");
for(int i = 0; i <= bList.length; i++)
{
String line = " ";
if(i < bList.length)
line = bList[i];
//#make sure the line isn't blank
if (true || line.length() > 0 ) // actually i think we want blank lines
{
//# matches are off if we're between <pre> or <code> tags
if(line.toLowerCase().indexOf("<pre>") > -1)
{
pre = true;
}
//# deal with block replacements first, then see if we're in a list
if (!pre)
{
line = preg_replace(block_find,block_replace,line);
}
//# kill any br tags that slipped in earlier
if (pre == true)
{
line = replace(line,"<br />","\n");
}
//# matches back on after </pre>
if(line.toLowerCase().indexOf("</pre>") > -1)
{
pre = false;
}
//# at the beginning of a list, $line switches to a value
if (list.length() == 0 && preg_match("\\t<li",line))
{
line = preg_replace("^(\\t<li)(o|u)","\n<$2l>\n$1$2",line);
list = line.substring(2,3);
}
//# at the end of a list, $line switches to empty
else if (list.length() > 0 && !preg_match("\\t<li" + list,line))
{
line = preg_replace("^(.*)$","</" + list + "l>\n$1",line);
list = "";
}
}
// push each line to a new array once it's processed
blockBuffer.append(line);
blockBuffer.append("\n");
}
text = blockBuffer.toString();
//#clean up <notextile>
text = preg_replace("<\\/?notextile>", "",text);
//#clean up <notextile>
text = replace(text,"({)(})", "\n");
//# clean up liu and lio
text = preg_replace("<(\\/?)li(u|o)>", "<$1li>",text);
//# turn the temp char back to an ampersand entity
text = replace(text,"x%x%","&");
//# Newline linebreaks, just for markup tidiness
text = replace(text,"<br />","<br />\n");
return text;
}
/**
* Does just that.
*
* @param source The string to start with
* @param searchFor The string we are looking for
* @param replaceWith The replacement
*
* @return The reformatted string
*
*/
private static String replace ( String source , String searchFor , String replaceWith )
{
if (source == null || "".equals(source)) {
return source;
}
if (replaceWith == null) {
return source;
}
if ("".equals(searchFor)) {
return source;
}
int s = 0;
int e = 0;
StringBuffer result = new StringBuffer();
while ((e = source.indexOf(searchFor, s)) >= 0)
{
result.append(source.substring(s, e));
result.append(replaceWith);
s = e + searchFor.length();
}
result.append(source.substring(s));
return result.toString();
}
private static String htmlspecialchars(String text, int mode)
{
text = replace(text,"&", "&");
if (mode != ENT_NOQUOTES)
text = replace(text,"\"", """);
if (mode == ENT_QUOTES)
text = replace(text,"'", "'");
text = replace(text,"<", "<");
text = replace(text,">", ">");
return text ;
}
private static String preg_replace(String pattern,String replace,String text) throws Exception
{
gnu.regexp.RE r = new gnu.regexp.RE(pattern);
return r.substituteAll(text,replace);
}
private static String preg_replace(String[] pattern,String[] replace,String text) throws Exception
{
for(int i = 0; i < pattern.length; i++)
{
text = preg_replace(pattern[i],replace[i],text);
}
return text;
}
private static boolean preg_match(String pattern,String text) throws Exception
{
gnu.regexp.RE r = new gnu.regexp.RE(pattern);
return r.getMatch(text) != null;
}
private static String[] preg_split(String pattern,String text) throws Exception
{
int startAt = 0;
ArrayList tempList = new ArrayList();
gnu.regexp.RE r = new gnu.regexp.RE(pattern);
gnu.regexp.REMatch match = r.getMatch(text);
while(match != null)
{
String beforeMatch = text.substring(startAt,match.getStartIndex());
tempList.add(beforeMatch);
tempList.add(match.toString());
startAt = match.getEndIndex();
match = r.getMatch(text,startAt);
}
tempList.add(text.substring(startAt));
// copy out our templist to an array of strings which is what we return
String[] ret = new String[tempList.size()];
for(int i = 0; i < ret.length; i++)
{
ret[i] = (String)tempList.get(i);
}
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -