From f93a06451d5df9ec2217ebfb7b3a8690eb3aff07 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Fri, 27 Feb 2026 15:18:10 +0100 Subject: [PATCH] Extend autolink parsing to handle non-HTTP links, add fallback for invalid autolinks, and update `ParseTest` coverage. --- .../kotlin/nl/astraeus/markdown/parser/Paragraph.kt | 6 +++++- .../kotlin/nl/astraeus/markdown/parser/ParseTest.kt | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/nl/astraeus/markdown/parser/Paragraph.kt b/src/commonMain/kotlin/nl/astraeus/markdown/parser/Paragraph.kt index f5c8a50..b8c8f05 100644 --- a/src/commonMain/kotlin/nl/astraeus/markdown/parser/Paragraph.kt +++ b/src/commonMain/kotlin/nl/astraeus/markdown/parser/Paragraph.kt @@ -133,8 +133,12 @@ private val states = listOf( if (content.contains("@") and content.contains(".")) { Link("mailto:$content", content) - } else { + } else if (content.startsWith("http://") || + content.startsWith("https://") + ) { Link(content, content) + } else { + Text("<$content>") } }, diff --git a/src/commonTest/kotlin/nl/astraeus/markdown/parser/ParseTest.kt b/src/commonTest/kotlin/nl/astraeus/markdown/parser/ParseTest.kt index bf71c2d..85dc6b6 100644 --- a/src/commonTest/kotlin/nl/astraeus/markdown/parser/ParseTest.kt +++ b/src/commonTest/kotlin/nl/astraeus/markdown/parser/ParseTest.kt @@ -398,7 +398,7 @@ class ParseTest { @Test fun testAutlinks() { val input = """ - Dit is een text met mail autolink and http autolink. + Dit is een text met mail autolink and http autolink and autolink. """.trimIndent() val md = markdown(input)