Skip to content

Commit

Permalink
Merge branch 'main' into spell-check-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wavesonics committed Dec 9, 2024
2 parents 87905ce + 612f9f7 commit 4776c1e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
}

fun onText(text: String) {
val text = text.replace('\n', ' ')

if (text.isEmpty()) return

if (richParagraphList.isEmpty())
Expand Down Expand Up @@ -183,7 +185,10 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
newRichSpan.text = "$".repeat(node.endOffset - node.startOffset)
}

if (node.type == GFMTokenTypes.GFM_AUTOLINK) {
if (
node.type == GFMTokenTypes.GFM_AUTOLINK ||
node.type == MarkdownTokenTypes.CODE_LINE
) {
onText(node.getTextInNode(input).toString())
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,50 @@ class RichTextStateMarkdownParserEncodeTest {
assertEquals("Prompt\nEmphasis", state.toText())
}

@Test
fun testEncodeWithLeadingSpaces() {
val markdown = """First line
indented line"""

val state = RichTextStateMarkdownParser.encode(markdown)

val parsedString = state.toText()

assertEquals(
expected = """
First line
indented line
""".trimIndent(),
actual = parsedString
)
}

@Test
fun testEncodeInlineCodeInDifferentLines() {
val markdown =
"""
Hello `World!
Kotlin` MP
""".trimIndent()

val state = RichTextStateMarkdownParser.encode(markdown)

val parsedString = state.toText()

assertEquals(
expected =
"""
Hello World! Kotlin MP
""".trimIndent(),
actual = parsedString,
)

assertEquals(
expected = 1,
actual = state.richParagraphList.size,
)
}

}

0 comments on commit 4776c1e

Please sign in to comment.