Skip to content

Commit

Permalink
Merge pull request #192 from jkuhlemann/strikethrough-support
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipme authored Jul 18, 2024
2 parents 3bb7ef0 + 9aa7fe9 commit ca460b9
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/src/main/java/me/mudkip/moememos/ext/AnnotatedStringExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import androidx.compose.ui.text.UrlAnnotation
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withAnnotation
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp
import org.intellij.markdown.MarkdownElementTypes
import org.intellij.markdown.MarkdownTokenTypes
import org.intellij.markdown.ast.ASTNode
import org.intellij.markdown.ast.getTextInNode
import org.intellij.markdown.flavours.gfm.GFMElementTypes
import org.intellij.markdown.flavours.gfm.GFMTokenTypes
import java.util.UUID

Expand Down Expand Up @@ -166,8 +168,8 @@ fun AnnotatedString.Builder.appendMarkdown(
withStyle(SpanStyle(fontFamily = FontFamily.Monospace)) {
node.children.filter {
it.type != MarkdownTokenTypes.CODE_FENCE_START
&& it.type != MarkdownTokenTypes.CODE_FENCE_END
&& it.type != MarkdownTokenTypes.FENCE_LANG
&& it.type != MarkdownTokenTypes.CODE_FENCE_END
&& it.type != MarkdownTokenTypes.FENCE_LANG
}.drop(1).dropLast(1).forEach { childNode ->
appendMarkdown(
markdownText = markdownText,
Expand Down Expand Up @@ -272,9 +274,29 @@ fun AnnotatedString.Builder.appendMarkdown(
}
}

GFMElementTypes.STRIKETHROUGH -> {
withStyle(SpanStyle(textDecoration = TextDecoration.LineThrough)) {
node.children.filter { it.type != GFMTokenTypes.TILDE }.forEach { childNode ->
appendMarkdown(
markdownText = markdownText,
node = childNode,
depth = depth + 1,
linkColor = linkColor,
onImage = onImage,
onCheckbox = onCheckbox,
maxWidth = maxWidth,
bulletColor = bulletColor,
headlineLarge = headlineLarge,
headlineMedium = headlineMedium,
headlineSmall = headlineSmall
)
}
}
}

else -> {
append(node.getTextInNode(markdownText).toString())
}
}
return this
}
}

0 comments on commit ca460b9

Please sign in to comment.