in src/commonMain/kotlin/org/intellij/markdown/parser/sequentialparsers/impl/LinkParserUtil.kt [10:53]
fun parseLinkDestination(iterator: TokensCache.Iterator): LocalParsingResult? {
var it = iterator
if (it.type == MarkdownTokenTypes.EOL || it.type == MarkdownTokenTypes.RPAREN) {
return null
}
val startIndex = it.index
val withBraces = it.type == MarkdownTokenTypes.LT
if (withBraces) {
it = it.advance()
}
var hasOpenedParentheses = false
while (it.type != null) {
if (withBraces && it.type == MarkdownTokenTypes.GT) {
break
} else if (!withBraces) {
if (it.type == MarkdownTokenTypes.LPAREN) {
if (hasOpenedParentheses) {
break
}
hasOpenedParentheses = true
}
val next = it.rawLookup(1)
if (SequentialParserUtil.isWhitespace(it, 1) || next == null) {
break
} else if (next == MarkdownTokenTypes.RPAREN) {
if (!hasOpenedParentheses) {
break
}
hasOpenedParentheses = false
}
}
it = it.advance()
}
if (it.type != null && !hasOpenedParentheses) {
return LocalParsingResult(it,
listOf(SequentialParser.Node(startIndex..it.index + 1, MarkdownElementTypes.LINK_DESTINATION)))
}
return null
}