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

global link definitions should use case-insensitive matching logic #541

Merged
merged 1 commit into from
Sep 23, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private[link] class DocumentTargets(document: Document, slugBuilder: String => S

val linkConfig = document.config.get[LinkConfig].getOrElse(LinkConfig.empty)
val targetsFromConfig = linkConfig.targets.map { defn =>
linkDefinitionResolver(LinkDefinitionSelector(defn.id), defn.target)
linkDefinitionResolver(LinkDefinitionSelector(defn.id.toLowerCase), defn.target)
}

val resolvedTargets = groupedTargets.toSeq.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ class InlineParsersSpec extends FunSuite with TestSourceBuilders {
runEnclosed(input, ref)
}

test("link reference with an implicit id, preserving the case for the link text") {
val input = "some [Link] here"
val ref = LinkIdReference("link", source("[Link]", input))("Link")
runEnclosed(input, ref)
}

test("image reference with an explicit id") {
val input = "some ![image][id] here"
runEnclosed(input, ImageIdReference("image", "id", source("![image][id]", input)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class RewriteRulesSpec extends FunSuite with ParagraphCompanionShortcuts with Te
private val linkConfig = LinkConfig.empty
.addTargets(
TargetDefinition.internal("int", RelativePath.parse("../doc-1.md#ref")),
TargetDefinition.internal("CasE", RelativePath.parse("../doc-2.md#ref")),
TargetDefinition.external("ext", "https://www.foo.com/"),
TargetDefinition.internal("inv", RelativePath.parse("../doc-99.md#ref"))
)
Expand Down Expand Up @@ -356,6 +357,12 @@ class RewriteRulesSpec extends FunSuite with ParagraphCompanionShortcuts with Te
IdRefs.run(linkIdRef("int"), p(SpanLink(target)("text")))
}

test("global link defs - resolve internal link references with case-insensitive comparison") {
val target = InternalTarget(RelativePath.parse("../doc-2.md#ref")).relativeTo(Root / "tree1")
val ref = LinkIdReference(List(Text("Case")), "case", generatedSource(s"<<Case>>"))
IdRefs.run(ref, p(SpanLink(target)("Case")))
}

test("global link defs - resolve external link references") {
val externalLink = SpanLink.external("https://www.foo.com/")("text")
IdRefs.run(linkIdRef("ext"), p(externalLink))
Expand Down