feat: add html-to-md-swift converter and CLI support#14
Conversation
kiki830621
left a comment
There was a problem hiding this comment.
Code Review
CRITICAL
packages/html-to-md-swift/Package.swift:23-28— Self-test 宣告為.executableTarget,不是.testTarget。swift test完全跑不到這些測試。專案規定 80% test coverage(common-testing.md),其他所有 package 都用.testTarget+XCTestCase。需要改成標準 test target。
HIGH
-
HTMLConverter.swift:17—SwiftSoup.parse(html, input.deletingLastPathComponent().absoluteString)把file:///...當 base URL 傳入,導致 HTML 中的相對連結(如href="about.html")被解析成file:///Users/.../about.html洩漏到 Markdown 輸出。應傳空字串""以保留原始相對路徑。 -
HTMLConverter.swift— 只支援 UTF-8 encoding(String(contentsOf: input, encoding: .utf8))。實務上 HTML 常用 ISO-8859-1 / Windows-1252,會直接 throw I/O error。建議先嘗試 UTF-8,失敗後 fallbackString(contentsOf: input, usedEncoding:)。 -
HTMLConverter.swift:105-107—<hr>輸出---,與--frontmatter模式的 YAML 分隔符衝突。Markdown parser 會誤判。建議改用* * *或- - -(帶空格)。 -
Sources/MacDocCLI/MacDoc+HTML.swift:8— 用ParsableCommand而非AsyncParsableCommand,與Wordsubcommand 模式不一致。 -
packages/html-to-md-swift/Package.swift:5— deployment target 宣告.macOS(.v14),其他所有 local packages 都是.v13。應統一為.v13。
MEDIUM
<ol start="N">的startattribute 被忽略,永遠從 1 開始編號。- Block-level
<br>不受--hard-breaksflag 控制,與 inline path 行為不一致。 trimTrailingNewlines用removeLast()in-place mutation,可改用trimmingCharacters(in:)。
|
Fixes applied and merged directly to main. See commit 60aec53. |
Summary
packages/html-to-md-swiftHTMLConverter: DocumentConverterusing SwiftSoup + streaming Markdown emissionmacdoc htmlCLI subcommandCONVERSIONS.mdwith a real matrix + priority queue and markhtml-to-md-swiftactiveCloses #13.
What the converter supports
Block-level
h1...h6pre > codediv,section,article,main, etc.)Inline
<br>hard-break option<u>,<sup>,<sub>,<mark>Testing
Validated the new package with:
cd packages/html-to-md-swift swift build --target HTMLToMDSwift swift run HTMLToMDSwiftSelfTestSelf-test coverage includes:
Notes
swift buildis still affected by the existing clean-clone path dependency problem tracked in build: move local path dependencies to remote packages for clean clone/build #12; this PR does not attempt to solve that separately.XCTest/Testingmodules, the package uses a self-test executable for verification instead ofswift testin this branch.