public static String friendlyEncodeHTML(String text, boolean skipLeadingWhitespace) {

		StringBuilder buffer = new StringBuilder();

		int i = 0;
		int col = 0;
		if (skipLeadingWhitespace) {
			for (i = 0; i < text.length(); i++) { // skip leading spaces.
				if (!Character.isWhitespace(text.charAt(i))) {
					break;
				}
			}
		}
		for (; i < text.length(); i++) {
			char c = text.charAt(i);
			if (c == '\r') {
				// Strip CR and reset column
				col = 0;
				continue;
			}
			else if (c == '\n') {
				buffer.append(c);
				col = 0;
				continue;
			}
			else if (c == '\t') {
				int cnt = TAB_SIZE - (col % TAB_SIZE);
				for (int k = 0; k < cnt; k++) {
					buffer.append(HTML_SPACE);
				}
				col = 0;
				continue;
			}
			else if (c == ' ') {
				buffer.append(HTML_SPACE);
			}
			else if (c < ' ') {
				// Strip other non-printing chars
				continue;
			}
			else if (c > 0x7F) {
				buffer.append("&#x");
				buffer.append(Integer.toString(c, 16).toUpperCase());
				buffer.append(";");
			}
			else {
				switch (c) {
					case '&':
						buffer.append("&amp;");
						break;
					case '<':
						buffer.append("&lt;");
						break;
					case '>':
						buffer.append("&gt;");
						break;
					case 0x7F:
						break;
					default:
						buffer.append(c);
						break;
				}
			}
			++col;
		}

		return buffer.toString();
	}
See {@link #friendlyEncodeHTML(String)}

@param text string to be encoded
@param skipLeadingWhitespace  true signals to ignore any leading whitespace characters.
	      This is useful when line wrapping to force wrapped lines to the left
@return the encoded HTML string
Ghidra/Framework/Gui/src/main/java/ghidra/util/HTMLUtilities.java