diff --git a/Sources/SwiftHTMLtoMarkdown/BasicHTML.swift b/Sources/SwiftHTMLtoMarkdown/BasicHTML.swift index fa97bd7..6fa378c 100644 --- a/Sources/SwiftHTMLtoMarkdown/BasicHTML.swift +++ b/Sources/SwiftHTMLtoMarkdown/BasicHTML.swift @@ -108,6 +108,14 @@ public class BasicHTML: HTML { markdown += "\n```" return } + } else if node.nodeName() == "ul", node.childNodeSize() >= 1 { + for child in node.getChildNodes() { + if child.nodeName() == "li" { + markdown += "\n- " + try convertNode(child) + } + } + return } if node.nodeName() == "#text" && node.description != " " { diff --git a/Tests/SwiftHTMLtoMarkdownTests/BasicHTMLTests.swift b/Tests/SwiftHTMLtoMarkdownTests/BasicHTMLTests.swift index cfdfb3f..28ef7fc 100644 --- a/Tests/SwiftHTMLtoMarkdownTests/BasicHTMLTests.swift +++ b/Tests/SwiftHTMLtoMarkdownTests/BasicHTMLTests.swift @@ -5,12 +5,13 @@ // Created by Taylor Lineman on 8/23/23. // -import XCTest +import Foundation +import Testing @testable import SwiftHTMLtoMarkdown -final class BasicHTMLTests: XCTestCase { +final class BasicHTMLTests { - func testAll() throws { + @Test func all() throws { let raw = """
This text is really important.
+This is some code Hello World!
Hello World
@@ -55,6 +61,8 @@ final class BasicHTMLTests: XCTestCase {
A*cats*meow
This text is ***really important***.
+ - This is the first list item
+ - This is the second list item
This is some code `Hello World!`
@@ -71,10 +79,10 @@ final class BasicHTMLTests: XCTestCase {
let markdown = try document.asMarkdown()
print(markdown)
- XCTAssertTrue(markdown == correctOutput)
+ #expect(markdown == correctOutput)
}
- func testHeaderLevelOne() throws {
+ @Test func headerLevelOne() throws {
let raw = "Paragraphs are pretty fun
" let correctOutput = "Paragraphs are pretty fun" var document = BasicHTML(rawHTML: raw) @@ -172,10 +180,10 @@ final class BasicHTMLTests: XCTestCase { let markdown = try document.asMarkdown() print(markdown) - XCTAssertTrue(markdown == correctOutput) + #expect(markdown == correctOutput) } - func testBold() throws { + @Test func bold() throws { let raw = "I just love bold text.
" let correctOutput = "I just love **bold text**." var document = BasicHTML(rawHTML: raw) @@ -183,10 +191,10 @@ final class BasicHTMLTests: XCTestCase { let markdown = try document.asMarkdown() print(markdown) - XCTAssertTrue(markdown == correctOutput) + #expect(markdown == correctOutput) } - func testBoldWithNoLeadingOrTrailingSpaces() throws { + @Test func boldWithNoLeadingOrTrailingSpaces() throws { let raw = "Loveisbold
" let correctOutput = "Love**is**bold" var document = BasicHTML(rawHTML: raw) @@ -194,10 +202,10 @@ final class BasicHTMLTests: XCTestCase { let markdown = try document.asMarkdown() print(markdown) - XCTAssertTrue(markdown == correctOutput) + #expect(markdown == correctOutput) } - func testItalicized() throws { + @Test func italicized() throws { let raw = "Italicized text is the cat's meow.
" let correctOutput = "Italicized text is the *cat's meow*." var document = BasicHTML(rawHTML: raw) @@ -205,10 +213,10 @@ final class BasicHTMLTests: XCTestCase { let markdown = try document.asMarkdown() print(markdown) - XCTAssertTrue(markdown == correctOutput) + #expect(markdown == correctOutput) } - func testItalicizedWithNoLeadingOrTrailingSpaces() throws { + @Test func italicizedWithNoLeadingOrTrailingSpaces() throws { let raw = "Acatsmeow
" let correctOutput = "A*cats*meow" var document = BasicHTML(rawHTML: raw) @@ -216,10 +224,10 @@ final class BasicHTMLTests: XCTestCase { let markdown = try document.asMarkdown() print(markdown) - XCTAssertTrue(markdown == correctOutput) + #expect(markdown == correctOutput) } - func testItalicizedBoldText() throws { + @Test func italicizedBoldText() throws { let raw = "This text is really important.
" let correctOutput = "This text is ***really important***." var document = BasicHTML(rawHTML: raw) @@ -227,10 +235,10 @@ final class BasicHTMLTests: XCTestCase { let markdown = try document.asMarkdown() print(markdown) - XCTAssertTrue(markdown == correctOutput) + #expect(markdown == correctOutput) } - func testFencedCodeBlockWithLanguage() throws { + @Test func fencedCodeBlockWithLanguage() throws { let raw = """Hello World
"""
@@ -246,10 +254,10 @@ final class BasicHTMLTests: XCTestCase {
let markdown = try document.asMarkdown()
print(markdown)
- XCTAssertTrue(markdown == correctOutput)
+ #expect(markdown == correctOutput)
}
- func testFencedCodeBlockWithoutLanguage() throws {
+ @Test func fencedCodeBlockWithoutLanguage() throws {
let raw = """
Hello World
"""
@@ -265,10 +273,10 @@ final class BasicHTMLTests: XCTestCase {
let markdown = try document.asMarkdown()
print(markdown)
- XCTAssertTrue(markdown == correctOutput)
+ #expect(markdown == correctOutput)
}
- func testCode() throws {
+ @Test func code() throws {
let raw = "This is some code Hello World!