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 ๐จโจ
- Host: GitHub
- URL: https://github.com/1amageek/remark
- Owner: 1amageek
- Created: 2024-10-29T11:26:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-22T11:07:28.000Z (12 months ago)
- Last Synced: 2025-01-22T12:22:02.863Z (12 months ago)
- Topics: front-matter, html, markdown, ogp, swift
- Language: Swift
- Homepage: https://github.com/1amageek/Remark
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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. โจ