Skip to content

Commit

Permalink
add more helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jan 6, 2020
1 parent ef385b0 commit 47f157f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/ch/digitalfondue/jfiveparse/JFiveParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,41 @@
import java.io.Reader;
import java.io.Writer;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

/**
* Expose convenient static methods for parsing String or Reader as Html document and serializing nodes back to String.
*/
public class JFiveParse {

/**
* Parse a full html document with the default options.
*
* @param input
* @return a {@link Document}
*/
public static Document parse(String input) {
return parse(input, EnumSet.noneOf(Option.class));
}

/**
* Parse a full html document with the given options
*
* @param input
* @param options
* @return a {@link Document}
*/
public static Document parse(String input, Set<Option> options) {
return new Parser(options).parse(input);
}

/**
* Parse a full html document using a {@link Reader} as a input with the default options.
*
* @param input
* @return
*/
public static Document parse(Reader input) {
return parse(input, EnumSet.noneOf(Option.class));
}
Expand All @@ -42,6 +62,31 @@ public static Document parse(Reader input, Set<Option> options) {
return new Parser(options).parse(input);
}

/**
* Parse a html fragment, with a "div" element as a parent node.
*
* @param input
* @return
*/
public static List<Node> parseFragment(String input) {
return parseFragment(input, EnumSet.noneOf(Option.class));
}

/**
* Parse a html fragment, with a "div" element as a parent node.
*
* @param input
* @param options
* @return
*/
public static List<Node> parseFragment(String input, Set<Option> options) {
return parseFragment(new Element("div", Node.NAMESPACE_HTML), input, options);
}

public static List<Node> parseFragment(Element parent, String input, Set<Option> options) {
return new Parser(options).parseFragment(parent, input);
}

public static String serialize(Node node) {
return serialize(node, EnumSet.noneOf(Option.class));
}
Expand Down

0 comments on commit 47f157f

Please sign in to comment.