# Quick Reference: Bootstrap Functions

## Add Bootstrap to HTML

```rust
use herolib_web::html;

let html = "<html><head></head><body><h1>Hello</h1></body></html>";
let with_bootstrap = html::add_bootstrap(html);
```

**What happens:**
- Removes any existing Bootstrap (all versions)
- Injects Bootstrap 5.3.8 CSS in `<head>`
- Injects Bootstrap 5.3.8 JS before `</body>`
- Handles incomplete HTML gracefully

## Remove Bootstrap from HTML

```rust
use herolib_web::html;

let clean_html = html::remove_bootstrap(html_with_bootstrap);
```

**What happens:**
- Removes all Bootstrap CSS links (any version)
- Removes all Bootstrap JS scripts (any version)
- Preserves all other content

## Upgrade Bootstrap Version

```rust
use herolib_web::html;

// HTML with old Bootstrap
let old = r#"<html>
<head>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    Content here
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>"#;

// Upgrade to Bootstrap 5.3.8
let upgraded = html::add_bootstrap(old);
```

## Build HTML with Bootstrap

```rust
use herolib_web::html;

let content = html::HtmlBuilder::new()
    .add_tag("h1", "Title", &[("class", "mb-4")])
    .add_tag("p", "Content", &[("class", "lead")])
    .build();

let full_html = format!(
    "<html><head></head><body>{}</body></html>",
    content
);

let with_bootstrap = html::add_bootstrap(&full_html);
```

## Bootstrap CDN Details

**Version:** 5.3.8

**CSS:**
```html
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" 
      rel="stylesheet" 
      integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" 
      crossorigin="anonymous">
```

**JavaScript:**
```html
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" 
        integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" 
        crossorigin="anonymous"></script>
```

## Key Features

✓ **Idempotent** - Multiple calls produce same result
✓ **Smart** - Removes old versions before adding new ones
✓ **Graceful** - Handles incomplete HTML structures
✓ **Secure** - Uses SRI (Subresource Integrity) hashes
✓ **Fast** - Uses compiled regex patterns with caching

## Common Patterns

### Pattern 1: Generate Bootstrap Page
```rust
let html = html::add_bootstrap("<html><head></head><body>Content</body></html>");
```

### Pattern 2: Upgrade Existing Page
```rust
let old_html = std::fs::read_to_string("index.html")?;
let upgraded = html::add_bootstrap(&old_html);
std::fs::write("index.html", upgraded)?;
```

### Pattern 3: Process Without Bootstrap
```rust
let no_bootstrap = html::remove_bootstrap(&page);
let result = process_page(&no_bootstrap);
```
