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! ๐
- ๐ 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
Add Remark to your Package.swift
:
dependencies: [
.package(url: "/~https://github.com/1amageek/Remark.git", branch: "main")
]
- Clone the repo and move into it:
git clone /~https://github.com/1amageek/Remark.git
cd Remark
- Install with make:
make install
Want a custom location? No problem! ๐ฏ
PREFIX=/your/custom/path make install
- Clone the repo ๐ฆ
- Build release version:
swift build -c release
- Copy to your bin:
cp .build/release/RemarkCLI /usr/local/bin/remark
Convert HTML from any URL to Markdown: โจ
remark https://example.com
Include the fancy front matter: ๐
remark --include-front-matter https://example.com
Just the plain text, please! ๐
remark --plain-text https://example.com
Here's a quick example to get you started! ๐
import Remark
let htmlContent = """
<!DOCTYPE html>
<html>
<head>
<title>My Amazing Page โจ</title>
<meta name="description" content="Something awesome!">
<meta property="og:image" content="https://example.com/cool.jpg">
</head>
<body>
<h1>Welcome! ๐</h1>
<p>This is <strong>amazing</strong> content.</p>
</body>
</html>
"""
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)
}
Your HTML becomes beautiful Markdown:
---
title: "My Amazing Page โจ"
description: "Something awesome!"
og_image: "https://example.com/cool.jpg"
---
# Welcome! ๐
This is **amazing** content.
make build # ๐ Release build
make debug # ๐ Debug build
make test # ๐ฏ Run tests
make clean # ๐งน Clean build artifacts
make update # ๐ Update all dependencies
make resolve # ๐ฏ Resolve dependencies
Here's an example test for OGP extraction:
import XCTest
@testable import Remark
final class RemarkTests: XCTestCase {
func testOGPDataExtraction() throws {
let htmlContent = """
<meta property="og:image" content="https://example.com/cool.jpg" />
<meta property="og:title" content="Amazing Page โจ" />
"""
let remark = try Remark(htmlContent)
XCTAssertEqual(remark.ogData["og_image"], "https://example.com/cool.jpg")
XCTAssertEqual(remark.ogData["og_title"], "Amazing Page โจ")
}
}
Love Remark? Want to make it better? Contributions are welcome! ๐
- ๐ด Fork it
- ๐จ Make your changes
- ๐งช Test them
- ๐ฏ Send a PR
Remark is available under the MIT license. See the LICENSE file for more info. โจ