Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/furstenheim/copy-down
Transform html to markdown
https://github.com/furstenheim/copy-down
Last synced: 21 days ago
JSON representation
Transform html to markdown
- Host: GitHub
- URL: https://github.com/furstenheim/copy-down
- Owner: furstenheim
- License: mit
- Created: 2020-05-30T11:42:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-03T14:01:14.000Z (over 1 year ago)
- Last Synced: 2024-05-01T14:19:14.531Z (9 months ago)
- Language: Java
- Size: 74.2 KB
- Stars: 50
- Watchers: 5
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Copy Down
Convert HTML into Markdown with Java.### Installation
Gradle:
```gradle
dependencies {
compile 'io.github.furstenheim:copy_down:1.1'
}
```Maven:
```xml
io.github.furstenheim
copy_down
1.1
```
### JSoup Compatibility
This library has a strong reliance on JSoup. Using a different version of it will lead to unexpected behaviours. Sadly, Java does not allow several versions of a library (unlike Node.js) so if your project is already using JSoup that version will have priority.
Supported versions are:
| This Library | Jsoup |
| ------------| --------|
| 1.0 | 1.13 |
| 1.1 | 1.15 |### Usage
```java
import io.github.furstenheim.CopyDown;
public class Main {
public static void main (String[] args) {
CopyDown converter = new CopyDown();
String myHtml = "Some title
Some html";Another paragraph
String markdown = converter.convert(myHtml);
System.out.println(markdown);
// Some title\n==========\n\nSome html\n\nAnother paragraph\n
}
}
```### Options
It is possible to use options for converting markdown:
```java
import io.github.furstenheim.CopyDown;
import io.github.furstenheim.Options;
import io.github.furstenheim.OptionsBuilder;public class Main {
public static void main (String[] args) {
OptionsBuilder optionsBuilder = OptionsBuilder.anOptions();
Options options = optionsBuilder
.withBr("-")
// more options
.build();
CopyDown converter = new CopyDown(options);
String myHtml = "Some title
Some html";Another paragraph
String markdown = converter.convert(myHtml);
System.out.println(markdown);
}
}
```| Option | Valid values | Default |
| :-------------------- | :------------ | :------ |
| `headingStyle` | `SETEXT` or `ATX` | `SETEXT` |
| `hr` | Any [Thematic break](http://spec.commonmark.org/0.27/#thematic-breaks) | `* * *` |
| `bulletListMarker` | `-`, `+`, or `*` | `*` |
| `codeBlockStyle` | `INDENTED` or `FENCED` | `INDENTED` |
| `fence` | ` ``` ` or `~~~` | ` ``` ` |
| `emDelimiter` | `_` or `*` | `_` |
| `strongDelimiter` | `**` or `__` | `**` |
| `linkStyle` | `INLINED` or `REFERENCED` | `INLINED` |
| `linkReferenceStyle` | `FULL`, `COLLAPSED`, or `SHORTCUT` | `FULL` |### Acknowledgment
This library is a port to Java of the wonderful library [Turndown.js](https://github.com/domchristie/turndown). This library passes the same test suite as the original library to ensure same behavior.