override fun createMarkerBlocks()

in src/commonMain/kotlin/org/intellij/markdown/parser/markerblocks/providers/LinkReferenceDefinitionProvider.kt [14:41]


    override fun createMarkerBlocks(pos: LookaheadText.Position,
                                    productionHolder: ProductionHolder,
                                    stateInfo: MarkerProcessor.StateInfo): List<MarkerBlock> {

        if (!MarkerBlockProvider.isStartOfLineWithConstraints(pos, stateInfo.currentConstraints)) {
            return emptyList()
        }

        val matchResult = matchLinkDefinition(pos.originalText, pos.offset) ?: return emptyList()
        for ((i, range) in matchResult.withIndex()) {
            productionHolder.addProduction(listOf(SequentialParser.Node(
                    addToRangeAndWiden(range, 0), when (i) {
                0 -> MarkdownElementTypes.LINK_LABEL
                1 -> MarkdownElementTypes.LINK_DESTINATION
                2 -> MarkdownElementTypes.LINK_TITLE
                else -> throw AssertionError("There are no more than three groups in this regex")
            })))
        }

        val matchLength = matchResult.last().last - pos.offset + 1
        val endPosition = pos.nextPosition(matchLength)

        if (endPosition != null && !isEndOfLine(endPosition)) {
            return emptyList()
        }
        return listOf(LinkReferenceDefinitionMarkerBlock(stateInfo.currentConstraints, productionHolder.mark(),
                pos.offset + matchLength))
    }