Render Status as Markdown

This commit is contained in:
Thomas Ricouard 2022-11-25 10:03:42 +01:00
parent 3c1b879d1a
commit 0608996bb8
4 changed files with 32 additions and 2 deletions

View file

@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "html2markdown",
"kind" : "remoteSourceControl",
"location" : "https://gitlab.com/mflint/HTML2Markdown",
"state" : {
"revision" : "00d7a9744bbd1e7762c587bbd248775e16345a65",
"version" : "1.0.0"
}
}
],
"version" : 2
}

View file

@ -13,10 +13,13 @@ let package = Package(
name: "Network", name: "Network",
targets: ["Network"]), targets: ["Network"]),
], ],
dependencies: [
.package(url: "https://gitlab.com/mflint/HTML2Markdown", exact: "1.0.0")
],
targets: [ targets: [
.target( .target(
name: "Network", name: "Network",
dependencies: []), dependencies: ["HTML2Markdown"]),
.testTarget( .testTarget(
name: "NetworkTests", name: "NetworkTests",
dependencies: ["Network"]), dependencies: ["Network"]),

View file

@ -0,0 +1,13 @@
import SwiftSoup
import HTML2Markdown
extension Status {
public var contentAsMarkdown: String {
do {
let dom = try HTMLParser().parse(html: content)
return dom.toMarkdown()
} catch {
return content
}
}
}

View file

@ -28,7 +28,7 @@ struct StatusRowView: View {
.foregroundColor(.gray) .foregroundColor(.gray)
} }
} }
Text(status.content) Text(try! AttributedString(markdown: status.contentAsMarkdown))
} }
} }
} }