public class Remark extends Object
It is recommended that you save this class if it is going to be reused for better performance. This class is thread-safe, but can only process a single document concurrently.
Usage:
Basic usage involves instantiating this class with a specific set of options, and calling one of the
convert*
methods on some form of input.
Examples:
// Create a generic remark that converts to pure-Markdown spec. Remark remark = new Remark(); String cleanedUp = remark.convertFragment(inputString); // Create a remark that converts to pegdown with all extensions enabled. Remark pegdownAll = new Remark(Options.pegdownAllExtensions()); cleanedUp = pegdownAll.convert(new URL("http://www.example.com"), 15000); // stream the conversion pegdownAll.withStream(System.out).convert(new URL("http://www.overzealous.com"), 15000);
Constructor and Description |
---|
Remark()
Creates a default, pure Markdown-compatible Remark instance.
|
Remark(Options options)
Creates a Remark instance with the specified options.
|
Modifier and Type | Method and Description |
---|---|
String |
convert(Document doc)
Converts an already-loaded JSoup Document to Markdown.
|
String |
convert(File file)
Converts an HTML file to Markdown.
|
String |
convert(File file,
String charset)
Converts an HTML file to Markdown.
|
String |
convert(File file,
String charset,
String baseUri)
Converts an HTML file to Markdown.
|
String |
convert(String html)
Converts HTML in memory to Markdown.
|
String |
convert(String html,
String baseUri)
Converts HTML in memory to Markdown.
|
String |
convert(URL url,
int timeoutMillis)
Converts an HTML document retrieved from a URL to Markdown.
|
String |
convertFragment(String body)
Converts an HTML body fragment to Markdown.
|
String |
convertFragment(String body,
String baseUri)
Converts an HTML body fragment to Markdown.
|
DocumentConverter |
getConverter()
Provides access to the DocumentConverter for customization.
|
boolean |
isCleanedHtmlEchoed()
Returns true if the cleaned HTML document is echoed to
System.out . |
void |
setCleanedHtmlEchoed(boolean cleanedHtmlEchoed)
To see the cleaned and processed HTML document, set this to true.
|
Remark |
withOutputStream(OutputStream os)
Use this method in a chain to handle streaming the output to an OutputStream.
|
Remark |
withWriter(Writer writer)
Use this method in a chain to handle streaming the output to a Writer.
|
public Remark()
public Remark(Options options)
options
- Specified options to use on this instance. See the docs for the Options class for common options sets.public DocumentConverter getConverter()
public boolean isCleanedHtmlEchoed()
System.out
.public void setCleanedHtmlEchoed(boolean cleanedHtmlEchoed)
System.out
for debugging purposes.cleanedHtmlEchoed
- true to echo out the cleaned HTML documentpublic Remark withWriter(Writer writer)
Note: The convert methods on the returned class will always return null
.
Note: It is up to the calling class to handle closing the writer!
Example:
new Remark(options).withWriter(myWiter).convert(htmlText);
writer
- Writer to receive the converted outputpublic Remark withOutputStream(OutputStream os)
Note: The convert methods on the returned class will always return null
.
Note: It is up to the calling class to handle closing the stream!
Example:
new Remark(options).withOutputStream(myOut).convert(htmlText);
os
- OutputStream to receive the converted outputpublic String convert(URL url, int timeoutMillis) throws IOException
url
- URL to connect to.timeoutMillis
- Maximum time to wait before giving up on the connection.IOException
- If an error occurs while retrieving the document.Jsoup.parse(URL, int)
public String convert(File file) throws IOException
file
- The file to load.IOException
- If an error occurs while loading the file.Jsoup.parse(File, String, String)
public String convert(File file, String charset) throws IOException
file
- The file to load.charset
- The charset of the file (if not specified and not UTF-8). Set to null
to determine from http-equiv
meta tag, if present, or fall back to UTF-8
(which is often safe to do).IOException
- If an error occurs while loading the file.Jsoup.parse(File, String, String)
public String convert(File file, String charset, String baseUri) throws IOException
file
- The file to load.charset
- The charset of the file (if not specified and not UTF-8). Set to null
to determine from http-equiv
meta tag, if present, or fall back to UTF-8
(which is often safe to do).baseUri
- The base URI for resolving relative links.IOException
- If an error occurs while loading the file.Jsoup.parse(File, String, String)
public String convert(String html)
html
- The string to processConvert from HTMLJsoup.parse(String, String)
public String convert(String html, String baseUri)
html
- The string to processConvert from HTMLbaseUri
- The base URI for resolving relative links.Jsoup.parse(String, String)
public String convertFragment(String body)
body
- The fragment string to processConvert from HTMLJsoup.parseBodyFragment(String, String)
public String convertFragment(String body, String baseUri)
body
- The fragment string to processConvert from HTMLbaseUri
- The base URI for resolving relative links.Jsoup.parseBodyFragment(String, String)
Copyright © 2017. All rights reserved.