Skip to content

Prepare for initial release #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[package]
name = "string-auto-indent"
description = "Automatically (re)indent multi-line strings"
version = "0.1.0-alpha"
authors = ["Jeremy Harris <jeremy.harris@zenosmosis.com>"]
edition = "2021"
description = "Normalizes multi-line string indentation while preserving platform-specific line endings."
repository = "https://github.com/jzombie/rust-string-auto-indent"
license = "MIT"

[dependencies]
doc-comment = "0.3.3"
63 changes: 58 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Multi-line String Auto Indent

[![made-with-rust][rust-logo]][rust-src-page]
[![crates.io][crates-badge]][crates-page]
[![Documentation][docs-badge]][docs-page]
[![MIT licensed][license-badge]][license-page]


| OS | Status |
|---------------|--------------------------------------------------------------------------------------|
| Ubuntu-latest | [![Ubuntu Tests][ubuntu-latest-badge]][ubuntu-latest-workflow] |
| macOS-latest | [![macOS Tests][macos-latest-badge]][macos-latest-workflow] |
| Windows-latest| [![Windows Tests][windows-latest-badge]][windows-latest-workflow] |


A Rust utility for automatically normalizing multi-line string indentation while preserving platform-specific line endings.

## Overview
Expand All @@ -14,12 +27,11 @@ When working with multi-line strings inside indented code blocks, unwanted leadi
cargo install string-auto-indent
```

## Example
## Usage

```rust
use string_auto_indent::{auto_indent, LineEnding};

println!("");
let text = r#"
String Auto Indent

Expand All @@ -28,23 +40,46 @@ let text = r#"
Level 3
"#;

// For cross-platform testing
let line_ending = LineEnding::detect(text);

// With auto-indent
assert_eq!(
auto_indent(text),
// Restore platform-specific line endings for testing
// For cross-platform testing: Restore platform-specific line endings
line_ending.restore("String Auto Indent\n\nLevel 1\n Level 2\n Level 3\n")
);

// Without auto-indent
assert_eq!(
text,
// Restore platform-specific line endings for testing
// For cross-platform testing: Restore platform-specific line endings
line_ending.restore("\n String Auto Indent\n\n Level 1\n Level 2\n Level 3\n"),
);
```

### Example Output

**With `auto-indent` enabled.**

```text
String Auto Indent

Level 1
Level 2
Level 3
```

**With `auto-intent` disabled.**

```text
String Auto Indent

Level 1
Level 2
Level 3
```

## How It Works

1. Detects the platform’s line endings (`\n`, `\r\n`, `\r`) and normalizes input for processing.
Expand All @@ -62,5 +97,23 @@ assert_eq!(
## License
Licensed under **MIT**. See [`LICENSE`][license-page] for details.

[license-page]: https://github.com/jzombie/rust-cargo-pkg-info-struct-builder/blob/main/LICENSE
[rust-src-page]: https://www.rust-lang.org/
[rust-logo]: https://img.shields.io/badge/Made%20with-Rust-black?&logo=Rust

[crates-page]: https://crates.io/crates/string-auto-indent
[crates-badge]: https://img.shields.io/crates/v/string-auto-indent.svg

[docs-page]: https://docs.rs/string-auto-indent
[docs-badge]: https://docs.rs/string-auto-indent/badge.svg

[license-page]: https://github.com/jzombie/rust-string-auto-indent/blob/main/LICENSE
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg

[ubuntu-latest-badge]: https://github.com/jzombie/rust-string-auto-indent/actions/workflows/rust-tests.yml/badge.svg?branch=main&job=Run%20Rust%20Tests%20(OS%20=%20ubuntu-latest)
[ubuntu-latest-workflow]: https://github.com/jzombie/rust-string-auto-indent/actions/workflows/rust-tests.yml?query=branch%3Amain

[macos-latest-badge]: https://github.com/jzombie/rust-string-auto-indent/actions/workflows/rust-tests.yml/badge.svg?branch=main&job=Run%20Rust%20Tests%20(OS%20=%20macos-latest)
[macos-latest-workflow]: https://github.com/jzombie/rust-string-auto-indent/actions/workflows/rust-tests.yml?query=branch%3Amain

[windows-latest-badge]: https://github.com/jzombie/rust-string-auto-indent/actions/workflows/rust-tests.yml/badge.svg?branch=main&job=Run%20Rust%20Tests%20(OS%20=%20windows-latest)
[windows-latest-workflow]: https://github.com/jzombie/rust-string-auto-indent/actions/workflows/rust-tests.yml?query=branch%3Amain