1amageek/Remark
Convert HTML to Markdown with OG metadata extraction and front matter generation ๐จโจ
โจ 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:
dependencies: [
.package(url: "https://github.com/1amageek/Remark.git", branch: "main")
]๐ป As a Command Line Tool
๐ Using Mint (Recommended)
Mint is the easiest way to install Swift command line tools! ๐
mint install 1amageek/RemarkThat's it! Now you can use remark from anywhere! โจ
๐ Using Make
- Clone the repo and move into it:
git clone https://github.com/1amageek/Remark.git
cd Remark- Install with make:
make installWant a custom location? No problem! ๐ฏ
PREFIX=/your/custom/path make install๐ง Manual Installation
- Clone the repo ๐ฆ
- Build release version:
swift build -c release- Copy to your bin:
cp .build/release/remark /usr/local/bin/remark๐ฎ Usage
๐ฅ Command Line Interface
Convert HTML from any URL to Markdown: โจ
remark https://example.comInclude the fancy front matter: ๐
remark --include-front-matter https://example.comJust the plain text, please! ๐
remark --plain-text https://example.com๐ Library Usage
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)
}๐จ Example Output
Your HTML becomes beautiful Markdown:
---
title: "My Amazing Page โจ"
description: "Something awesome!"
og_image: "https://example.com/cool.jpg"
---
# Welcome! ๐
This is **amazing** content.๐ Development
๐ Building
make build # ๐ Release build
make debug # ๐ Debug build๐งช Testing
make test # ๐ฏ Run tests๐งน Cleaning
make clean # ๐งน Clean build artifacts๐ฆ Dependencies
make update # ๐ Update all dependencies
make resolve # ๐ฏ Resolve dependencies๐งช Tests
Here's an example test for OGP extraction using Swift Testing:
import Testing
@testable import Remark
@Test("OGP data extraction")
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)
#expect(remark.ogData["og_image"] == "https://example.com/cool.jpg")
#expect(remark.ogData["og_title"] == "Amazing Page โจ")
}๐ Contributing
Love Remark? Want to make it better? Contributions are welcome! ๐
- ๐ด Fork it
- ๐จ Make your changes
- ๐งช Test them
- ๐ฏ Send a PR
๐ License
Remark is available under the MIT license. See the LICENSE file for more info. โจ
Package Metadata
Repository: 1amageek/Remark
Homepage: https://github.com/1amageek/Remark
Stars: 5
Forks: 2
Open issues: 0
Default branch: main
Primary language: swift
Topics: front-matter, html, markdown, ogp, swift
README: README.md