Skip to content

Commit

Permalink
0.1.8 - added support for hardBreak output type
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterken committed Oct 10, 2023
1 parent 3c077c5 commit 9027c48
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 106 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
./target
./pkg
./test_cases
./tmp
./releases
/target
/pkg
/test_cases
/tmp
.DS_Store
/releases
.DS_Store
.git
8 changes: 8 additions & 0 deletions .targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
aarch64-apple-darwin
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
i686-unknown-linux-gnu
x86_64-apple-darwin
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
x86_64-unknown-linux-gnu
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "htmltoadf"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
license = "MIT"
description = "An HTML to Atlassian Document Format (ADF) converter"
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ html2adf -h
```

```
htmltoadf 0.1.7
htmltoadf 0.1.8
An HTML to Atlassian Document Format (ADF) converter
USAGE:
Expand All @@ -56,20 +56,20 @@ OPTIONS:
### Install Binary from Crates.io with `cargo install`
```
$ cargo install htmltoadf
installing htmltoadf v0.1.7 (/usr/src/html2adf)
installing htmltoadf v0.1.8 (/usr/src/html2adf)
Updating crates.io index
Downloading crates ...
Downloaded lock_api v0.4.6
--snip--
Compiling htmltoadf v0.1.7
Compiling htmltoadf v0.1.8
Finished release [optimized] target(s) in 1m 42s
Installing ~/.cargo/bin/htmltoadf
Installed package `htmltoadf v0.1.7` (executable `html2adf`)
Installed package `htmltoadf v0.1.8` (executable `html2adf`)
```

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

### Docker Image
**Docker Repo:**
Expand All @@ -79,10 +79,10 @@ https://hub.docker.com/r/wouterken/html2adf
**Usage**

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

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

```toml
[dependencies]
htmltoadf = "0.1.7"
htmltoadf = "0.1.8"
```

**Code**
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

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

let editor;

Expand Down
24 changes: 24 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e
# Ask for RELEASE_NAME
read -p "Enter RELEASE_NAME: " RELEASE_NAME

# Create releases directory if it doesn't exist
mkdir -p "releases/${RELEASE_NAME}"

# Read targets from .targets file and build
if [ -f .targets ]; then
cat .targets | xargs -I {} cargo zigbuild --target {} --release -Z unstable-options --out-dir="./releases/${RELEASE_NAME}/{}" || true
echo "Build completed. Output files are in releases/${RELEASE_NAME}/ directory."

# Create tar.gz archive excluding files specified in .gitignore
git archive --format=tar.gz --output="releases/${RELEASE_NAME}/src.tar.gz" HEAD

# Create zip archive excluding files specified in .gitignore
git archive --format=zip --output="releases/${RELEASE_NAME}/src.zip" HEAD

echo "Tar.gz and Zip archives created in releases/${RELEASE_NAME}/ directory."
else
echo ".targets file not found."
fi
11 changes: 10 additions & 1 deletion src/adf_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use scraper::ElementRef;
use scraper::Html;
use serde_json::{Map, Value};

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

/**
* The main procedure for our ADF Builder.
Expand Down Expand Up @@ -130,6 +130,15 @@ fn build_adf_doc(leaf_nodes: Vec<DocNode>) -> NodeList {
vec![],
);
}
"br" => {
node_list.push_anon(
insertion_point,
content_type.typename.to_string(),
"".to_string(),
&[],
vec![],
);
}
"p" => {
let paragraph_handle = node_list.push_anon(
insertion_point,
Expand Down
8 changes: 6 additions & 2 deletions src/adf_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ lazy_static! {
pub static ref LEGAL_CHILD_TYPES: HashMap<String, AdfPermittedChildren> = HashMap::from([
(
String::from("paragraph"),
AdfPermittedChildren::any(&["text", "emoji"])
AdfPermittedChildren::any(&["text", "emoji", "hardBreak"])
),
(
String::from("heading"),
AdfPermittedChildren::any(&["text", "emoji"])
AdfPermittedChildren::any(&["text", "emoji", "hardBreak"])
),
(
String::from("bulletList"),
Expand Down Expand Up @@ -103,6 +103,10 @@ lazy_static! {
"hr",
AdfContentType::from_name("rule")
),
(
"br",
AdfContentType::from_name("hardBreak")
),
(
"html",
AdfContentType::from_name("doc")
Expand Down
6 changes: 6 additions & 0 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ pub fn extract_leaves(fragment: &Html) -> Vec<DocNode> {
text: "".trim().to_owned(),
node,
})
} else if element.value().name() == "br" {
leaf_nodes.push(DocNode {
name: "br",
text: "".trim().to_owned(),
node,
})
}
} else if let Node::Text(text_node) = node.value() {
if let Some(parent) = node.parent().and_then(ElementRef::wrap) {
Expand Down
Loading

0 comments on commit 9027c48

Please sign in to comment.