Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support b and i tags in Basic HTML #4

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Package.swift
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has the package platform been bumped to 16? It should continue supporting the lowest possible version.

Copy link
Author

@ryanbooker ryanbooker Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was failing to compile on iOS. macOS was compiling fine.

The Regex at BasicHTML.swift:96 & 98 seems to be the culprit.

../BasicHTML.swift:96:37: 'Regex' is only available in iOS 16.0 or newer
../BasicHTML.swift:96:54: 'firstMatch(in:)' is only available in iOS 16.0 or newer
../BasicHTML.swift:98:42: 'output' is only available in iOS 16.0 or newer

I think it would have been passing the checks because the build is done on macOS 13.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I'll push another merge after this to fix the platforms for macOS. As for this or it looks good!

Copy link
Author

@ryanbooker ryanbooker Apr 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now worries. macOS seems ok as Regex exists in macOS 13.

Is there anything you want me to change?

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "SwiftHTMLtoMarkdown",
platforms: [
.iOS(.v15),
.iOS(.v16),
.macOS(.v13)
],
products: [
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftHTMLtoMarkdown/BasicHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public class BasicHTML: HTML {
let href = try node.attr("href")
markdown += "(\(href))"
return
} else if node.nodeName() == "strong" {
} else if node.nodeName() == "strong" || node.nodeName() == "b" {
markdown += "**"
for child in node.getChildNodes() {
try convertNode(child)
}
markdown += "**"
return
} else if node.nodeName() == "em" {
} else if node.nodeName() == "em" || node.nodeName() == "i" {
markdown += "*"
for child in node.getChildNodes() {
try convertNode(child)
Expand Down
9 changes: 5 additions & 4 deletions Tests/SwiftHTMLtoMarkdownTests/BasicHTMLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ final class BasicHTMLTests: XCTestCase {
<h6>Heading level 6</h6>
<p>I just love <strong>bold text</strong>.</p>

<p>Love<strong>is</strong>bold</p>
<p>Love<b>is</b>bold</p>

<p>Italicized text is the <em>cat's meow</em>.</p>
<p>A<em>cats</em>meow</p>


<p>A<i>cats</i>meow</p>

<p>This text is <em><strong>really important</strong></em>.</p>

<p>This is some code <code>Hello World!</code></p>
Expand Down
Loading