https://github.com/actuallytaylor/swifthtmltomarkdown
A simple Swift package that converts HTML into Markdown
https://github.com/actuallytaylor/swifthtmltomarkdown
html html-to-markdown html-to-markdown-converter htmltomarkdown markdown swift
Last synced: 9 months ago
JSON representation
A simple Swift package that converts HTML into Markdown
- Host: GitHub
- URL: https://github.com/actuallytaylor/swifthtmltomarkdown
- Owner: ActuallyTaylor
- License: mit
- Created: 2023-06-24T05:13:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-26T11:10:09.000Z (about 2 years ago)
- Last Synced: 2025-09-06T14:49:04.462Z (9 months ago)
- Topics: html, html-to-markdown, html-to-markdown-converter, htmltomarkdown, markdown, swift
- Language: Swift
- Homepage:
- Size: 27.3 KB
- Stars: 46
- Watchers: 2
- Forks: 21
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Swift HTML -> Markdown
This package allows you to quickly convert HTML code into Markdown. Normally you want to go from Markdown -> HTML and there are a thousand packages and parsers to do that. However, what if the service you are using (like Mastodon) provides everything in HTML but you want to parse it in Markdown? Well you need to convert it. This package allows you to do just that!
## Supported Flavors of HTML
| Flavor | Support |
| -------------------- | --------------------------------------------------- |
| Mastodon Status HTML (MastodonHTML) | ✅ |
| Basic HTML (BasicHTML) | ⚠️ (Almost fully supported, tables are not) |
## How to use
Using the library is pretty simple. The first step is to pick which HTML flavor you are going to be converting. If you are converting a Basic HTML document you can use the `BasicHTML` class. For Mastodon statuses you can use the `MastodonHTML` class.
Once you have picked out the class you will be using, the following code is all you need!
```swift
var document = BasicHTML(rawHTML: raw)
try document.parse()
let markdown = try document.asMarkdown()
print(markdwon)
```