Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
pull_request:
push:
branches:
- main
workflow_dispatch:

jobs:
test:
name: Swift tests and smoke tests
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Show Swift version
run: swift --version

- name: Run unit tests
run: swift test

- name: Run CLI smoke tests
run: Scripts/smoke-test.sh
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ print(document.markdown)
swift run swift-markitdown path/to/file.html
```

## Testing

Run the unit test suite and CLI fixture smoke tests before opening a PR:

```bash
swift test
Scripts/smoke-test.sh
```

GitHub Actions runs the same checks on pushes to `main`, pull requests, and manual workflow dispatches.

## Roadmap

1. Expand the text/HTML/CSV/JSON converters with richer Markdown normalization and metadata extraction.
Expand Down
31 changes: 31 additions & 0 deletions Scripts/smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BINARY="${ROOT_DIR}/.build/debug/swift-markitdown"

swift build --package-path "${ROOT_DIR}" --product swift-markitdown

run_case() {
local name="$1"
local input="${ROOT_DIR}/Tests/Fixtures/${name}"
local expected="${ROOT_DIR}/Tests/Expected/${name%.*}.md"
local actual
actual="$(mktemp)"

"${BINARY}" "${input}" > "${actual}"

if ! diff -u "${expected}" "${actual}"; then
echo "Smoke test failed for ${name}" >&2
rm -f "${actual}"
return 1
fi

rm -f "${actual}"
echo "✓ ${name}"
}

run_case note.txt
run_case page.html
run_case table.csv
run_case data.json
4 changes: 4 additions & 0 deletions Sources/SwiftMarkItDown/Converters/HTMLConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public struct HTMLConverter: DocumentConverter {
html = html.replacingOccurrences(of: "\r\n", with: "\n")

let rules: [(String, String)] = [
("(?is)<head\\b[^>]*>.*?</head>", ""),
("(?is)<script\\b[^>]*>.*?</script>", ""),
("(?is)<style\\b[^>]*>.*?</style>", ""),
("(?is)<h1\\b[^>]*>(.*?)</h1>", "\n# $1\n"),
Expand All @@ -36,6 +37,9 @@ public struct HTMLConverter: DocumentConverter {
.smid_decodingHTMLEntities()
.replacingOccurrences(of: "[ \t]+\n", with: "\n", options: .regularExpression)
.replacingOccurrences(of: "\n{3,}", with: "\n\n", options: .regularExpression)
.split(separator: "\n", omittingEmptySubsequences: false)
.map { $0.trimmingCharacters(in: .whitespaces) }
.joined(separator: "\n")
.smid_trimmedBlankLines

return MarkdownDocument(markdown: markdown, sourceFormat: .html)
Expand Down
4 changes: 4 additions & 0 deletions Tests/Expected/data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- **formats**:
- txt
- html
- **title**: Roadmap
2 changes: 2 additions & 0 deletions Tests/Expected/note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello SwiftMarkItDown
This is plain text.
5 changes: 5 additions & 0 deletions Tests/Expected/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Smoke Test

Hello **native Swift** & Markdown.

[Example](https://example.com)
4 changes: 4 additions & 0 deletions Tests/Expected/table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| Name | Note |
| --- | --- |
| Swift | Native |
| Mark, It Down | CSV \| escaped |
1 change: 1 addition & 0 deletions Tests/Fixtures/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Roadmap","formats":["txt","html"]}
2 changes: 2 additions & 0 deletions Tests/Fixtures/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello SwiftMarkItDown
This is plain text.
13 changes: 13 additions & 0 deletions Tests/Fixtures/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<title>Ignored title</title>
<style>body { color: red; }</style>
<script>console.log("ignore");</script>
</head>
<body>
<h1>Smoke Test</h1>
<p>Hello <strong>native Swift</strong> &amp; Markdown.</p>
<p><a href="https://example.com">Example</a></p>
</body>
</html>
3 changes: 3 additions & 0 deletions Tests/Fixtures/table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name,Note
Swift,Native
"Mark, It Down","CSV | escaped"
2 changes: 1 addition & 1 deletion Tests/SwiftMarkItDownTests/SwiftMarkItDownTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SwiftMarkItDownTests {

@Test("converts simple HTML to Markdown")
func convertsHTML() throws {
let html = "<h1>Title</h1><p>Hello <strong>Swift</strong> &amp; iOS.</p><a href=\"https://example.com\">Link</a>"
let html = "<html><head><title>Ignored</title></head><body><h1>Title</h1><p>Hello <strong>Swift</strong> &amp; iOS.</p><a href=\"https://example.com\">Link</a></body></html>"
let request = ConversionRequest(data: Data(html.utf8), fileName: "index.html")
let document = try MarkItDown().convert(request)
#expect(document.markdown == "# Title\nHello **Swift** & iOS.\n\n[Link](https://example.com)")
Expand Down
Loading