Skip to content

Commit

Permalink
Add support for parsing and displaying Markdown content.
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinGeekDev committed Dec 26, 2024
1 parent bf099a6 commit 89d4333
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ dependencies {
//Nostr
implementation("org.rust-nostr:nostr-sdk:0.37.0")

//Markdown
implementation("org.jetbrains:markdown:0.7.3")

// Only for debug
debugImplementation("com.squareup.leakcanary:leakcanary-android:3.0-alpha-1")

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/nononsenseapps/feeder/model/FeedParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
import org.intellij.markdown.html.HtmlGenerator
import org.intellij.markdown.parser.MarkdownParser
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.kodein.di.DI
Expand All @@ -40,7 +43,6 @@ import rust.nostr.sdk.Nip21
import rust.nostr.sdk.Nip21Enum
import rust.nostr.sdk.NostrSdkException
import rust.nostr.sdk.PublicKey
import rust.nostr.sdk.Relay
import rust.nostr.sdk.RelayMetadata
import rust.nostr.sdk.SingleLetterTag
import rust.nostr.sdk.TagKind
Expand Down Expand Up @@ -506,13 +508,15 @@ fun Event.asArticle(authorName: String, imageUrl: String): ParsedArticle {
val articleImage = tags().find(TagKind.Image)?.content()
val articleSummary = tags().find(TagKind.Summary)?.content()
val articleContent = content()
val parsedMarkdown = markDownParser.buildMarkdownTreeFromString(articleContent)
val htmlFromContent = HtmlGenerator(articleContent, parsedMarkdown, CommonMarkFlavourDescriptor()).generateHtml()

return ParsedArticle(
id = articleId,
url = articleUri,
external_url = externalLink,
title = articleTitle,
content_html = null,
content_html = htmlFromContent,
content_text = articleContent,
summary = articleSummary,
image = if (articleImage != null) MediaImage(url = articleImage.toString()) else null,
Expand Down Expand Up @@ -718,6 +722,8 @@ suspend fun <T> OkHttpClient.curlAndOnResponse(
}
}

private val markDownParser = MarkdownParser(CommonMarkFlavourDescriptor())

class AuthorNostrData(
val uri: String,
val name: String,
Expand Down

0 comments on commit 89d4333

Please sign in to comment.