[Grazie][IDEA-326315] Do not exclude short reference link label in MarkdownTextExtractor

GitOrigin-RevId: fa98cb71ef188735269aeb4666e374e147123d68
This commit is contained in:
Ekaterina Berezhko
2024-04-02 14:37:05 +00:00
committed by intellij-monorepo-bot
parent ad36426508
commit c87ed9a7b7
2 changed files with 12 additions and 1 deletions
@@ -22,7 +22,7 @@ class MarkdownTextExtractor : TextExtractor() {
.withUnknown { it.node.isMarkdownCodeType() }
.withMarkup { e ->
e.elementType in markup ||
e.firstChild == null && e.parent.node.isMarkdownLinkType() && !isLinkText(e)
e.firstChild == null && e.parent.node.isMarkdownLinkType() && !isLinkText(e) && !isShortRefLinkLabel(e)
}
.excluding { it.elementType == MarkdownElementTypes.IMAGE }
.removingIndents(" \t").removingLineSuffixes(" \t")
@@ -34,4 +34,9 @@ class MarkdownTextExtractor : TextExtractor() {
private fun isLinkText(e: PsiElement) =
(e.elementType == MarkdownTokenTypes.TEXT || e.elementType == MarkdownTokenTypes.GFM_AUTOLINK || e is PsiWhiteSpace) &&
e.parent.elementType == MarkdownElementTypes.LINK_TEXT
private fun isShortRefLinkLabel(e: PsiElement) =
e.parent.parent.elementType == MarkdownElementTypes.SHORT_REFERENCE_LINK &&
e.parent.elementType == MarkdownElementTypes.LINK_LABEL &&
(e.elementType == MarkdownTokenTypes.TEXT || e is PsiWhiteSpace)
}
@@ -58,6 +58,12 @@ public class TextExtractionTest extends BasePlatformTestCase {
Assertions.assertArrayEquals(new int[]{0, extracted.length()}, extracted.markupOffsets());
}
public void testMarkdownShortRefLink() {
TextContent extracted = extractText("a.md", "go to [link] and validate\n[link] : http://localhost", 3);
assertEquals("go to link and validate\nlink : http://localhost", unknownOffsets(extracted));
Assertions.assertArrayEquals(new int[]{6, 10, 24, 28}, extracted.markupOffsets());
}
public void testMarkdownIndent() {
TextContent extracted = extractText("a.md", "* first line \n second line", 3);
assertEquals("first line\nsecond line", unknownOffsets(extracted));