| Crates.io | html_transpose |
| lib.rs | html_transpose |
| version | 0.1.1 |
| created_at | 2026-01-20 09:48:30.848847+00 |
| updated_at | 2026-01-21 10:14:18.311956+00 |
| description | html table transpose library |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2056248 |
| size | 42,968 |
A Rust library for transposing HTML tables while preserving merged cells, attributes, and structure.
html_transpose is a lightweight Rust library that transposes HTML tables (swaps rows and columns) while correctly handling:
rowspan and colspan)When a table is transposed, rowspan and colspan attributes are automatically swapped to maintain the correct visual structure.
rowspan and colspan attributesAdd this to your Cargo.toml:
[dependencies]
html_transpose = "0.1.0"
scraper = "0.25.0"
use html_transpose::transpose;
let html_table = r#"
<table>
<tr><td>A</td><td>B</td></tr>
<tr><td>C</td><td>D</td></tr>
</table>
"#;
match transpose(html_table) {
Ok(transposed) => println!("{}", transposed),
Err(e) => eprintln!("Error: {}", e),
}
transpose(html: &str) -> Result<String, String>Transposes an HTML table string.
Parameters:
html: A string containing an HTML table (must contain a <table> element)Returns:
Ok(String): The transposed HTML table as a stringErr(String): An error message if the input is invalidErrors:
<table> element is found in the inputRun the test suite:
cargo test
The library includes comprehensive tests covering:
rowspan and colspanThe library works by:
scraper crate to parse HTMLrowspan ↔ colspan appropriatelyscraper: HTML parsing and CSS selector supportThis project is available for use under your preferred license.
Contributions are welcome! Please feel free to submit a Pull Request.