mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Handling < > & and unicode in copy to html.
http://code.google.com/p/arduino/issues/detail?id=29
This commit is contained in:
parent
6cbb866123
commit
06d3d85143
@ -114,6 +114,26 @@ public class DiscourseFormat {
|
|||||||
" has been copied to the clipboard.");
|
" has been copied to the clipboard.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a char to a stringbuffer while escaping for proper display in HTML.
|
||||||
|
* @param c input char to escape
|
||||||
|
* @param buffer StringBuffer to append html-safe version of c to.
|
||||||
|
*/
|
||||||
|
private void appendToHTML(char c, StringBuffer buffer) {
|
||||||
|
if (!html) {
|
||||||
|
buffer.append(c);
|
||||||
|
} else if (c == '<') {
|
||||||
|
buffer.append("<");
|
||||||
|
} else if (c == '>') {
|
||||||
|
buffer.append(">");
|
||||||
|
} else if (c == '&') {
|
||||||
|
buffer.append("&");
|
||||||
|
} else if (c > 127) {
|
||||||
|
buffer.append("&#" + ((int) c) + ";"); // use unicode entity
|
||||||
|
} else {
|
||||||
|
buffer.append(c); // normal character
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A terrible headache...
|
// A terrible headache...
|
||||||
public void appendFormattedLine(StringBuffer cf, int line) {
|
public void appendFormattedLine(StringBuffer cf, int line) {
|
||||||
@ -138,7 +158,7 @@ public class DiscourseFormat {
|
|||||||
if (tokenMarker == null) {
|
if (tokenMarker == null) {
|
||||||
for (int j = 0; j < segmentCount; j++) {
|
for (int j = 0; j < segmentCount; j++) {
|
||||||
char c = segmentArray[j + segmentOffset];
|
char c = segmentArray[j + segmentOffset];
|
||||||
cf = cf.append(c);
|
appendToHTML(c, cf);
|
||||||
// int charWidth;
|
// int charWidth;
|
||||||
// if (c == '\t') {
|
// if (c == '\t') {
|
||||||
// charWidth = (int) painter.nextTabStop(width, j) - width;
|
// charWidth = (int) painter.nextTabStop(width, j) - width;
|
||||||
@ -171,7 +191,7 @@ public class DiscourseFormat {
|
|||||||
if (id == Token.END) {
|
if (id == Token.END) {
|
||||||
char c = segmentArray[segmentOffset + offset];
|
char c = segmentArray[segmentOffset + offset];
|
||||||
if (segmentOffset + offset < limit) {
|
if (segmentOffset + offset < limit) {
|
||||||
cf.append(c);
|
appendToHTML(c, cf);
|
||||||
} else {
|
} else {
|
||||||
cf.append('\n');
|
cf.append('\n');
|
||||||
}
|
}
|
||||||
@ -203,7 +223,7 @@ public class DiscourseFormat {
|
|||||||
// cf.append(' ');
|
// cf.append(' ');
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
cf.append(c);
|
appendToHTML(c, cf);
|
||||||
}
|
}
|
||||||
// Place close tags [/]
|
// Place close tags [/]
|
||||||
if (j == (length - 1) && id != Token.NULL && styles[id].isBold())
|
if (j == (length - 1) && id != Token.NULL && styles[id].isBold())
|
||||||
@ -225,4 +245,4 @@ public class DiscourseFormat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user