Skip to content

Commit 9027c48

Browse files
committed
0.1.8 - added support for hardBreak output type
1 parent 3c077c5 commit 9027c48

File tree

12 files changed

+273
-106
lines changed

12 files changed

+273
-106
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
./target
2+
./pkg
3+
./test_cases
4+
./tmp
5+
./releases
16
/target
27
/pkg
38
/test_cases
49
/tmp
5-
.DS_Store
10+
/releases
11+
.DS_Store
12+
.git

.targets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
aarch64-apple-darwin
2+
aarch64-unknown-linux-gnu
3+
aarch64-unknown-linux-musl
4+
i686-unknown-linux-gnu
5+
x86_64-apple-darwin
6+
x86_64-pc-windows-gnu
7+
x86_64-pc-windows-msvc
8+
x86_64-unknown-linux-gnu

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "htmltoadf"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
edition = "2021"
55
license = "MIT"
66
description = "An HTML to Atlassian Document Format (ADF) converter"

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $ html2adf -h
3838
```
3939

4040
```
41-
htmltoadf 0.1.7
41+
htmltoadf 0.1.8
4242
An HTML to Atlassian Document Format (ADF) converter
4343
4444
USAGE:
@@ -56,20 +56,20 @@ OPTIONS:
5656
### Install Binary from Crates.io with `cargo install`
5757
```
5858
$ cargo install htmltoadf
59-
installing htmltoadf v0.1.7 (/usr/src/html2adf)
59+
installing htmltoadf v0.1.8 (/usr/src/html2adf)
6060
Updating crates.io index
6161
Downloading crates ...
6262
Downloaded lock_api v0.4.6
6363
--snip--
64-
Compiling htmltoadf v0.1.7
64+
Compiling htmltoadf v0.1.8
6565
Finished release [optimized] target(s) in 1m 42s
6666
Installing ~/.cargo/bin/htmltoadf
67-
Installed package `htmltoadf v0.1.7` (executable `html2adf`)
67+
Installed package `htmltoadf v0.1.8` (executable `html2adf`)
6868
```
6969

7070
### Download Binary file from Github
7171
Pre-built binaries can be downloaded from here:
72-
https://github.com/wouterken/htmltoadf/releases/tag/0.1.7
72+
https://github.com/wouterken/htmltoadf/releases/tag/0.1.8
7373

7474
### Docker Image
7575
**Docker Repo:**
@@ -79,10 +79,10 @@ https://hub.docker.com/r/wouterken/html2adf
7979
**Usage**
8080

8181
```bash
82-
$ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf:0.1.7
82+
$ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf:0.1.8
8383
{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Hello world"},{"type":"text","text":"Test"}]}]}
8484

85-
$ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf:0.1.7 | jq
85+
$ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf:0.1.8 | jq
8686
{
8787
"version": 1,
8888
"type": "doc",
@@ -115,7 +115,7 @@ $ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf
115115

116116
```toml
117117
[dependencies]
118-
htmltoadf = "0.1.7"
118+
htmltoadf = "0.1.8"
119119
```
120120

121121
**Code**

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
</style>
8181
<script defer type="module">
82-
import init, {convert} from "https://unpkg.com/[email protected].7/htmltoadf.js";
82+
import init, {convert} from "https://unpkg.com/[email protected].8/htmltoadf.js";
8383

8484
let editor;
8585

release.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e
4+
# Ask for RELEASE_NAME
5+
read -p "Enter RELEASE_NAME: " RELEASE_NAME
6+
7+
# Create releases directory if it doesn't exist
8+
mkdir -p "releases/${RELEASE_NAME}"
9+
10+
# Read targets from .targets file and build
11+
if [ -f .targets ]; then
12+
cat .targets | xargs -I {} cargo zigbuild --target {} --release -Z unstable-options --out-dir="./releases/${RELEASE_NAME}/{}" || true
13+
echo "Build completed. Output files are in releases/${RELEASE_NAME}/ directory."
14+
15+
# Create tar.gz archive excluding files specified in .gitignore
16+
git archive --format=tar.gz --output="releases/${RELEASE_NAME}/src.tar.gz" HEAD
17+
18+
# Create zip archive excluding files specified in .gitignore
19+
git archive --format=zip --output="releases/${RELEASE_NAME}/src.zip" HEAD
20+
21+
echo "Tar.gz and Zip archives created in releases/${RELEASE_NAME}/ directory."
22+
else
23+
echo ".targets file not found."
24+
fi

src/adf_builder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use scraper::ElementRef;
1111
use scraper::Html;
1212
use serde_json::{Map, Value};
1313

14-
static VALID_EMPTY_TYPES: [&str; 3] = ["hr", "iframe", "img"];
14+
static VALID_EMPTY_TYPES: [&str; 4] = ["hr", "iframe", "img", "br"];
1515

1616
/**
1717
* The main procedure for our ADF Builder.
@@ -130,6 +130,15 @@ fn build_adf_doc(leaf_nodes: Vec<DocNode>) -> NodeList {
130130
vec![],
131131
);
132132
}
133+
"br" => {
134+
node_list.push_anon(
135+
insertion_point,
136+
content_type.typename.to_string(),
137+
"".to_string(),
138+
&[],
139+
vec![],
140+
);
141+
}
133142
"p" => {
134143
let paragraph_handle = node_list.push_anon(
135144
insertion_point,

src/adf_structure.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ lazy_static! {
1818
pub static ref LEGAL_CHILD_TYPES: HashMap<String, AdfPermittedChildren> = HashMap::from([
1919
(
2020
String::from("paragraph"),
21-
AdfPermittedChildren::any(&["text", "emoji"])
21+
AdfPermittedChildren::any(&["text", "emoji", "hardBreak"])
2222
),
2323
(
2424
String::from("heading"),
25-
AdfPermittedChildren::any(&["text", "emoji"])
25+
AdfPermittedChildren::any(&["text", "emoji", "hardBreak"])
2626
),
2727
(
2828
String::from("bulletList"),
@@ -103,6 +103,10 @@ lazy_static! {
103103
"hr",
104104
AdfContentType::from_name("rule")
105105
),
106+
(
107+
"br",
108+
AdfContentType::from_name("hardBreak")
109+
),
106110
(
107111
"html",
108112
AdfContentType::from_name("doc")

src/extractor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ pub fn extract_leaves(fragment: &Html) -> Vec<DocNode> {
5757
text: "".trim().to_owned(),
5858
node,
5959
})
60+
} else if element.value().name() == "br" {
61+
leaf_nodes.push(DocNode {
62+
name: "br",
63+
text: "".trim().to_owned(),
64+
node,
65+
})
6066
}
6167
} else if let Node::Text(text_node) = node.value() {
6268
if let Some(parent) = node.parent().and_then(ElementRef::wrap) {

0 commit comments

Comments
 (0)