Skip to content

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

Notifications You must be signed in to change notification settings

1amageek/Remark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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:

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:
git clone /~https://github.com/1amageek/Remark.git
cd Remark
  1. Install with make:
make install

Want a custom location? No problem! ๐ŸŽฏ

PREFIX=/your/custom/path make install

๐Ÿ”ง Manual Installation

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

๐ŸŽฎ Usage

๐Ÿ–ฅ Command Line Interface

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

๐Ÿ“š 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:

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 โœจ")
    }
}

๐ŸŒŸ 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. โœจ

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published