diff --git a/src/main/java/com/github/rjeschke/txtmark/Block.java b/src/main/java/com/github/rjeschke/txtmark/Block.java index 01bd969..ab3819b 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Block.java +++ b/src/main/java/com/github/rjeschke/txtmark/Block.java @@ -36,7 +36,7 @@ class Block public String id = null; /** Block meta information */ public String meta = ""; - + /** Constructor. */ public Block() { diff --git a/src/main/java/com/github/rjeschke/txtmark/Configuration.java b/src/main/java/com/github/rjeschke/txtmark/Configuration.java index 2359e96..3acfdee 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Configuration.java +++ b/src/main/java/com/github/rjeschke/txtmark/Configuration.java @@ -101,7 +101,7 @@ public class Configuration private Decorator decorator = new DefaultDecorator(); private BlockEmitter codeBlockEmitter = null; private SpanEmitter specialLinkEmitter = null; - + /** * Constructor. * @@ -206,7 +206,8 @@ public class Configuration /** * Sets the emitter for special link spans ([[ ... ]]). * - * @param emitter The emitter. + * @param emitter + * The emitter. * @return This builder. * @since 0.7 */ @@ -215,7 +216,7 @@ public class Configuration this.specialLinkEmitter = emitter; return this; } - + /** * Builds a configuration instance. * diff --git a/src/main/java/com/github/rjeschke/txtmark/Decorator.java b/src/main/java/com/github/rjeschke/txtmark/Decorator.java index a5d6fe0..c29b05d 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Decorator.java +++ b/src/main/java/com/github/rjeschke/txtmark/Decorator.java @@ -25,20 +25,32 @@ public interface Decorator /** * Called when a paragraph is opened. * - *

Default implementation is:

- *
out.append("<p>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<p>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openParagraph(final StringBuilder out); - + /** * Called when a paragraph is closed. * - *

Default implementation is:

- *
out.append("</p>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</p>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeParagraph(final StringBuilder out); @@ -46,236 +58,380 @@ public interface Decorator * Called when a blockquote is opened. * * Default implementation is: - *
out.append("<blockquote>");
* - * @param out The StringBuilder to write to. + *
+     * out.append("<blockquote>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openBlockquote(final StringBuilder out); - + /** * Called when a blockquote is closed. * - *

Default implementation is:

- *
out.append("</blockquote>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</blockquote>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeBlockquote(final StringBuilder out); - + /** * Called when a code block is opened. * - *

Default implementation is:

- *
out.append("<pre><code>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<pre><code>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openCodeBlock(final StringBuilder out); - + /** * Called when a code block is closed. * - *

Default implementation is:

- *
out.append("</code></pre>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</code></pre>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeCodeBlock(final StringBuilder out); - + /** * Called when a code span is opened. * - *

Default implementation is:

- *
out.append("<code>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<code>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openCodeSpan(final StringBuilder out); /** * Called when a code span is closed. * - *

Default implementation is:

- *
out.append("</code>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</code>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeCodeSpan(final StringBuilder out); - + /** * Called when a headline is opened. * - *

Note: Don't close the HTML tag!

- *

Default implementation is:

- *
 out.append("<h");
-     * out.append(level);
+ *

+ * Note: Don't close the HTML tag! + *

+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     *  out.append("<h");
+     * out.append(level);
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openHeadline(final StringBuilder out, int level); - + /** * Called when a headline is closed. * - *

Default implementation is:

- *
 out.append("</h");
-     * out.append(level);
-     * out.append(">\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     *  out.append("</h");
+     * out.append(level);
+     * out.append(">\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeHeadline(final StringBuilder out, int level); /** * Called when a strong span is opened. * - *

Default implementation is:

- *
out.append("<strong>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<strong>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openStrong(final StringBuilder out); /** * Called when a strong span is closed. * - *

Default implementation is:

- *
out.append("</strong>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</strong>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeStrong(final StringBuilder out); - + /** * Called when an emphasis span is opened. * - *

Default implementation is:

- *
out.append("<em>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<em>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openEmphasis(final StringBuilder out); - + /** * Called when an emphasis span is closed. * - *

Default implementation is:

- *
out.append("</em>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</em>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeEmphasis(final StringBuilder out); /** * Called when a superscript span is opened. * - *

Default implementation is:

- *
out.append("<sup>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<sup>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openSuper(final StringBuilder out); /** * Called when a superscript span is closed. * - *

Default implementation is:

- *
out.append("</sup>");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</sup>");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeSuper(final StringBuilder out); /** * Called when an ordered list is opened. * - *

Default implementation is:

- *
out.append("<ol>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<ol>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openOrderedList(final StringBuilder out); - + /** * Called when an ordered list is closed. * - *

Default implementation is:

- *
out.append("</ol>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</ol>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeOrderedList(final StringBuilder out); /** * Called when an unordered list is opened. * - *

Default implementation is:

- *
out.append("<ul>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<ul>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openUnorderedList(final StringBuilder out); - + /** * Called when an unordered list is closed. * - *

Default implementation is:

- *
out.append("</ul>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</ul>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeUnorderedList(final StringBuilder out); - + /** * Called when a list item is opened. * - *

Note: Don't close the HTML tag!

- *

Default implementation is:

- *
out.append("<li");
+ *

+ * Note: Don't close the HTML tag! + *

+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<li");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openListItem(final StringBuilder out); - + /** * Called when a list item is closed. * - *

Default implementation is:

- *
out.append("</li>\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("</li>\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void closeListItem(final StringBuilder out); - + /** * Called when a horizontal ruler is encountered. * - *

Default implementation is:

- *
out.append("<hr />\n");
+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<hr />\n");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void horizontalRuler(final StringBuilder out); - + /** * Called when a link is opened. * - *

Note: Don't close the HTML tag!

- *

Default implementation is:

- *
out.append("<a");
+ *

+ * Note: Don't close the HTML tag! + *

+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<a");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openLink(final StringBuilder out); - + /** * Called when an image is opened. * - *

Note: Don't close the HTML tag!

- *

Default implementation is:

- *
out.append("<img");
+ *

+ * Note: Don't close the HTML tag! + *

+ *

+ * Default implementation is: + *

* - * @param out The StringBuilder to write to. + *
+     * out.append("<img");
+     * 
+ * + * @param out + * The StringBuilder to write to. */ public void openImage(final StringBuilder out); } diff --git a/src/main/java/com/github/rjeschke/txtmark/Emitter.java b/src/main/java/com/github/rjeschke/txtmark/Emitter.java index 7b86bbd..27cc581 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Emitter.java +++ b/src/main/java/com/github/rjeschke/txtmark/Emitter.java @@ -31,7 +31,7 @@ class Emitter private final Configuration config; /** Extension flag. */ public boolean useExtensions = false; - + /** Constructor. */ public Emitter(final Configuration config) { @@ -42,8 +42,10 @@ class Emitter /** * Adds a LinkRef to this set of LinkRefs. * - * @param key The key/id. - * @param linkRef The LinkRef. + * @param key + * The key/id. + * @param linkRef + * The LinkRef. */ public void addLinkRef(final String key, final LinkRef linkRef) { @@ -53,8 +55,10 @@ class Emitter /** * Transforms the given block recursively into HTML. * - * @param out The StringBuilder to write to. - * @param root The Block to process. + * @param out + * The StringBuilder to write to. + * @param root + * The Block to process. */ public void emit(final StringBuilder out, final Block root) { @@ -156,8 +160,10 @@ class Emitter /** * Transforms lines into HTML. * - * @param out The StringBuilder to write to. - * @param block The Block to process. + * @param out + * The StringBuilder to write to. + * @param block + * The Block to process. */ private void emitLines(final StringBuilder out, final Block block) { @@ -181,9 +187,12 @@ class Emitter /** * Finds the position of the given Token in the given String. * - * @param in The String to search on. - * @param start The starting character position. - * @param token The token to find. + * @param in + * The String to search on. + * @param start + * The starting character position. + * @param token + * The token to find. * @return The position of the token or -1 if none could be found. */ private int findToken(final String in, int start, MarkToken token) @@ -201,10 +210,14 @@ class Emitter /** * Checks if there is a valid markdown link definition. * - * @param out The StringBuilder containing the generated output. - * @param in Input String. - * @param start Starting position. - * @param token Either LINK or IMAGE. + * @param out + * The StringBuilder containing the generated output. + * @param in + * Input String. + * @param start + * Starting position. + * @param token + * Either LINK or IMAGE. * @return The new position or -1 if there is no valid markdown link. */ private int checkLink(final StringBuilder out, final String in, int start, MarkToken token) @@ -212,7 +225,7 @@ class Emitter boolean isAbbrev = false; int pos = start + (token == MarkToken.LINK ? 1 : 2); final StringBuilder temp = new StringBuilder(); - + temp.setLength(0); pos = Utils.readMdLinkId(temp, in, pos); if(pos < start) @@ -355,12 +368,15 @@ class Emitter } /** - * Check if there is a valid HTML tag here. - * This method also transforms auto links and mailto auto links. + * Check if there is a valid HTML tag here. This method also transforms auto + * links and mailto auto links. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Starting position. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Starting position. * @return The new position or -1 if nothing valid has been found. */ private int checkHtml(final StringBuilder out, final String in, int start) @@ -386,7 +402,7 @@ class Emitter return pos; } } - + // Check for mailto auto link temp.setLength(0); pos = Utils.readUntil(temp, in, start + 1, '@', ' ', '>', '\n'); @@ -406,23 +422,26 @@ class Emitter return pos; } } - + // Check for inline html if(start + 2 < in.length()) { temp.setLength(0); return Utils.readXML(out, in, start, this.config.safeMode); - } - + } + return -1; } - + /** * Check if this is a valid XML/HTML entity. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Starting position + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Starting position * @return The new position or -1 if this entity in invalid. */ private static int checkEntity(final StringBuilder out, final String in, int start) @@ -465,18 +484,24 @@ class Emitter out.append(';'); return HTML.isEntity(out.toString()) ? pos : -1; } - + return pos; } - + /** - * Recursively scans through the given line, taking care of any markdown stuff. + * Recursively scans through the given line, taking care of any markdown + * stuff. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Start position. - * @param token The matching Token (for e.g. '*') - * @return The position of the matching Token or -1 if token was NONE or no Token could be found. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Start position. + * @param token + * The matching Token (for e.g. '*') + * @return The position of the matching Token or -1 if token was NONE or no + * Token could be found. */ private int recursiveEmitLine(final StringBuilder out, final String in, int start, MarkToken token) { @@ -485,7 +510,9 @@ class Emitter while(pos < in.length()) { final MarkToken mt = this.getToken(in, pos); - if(token != MarkToken.NONE && (mt == token || token == MarkToken.EM_STAR && mt == MarkToken.STRONG_STAR || token == MarkToken.EM_UNDERSCORE && mt == MarkToken.STRONG_UNDERSCORE)) + if(token != MarkToken.NONE + && (mt == token || token == MarkToken.EM_STAR && mt == MarkToken.STRONG_STAR || token == MarkToken.EM_UNDERSCORE + && mt == MarkToken.STRONG_UNDERSCORE)) return pos; switch(mt) @@ -666,14 +693,16 @@ class Emitter /** * Check if there is any markdown Token. * - * @param in Input String. - * @param pos Starting position. + * @param in + * Input String. + * @param pos + * Starting position. * @return The Token. */ private MarkToken getToken(final String in, final int pos) { final char c0 = pos > 0 ? in.charAt(pos - 1) : ' '; - final char c = in.charAt(pos); + final char c = in.charAt(pos); final char c1 = pos + 1 < in.length() ? in.charAt(pos + 1) : ' '; final char c2 = pos + 2 < in.length() ? in.charAt(pos + 2) : ' '; final char c3 = pos + 3 < in.length() ? in.charAt(pos + 3) : ' '; @@ -785,8 +814,10 @@ class Emitter /** * Writes a set of markdown lines into the StringBuilder. * - * @param out The StringBuilder to write to. - * @param lines The lines to write. + * @param out + * The StringBuilder to write to. + * @param lines + * The lines to write. */ private void emitMarkedLines(final StringBuilder out, final Line lines) { @@ -811,8 +842,10 @@ class Emitter /** * Writes a set of raw lines into the StringBuilder. * - * @param out The StringBuilder to write to. - * @param lines The lines to write. + * @param out + * The StringBuilder to write to. + * @param lines + * The lines to write. */ private void emitRawLines(final StringBuilder out, final Line lines) { @@ -869,9 +902,12 @@ class Emitter /** * Writes a code block into the StringBuilder. * - * @param out The StringBuilder to write to. - * @param lines The lines to write. - * @param meta Meta information. + * @param out + * The StringBuilder to write to. + * @param lines + * The lines to write. + * @param meta + * Meta information. */ private void emitCodeLines(final StringBuilder out, final Line lines, final String meta, final boolean removeIndent) { diff --git a/src/main/java/com/github/rjeschke/txtmark/LinkRef.java b/src/main/java/com/github/rjeschke/txtmark/LinkRef.java index 5c702c8..aea77b6 100644 --- a/src/main/java/com/github/rjeschke/txtmark/LinkRef.java +++ b/src/main/java/com/github/rjeschke/txtmark/LinkRef.java @@ -32,8 +32,10 @@ class LinkRef /** * Constructor. * - * @param link The link. - * @param title The title (may be null). + * @param link + * The link. + * @param title + * The title (may be null). */ public LinkRef(final String link, final String title, final boolean isAbbrev) { diff --git a/src/main/java/com/github/rjeschke/txtmark/Processor.java b/src/main/java/com/github/rjeschke/txtmark/Processor.java index 56a9c8d..64fb34b 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Processor.java +++ b/src/main/java/com/github/rjeschke/txtmark/Processor.java @@ -269,7 +269,8 @@ public class Processor * if an IO error occurs * @see Configuration#DEFAULT */ - public final static String process(final File file, final Decorator decorator, final boolean safeMode) throws IOException + public final static String process(final File file, final Decorator decorator, final boolean safeMode) + throws IOException { return process(file, Configuration.builder().setDecorator(decorator).setSafeMode(safeMode).build()); } @@ -305,7 +306,8 @@ public class Processor * if an IO error occurs * @see Configuration#DEFAULT */ - public final static String process(final File file, final String encoding, final boolean safeMode) throws IOException + public final static String process(final File file, final String encoding, final boolean safeMode) + throws IOException { return process(file, Configuration.builder().setEncoding(encoding).setSafeMode(safeMode).build()); } @@ -324,7 +326,8 @@ public class Processor * if an IO error occurs * @see Configuration#DEFAULT */ - public final static String process(final File file, final String encoding, final Decorator decorator) throws IOException + public final static String process(final File file, final String encoding, final Decorator decorator) + throws IOException { return process(file, Configuration.builder().setEncoding(encoding).setDecorator(decorator).build()); } @@ -869,7 +872,8 @@ public class Processor { if(line.getLineType(this.useExtensions) == LineType.FENCED_CODE) break; - // TODO ... is this really necessary? Maybe add a special flag? + // TODO ... is this really necessary? Maybe add a special + // flag? line = line.next; } if(line != null) diff --git a/src/main/java/com/github/rjeschke/txtmark/Run.java b/src/main/java/com/github/rjeschke/txtmark/Run.java index 63f2ce6..0724273 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Run.java +++ b/src/main/java/com/github/rjeschke/txtmark/Run.java @@ -24,30 +24,41 @@ import java.io.InputStreamReader; /** * Simple class for processing markdown files on the command line. * - *

Usage:

- *
java -cp txtmark.jar txtmark.Run filename [header_footer_file]
- * 
+ *

+ * Usage: + *

* - *

The header_footer_file is an optional UTF-8 encoded file containing - * a header and a footer to output around the generated HTML code.

+ *
+ * java -cp txtmark.jar txtmark.Run filename [header_footer_file]
+ * 
+ * 
* - *

Example:

+ *

+ * The header_footer_file is an optional UTF-8 encoded file + * containing a header and a footer to output around the generated HTML code. + *

* - *
<?xml version="1.0" encoding="UTF-8"?>
- *<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- *                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- *<html xmlns="http://www.w3.org/1999/xhtml">
- *<head>
- *<title>markdown</title>
- *<link type="text/css" href="style.css" rel="stylesheet"/>
- *<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
- *</head>
- *<body>
- *<!-- the following line separates header from footer -->
- *<!-- ### -->
- *</body>
- *</html>
- *
+ *

+ * Example: + *

+ * + *
+ * <?xml version="1.0" encoding="UTF-8"?>
+ * <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ *                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+ * <html xmlns="http://www.w3.org/1999/xhtml">
+ * <head>
+ * <title>markdown</title>
+ * <link type="text/css" href="style.css" rel="stylesheet"/>
+ * <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
+ * </head>
+ * <body>
+ * <!-- the following line separates header from footer -->
+ * <!-- ### -->
+ * </body>
+ * </html>
+ * 
+ * 
* * @author René Jeschke */ @@ -56,8 +67,10 @@ public class Run /** * Static main. * - * @param args Program arguments. - * @throws IOException If an IO error occurred. + * @param args + * Program arguments. + * @throws IOException + * If an IO error occurred. */ public static void main(String[] args) throws IOException { diff --git a/src/main/java/com/github/rjeschke/txtmark/SpanEmitter.java b/src/main/java/com/github/rjeschke/txtmark/SpanEmitter.java index 0ecbae4..3acd428 100644 --- a/src/main/java/com/github/rjeschke/txtmark/SpanEmitter.java +++ b/src/main/java/com/github/rjeschke/txtmark/SpanEmitter.java @@ -16,18 +16,20 @@ package com.github.rjeschke.txtmark; /** - * An interface for emitting span elements. Currently only - * used for special links. + * An interface for emitting span elements. Currently only used for special + * links. * * @author René Jeschke (rene_jeschke@yahoo.de) */ public interface SpanEmitter { /** - * Emits a span element. + * Emits a span element. * - * @param out The StringBuilder to append to. - * @param content The span's content. + * @param out + * The StringBuilder to append to. + * @param content + * The span's content. */ public void emitSpan(StringBuilder out, String content); } diff --git a/src/main/java/com/github/rjeschke/txtmark/Utils.java b/src/main/java/com/github/rjeschke/txtmark/Utils.java index 6c9b027..32a800b 100644 --- a/src/main/java/com/github/rjeschke/txtmark/Utils.java +++ b/src/main/java/com/github/rjeschke/txtmark/Utils.java @@ -24,7 +24,7 @@ class Utils { /** Random number generator value. */ private static int RND = (int)System.nanoTime(); - + /** * LCG random number generator. * @@ -34,12 +34,14 @@ class Utils { return (RND = RND * 1664525 + 1013904223) >>> 22; } - + /** * Skips spaces in the given String. * - * @param in Input String. - * @param start Starting position. + * @param in + * Input String. + * @param start + * Starting position. * @return The new position or -1 if EOL has been reached. */ public final static int skipSpaces(final String in, final int start) @@ -53,9 +55,12 @@ class Utils /** * Processed the given escape sequence. * - * @param out The StringBuilder to write to. - * @param ch The character. - * @param pos Current parsing position. + * @param out + * The StringBuilder to write to. + * @param ch + * The character. + * @param pos + * Current parsing position. * @return The new position. */ public final static int escape(final StringBuilder out, final char ch, final int pos) @@ -89,14 +94,18 @@ class Utils return pos; } } - + /** * Reads characters until any 'end' character is encountered. * - * @param out The StringBuilder to write to. - * @param in The Input String. - * @param start Starting position. - * @param end End characters. + * @param out + * The StringBuilder to write to. + * @param in + * The Input String. + * @param start + * Starting position. + * @param end + * End characters. * @return The new position or -1 if no 'end' char was found. */ public final static int readUntil(final StringBuilder out, final String in, final int start, final char... end) @@ -133,10 +142,14 @@ class Utils /** * Reads characters until the 'end' character is encountered. * - * @param out The StringBuilder to write to. - * @param in The Input String. - * @param start Starting position. - * @param end End characters. + * @param out + * The StringBuilder to write to. + * @param in + * The Input String. + * @param start + * Starting position. + * @param end + * End characters. * @return The new position or -1 if no 'end' char was found. */ public final static int readUntil(final StringBuilder out, final String in, final int start, final char end) @@ -164,9 +177,12 @@ class Utils /** * Reads a markdown link. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Starting position. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Starting position. * @return The new position or -1 if this is no valid markdown link. */ public final static int readMdLink(final StringBuilder out, final String in, final int start) @@ -211,9 +227,12 @@ class Utils /** * Reads a markdown link ID. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Starting position. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Starting position. * @return The new position or -1 if this is no valid markdown link ID. */ public final static int readMdLinkId(final StringBuilder out, final String in, final int start) @@ -253,12 +272,17 @@ class Utils } /** - * Reads characters until any 'end' character is encountered, ignoring escape sequences. + * Reads characters until any 'end' character is encountered, ignoring + * escape sequences. * - * @param out The StringBuilder to write to. - * @param in The Input String. - * @param start Starting position. - * @param end End characters. + * @param out + * The StringBuilder to write to. + * @param in + * The Input String. + * @param start + * Starting position. + * @param end + * End characters. * @return The new position or -1 if no 'end' char was found. */ public final static int readRawUntil(final StringBuilder out, final String in, final int start, final char... end) @@ -286,12 +310,17 @@ class Utils } /** - * Reads characters until the end character is encountered, ignoring escape sequences. + * Reads characters until the end character is encountered, ignoring escape + * sequences. * - * @param out The StringBuilder to write to. - * @param in The Input String. - * @param start Starting position. - * @param end End characters. + * @param out + * The StringBuilder to write to. + * @param in + * The Input String. + * @param start + * Starting position. + * @param end + * End characters. * @return The new position or -1 if no 'end' char was found. */ public final static int readRawUntil(final StringBuilder out, final String in, final int start, final char end) @@ -312,10 +341,14 @@ class Utils /** * Appends the given string encoding special HTML characters. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Input String starting position. - * @param end Input String end position. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Input String starting position. + * @param end + * Input String end position. */ public final static void appendCode(final StringBuilder out, final String in, final int start, final int end) { @@ -341,12 +374,17 @@ class Utils } /** - * Appends the given string encoding special HTML characters (used in HTML attribute values). + * Appends the given string encoding special HTML characters (used in HTML + * attribute values). * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Input String starting position. - * @param end Input String end position. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Input String starting position. + * @param end + * Input String end position. */ public final static void appendValue(final StringBuilder out, final String in, final int start, final int end) { @@ -380,8 +418,10 @@ class Utils /** * Append the given char as a decimal HTML entity. * - * @param out The StringBuilder to write to. - * @param value The character. + * @param out + * The StringBuilder to write to. + * @param value + * The character. */ public final static void appendDecEntity(final StringBuilder out, final char value) { @@ -389,12 +429,14 @@ class Utils out.append((int)value); out.append(';'); } - + /** * Append the given char as a hexadecimal HTML entity. * - * @param out The StringBuilder to write to. - * @param value The character. + * @param out + * The StringBuilder to write to. + * @param value + * The character. */ public final static void appendHexEntity(final StringBuilder out, final char value) { @@ -406,10 +448,14 @@ class Utils /** * Appends the given mailto link using obfuscation. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Input String starting position. - * @param end Input String end position. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Input String starting position. + * @param end + * Input String end position. */ public final static void appendMailto(final StringBuilder out, final String in, final int start, final int end) { @@ -441,12 +487,14 @@ class Utils } } } - + /** * Extracts the tag from an XML element. * - * @param out The StringBuilder to write to. - * @param in Input StringBuilder. + * @param out + * The StringBuilder to write to. + * @param in + * Input StringBuilder. */ public final static void getXMLTag(final StringBuilder out, final StringBuilder in) { @@ -458,12 +506,14 @@ class Utils out.append(in.charAt(pos++)); } } - + /** * Extracts the tag from an XML element. * - * @param out The StringBuilder to write to. - * @param in Input String. + * @param out + * The StringBuilder to write to. + * @param in + * Input String. */ public final static void getXMLTag(final StringBuilder out, final String in) { @@ -479,80 +529,92 @@ class Utils /** * Reads an XML element. * - * @param out The StringBuilder to write to. - * @param in Input String. - * @param start Starting position. - * @param safeMode Whether to escape unsafe HTML tags or not + * @param out + * The StringBuilder to write to. + * @param in + * Input String. + * @param start + * Starting position. + * @param safeMode + * Whether to escape unsafe HTML tags or not * @return The new position or -1 if this is no valid XML element. */ public final static int readXML(final StringBuilder out, final String in, final int start, final boolean safeMode) { int pos; final boolean isCloseTag; - try { + try + { if(in.charAt(start + 1) == '/') - { - isCloseTag = true; - pos = start + 2; - } - else if(in.charAt(start + 1) == '!') - { - out.append("'); - if(pos == -1) return -1; - final String tag = temp.toString().trim().toLowerCase(); - if(HTML.isUnsafeHtmlElement(tag)) - { - out.append("<"); - if(isCloseTag) - out.append('/'); - out.append(temp); - } - } - else - { - out.append('<'); - if(isCloseTag) - out.append('/'); - pos = readRawUntil(out, in, pos, ' ', '/', '>'); - } - if(pos == -1) return -1; - pos = readRawUntil(out, in, pos, '/', '>'); - if(in.charAt(pos) == '/') - { - out.append(" /"); - pos = readRawUntil(out, in, pos + 1, '>'); - if(pos == -1) - return -1; - } - if(in.charAt(pos) == '>') - { - out.append('>'); - return pos; - } - } catch (StringIndexOutOfBoundsException e) { + { + isCloseTag = true; + pos = start + 2; + } + else if(in.charAt(start + 1) == '!') + { + out.append("'); + if(pos == -1) + return -1; + final String tag = temp.toString().trim().toLowerCase(); + if(HTML.isUnsafeHtmlElement(tag)) + { + out.append("<"); + if(isCloseTag) + out.append('/'); + out.append(temp); + } + } + else + { + out.append('<'); + if(isCloseTag) + out.append('/'); + pos = readRawUntil(out, in, pos, ' ', '/', '>'); + } + if(pos == -1) + return -1; + pos = readRawUntil(out, in, pos, '/', '>'); + if(in.charAt(pos) == '/') + { + out.append(" /"); + pos = readRawUntil(out, in, pos + 1, '>'); + if(pos == -1) + return -1; + } + if(in.charAt(pos) == '>') + { + out.append('>'); + return pos; + } + } + catch (StringIndexOutOfBoundsException e) + { return -1; } return -1; } - + /** - * Appends the given string to the given StringBuilder, replacing - * '&', '<' and '>' by their respective HTML entities. + * Appends the given string to the given StringBuilder, replacing '&', + * '<' and '>' by their respective HTML entities. * - * @param out The StringBuilder to append to. - * @param value The string to append. - * @param offset The character offset into value from where to start + * @param out + * The StringBuilder to append to. + * @param value + * The string to append. + * @param offset + * The character offset into value from where to start */ public final static void codeEncode(StringBuilder out, String value, int offset) { @@ -575,11 +637,12 @@ class Utils } } } - + /** * Removes trailing ` and trims spaces. * - * @param fenceLine Fenced code block starting line + * @param fenceLine + * Fenced code block starting line * @return Rest of the line after trimming and backtick removal * @since 0.7 */