An open API service indexing awesome lists of open source software.

https://github.com/1amageek/remark

Convert HTML to Markdown with OG metadata extraction and front matter generation ๐ŸŽจโœจ
https://github.com/1amageek/remark

front-matter html markdown ogp swift

Last synced: 10 months ago
JSON representation

Convert HTML to Markdown with OG metadata extraction and front matter generation ๐ŸŽจโœจ

Awesome Lists containing this project

README

          

# Remark ๐ŸŽจโœจ

Convert HTML to beautiful Markdown with ease! โœจ Remark is a Swift library and command-line tool designed to parse HTML content into Markdown, with support for extracting Open Graph (OG) metadata and front matter generation. Perfect for static site generators and Markdown-based applications! ๐Ÿš€

## โœจ Features

- ๐Ÿ“ **HTML to Markdown Conversion**: Convert HTML elements to clean, readable Markdown
- ๐ŸŒ **Open Graph (OG) Data Extraction**: Extract social media tags automatically
- ๐Ÿ“‹ **Front Matter Generation**: Generate front matter with title, description, and OG metadata
- ๐ŸŽฏ **Smart Indentation**: Perfect handling of nested lists and quotes
- ๐Ÿ”— **URL Resolution**: Automatically resolves relative URLs to absolute URLs
- ๐ŸŽจ **Intelligent Link Text**: Prioritizes accessibility with aria-label > img[alt] > title > text

## ๐Ÿš€ Installation

### ๐Ÿ“š As a Library (Swift Package Manager)

Add Remark to your `Package.swift`:

```swift
dependencies: [
.package(url: "https://github.com/1amageek/Remark.git", branch: "main")
]
```

### ๐Ÿ’ป As a Command Line Tool

#### ๐Ÿ›  Using Make (Recommended)

1. Clone the repo and move into it:
```bash
git clone https://github.com/1amageek/Remark.git
cd Remark
```

2. Install with make:
```bash
make install
```

Want a custom location? No problem! ๐ŸŽฏ
```bash
PREFIX=/your/custom/path make install
```

#### ๐Ÿ”ง Manual Installation

1. Clone the repo ๐Ÿ“ฆ
2. Build release version:
```bash
swift build -c release
```
3. Copy to your bin:
```bash
cp .build/release/RemarkCLI /usr/local/bin/remark
```

## ๐ŸŽฎ Usage

### ๐Ÿ–ฅ Command Line Interface

Convert HTML from any URL to Markdown: โœจ
```bash
remark https://example.com
```

Include the fancy front matter: ๐Ÿ“‹
```bash
remark --include-front-matter https://example.com
```

Just the plain text, please! ๐Ÿ“
```bash
remark --plain-text https://example.com
```

### ๐Ÿ“š Library Usage

Here's a quick example to get you started! ๐Ÿš€

```swift
import Remark

let htmlContent = """

My Amazing Page โœจ

Welcome! ๐ŸŽ‰


This is amazing content.

"""

do {
let remark = try Remark(htmlContent)
print("โœจ Title:", remark.title)
print("๐Ÿ“ Description:", remark.description)
print("๐ŸŒ OG Data:", remark.ogData)
print("๐Ÿ“„ Markdown:\n", remark.page)
} catch {
print("โŒ Error:", error)
}
```

### ๐ŸŽจ Example Output

Your HTML becomes beautiful Markdown:

```markdown
---
title: "My Amazing Page โœจ"
description: "Something awesome!"
og_image: "https://example.com/cool.jpg"
---

# Welcome! ๐ŸŽ‰

This is **amazing** content.
```

## ๐Ÿ›  Development

### ๐Ÿ— Building

```bash
make build # ๐Ÿš€ Release build
make debug # ๐Ÿ” Debug build
```

### ๐Ÿงช Testing

```bash
make test # ๐ŸŽฏ Run tests
```

### ๐Ÿงน Cleaning

```bash
make clean # ๐Ÿงน Clean build artifacts
```

### ๐Ÿ“ฆ Dependencies

```bash
make update # ๐Ÿ”„ Update all dependencies
make resolve # ๐ŸŽฏ Resolve dependencies
```

## ๐Ÿงช Tests

Here's an example test for OGP extraction:

```swift
import XCTest
@testable import Remark

final class RemarkTests: XCTestCase {
func testOGPDataExtraction() throws {
let htmlContent = """


"""

let remark = try Remark(htmlContent)
XCTAssertEqual(remark.ogData["og_image"], "https://example.com/cool.jpg")
XCTAssertEqual(remark.ogData["og_title"], "Amazing Page โœจ")
}
}
```

## ๐ŸŒŸ Contributing

Love Remark? Want to make it better? Contributions are welcome! ๐ŸŽ‰

1. ๐Ÿด Fork it
2. ๐Ÿ”จ Make your changes
3. ๐Ÿงช Test them
4. ๐ŸŽฏ Send a PR

## ๐Ÿ“ License

Remark is available under the MIT license. See the LICENSE file for more info. โœจ