From 7766625611e26ee01513cdeb0720bba14e132639 Mon Sep 17 00:00:00 2001 From: Wing <44992537+wingio@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:51:57 -0500 Subject: [PATCH] Finish documentation --- .../java/xyz/wingio/dimett/ast/Renderer.kt | 22 +++++++++++++++++++ .../main/java/xyz/wingio/dimett/ast/Rules.kt | 12 +++++----- .../ast/rendercontext/DefaultRenderContext.kt | 6 ++--- .../java/xyz/wingio/dimett/di/HttpModule.kt | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/xyz/wingio/dimett/ast/Renderer.kt b/app/src/main/java/xyz/wingio/dimett/ast/Renderer.kt index 109e6cc..75e557d 100644 --- a/app/src/main/java/xyz/wingio/dimett/ast/Renderer.kt +++ b/app/src/main/java/xyz/wingio/dimett/ast/Renderer.kt @@ -10,6 +10,14 @@ import xyz.wingio.syntakts.compose.rememberAsyncRendered import xyz.wingio.syntakts.markdown.addBasicMarkdownRules import xyz.wingio.syntakts.syntakts +/** + * Renders a formatted version of [text] + * + * @param text Text to parse and format + * @param emojiMap Used to insert custom emoji into the text + * @param mentionMap All the users mentioned in the post + * @param actionHandler Callback that is passed the actions name + */ @Composable fun Syntakts.render( text: String, @@ -21,6 +29,11 @@ fun Syntakts.render( context = rememberRenderContext(emojiMap, mentionMap, actionHandler) ) +/** + * Creates a remembered version of [DefaultRenderContext] + * + * @see DefaultRenderContext + */ @Composable fun rememberRenderContext( emojiMap: Map, @@ -35,6 +48,9 @@ fun rememberRenderContext( } } +/** + * Contains all the rules for rendering post content + */ val DefaultSyntakts = syntakts { addHashtagRule() addMentionRule() @@ -43,6 +59,9 @@ val DefaultSyntakts = syntakts { addUnicodeEmojiRule() } +/** + * Contains the rules for rendering styled string resources + */ val StringSyntakts = syntakts { addUrlRule() addClickableRule() @@ -50,6 +69,9 @@ val StringSyntakts = syntakts { addUnicodeEmojiRule() } +/** + * Only contains rules necessary for emotes and Twemoji + */ val EmojiSyntakts = syntakts { addEmojiRule() addUnicodeEmojiRule() diff --git a/app/src/main/java/xyz/wingio/dimett/ast/Rules.kt b/app/src/main/java/xyz/wingio/dimett/ast/Rules.kt index 5bfc133..37908f5 100644 --- a/app/src/main/java/xyz/wingio/dimett/ast/Rules.kt +++ b/app/src/main/java/xyz/wingio/dimett/ast/Rules.kt @@ -8,22 +8,22 @@ import xyz.wingio.syntakts.compose.style.toSyntaktsColor import xyz.wingio.syntakts.style.Style const val urlRegex = - "https?:\\/\\/([\\w+?]+\\.[\\w+]+)([a-zA-Z0-9\\~\\!\\@\\#\\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?" + "https?:\\/\\/([\\w+?]+\\.[\\w+]+)([a-zA-Z0-9\\~\\!\\@\\#\\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?" // https://example.com const val hyperlinkRegex = - "\\[(.+?)\\]\\(($urlRegex)\\)" + "\\[(.+?)\\]\\(($urlRegex)\\)" // [link](https://example.com) const val clickableRegex = - "\\[(.+?)\\]\\{(.+?)\\}" + "\\[(.+?)\\]\\{(.+?)\\}" // [some text]{onSomeAction} const val emojiRegex = - ":(.+?):" + ":(.+?):" // :shortcode: const val mentionRegex = - "@(\\S+?)\\b(@(\\S+)\\b)?" + "@(\\S+?)\\b(@(\\S+)\\b)?" // @user or @user@example.social const val hashtagRegex = - "#(.+?)\\b" + "#(.+?)\\b" // #sometext fun Syntakts.Builder.addUrlRule() { rule(urlRegex) { result, context -> diff --git a/app/src/main/java/xyz/wingio/dimett/ast/rendercontext/DefaultRenderContext.kt b/app/src/main/java/xyz/wingio/dimett/ast/rendercontext/DefaultRenderContext.kt index bc74eab..81e28f0 100644 --- a/app/src/main/java/xyz/wingio/dimett/ast/rendercontext/DefaultRenderContext.kt +++ b/app/src/main/java/xyz/wingio/dimett/ast/rendercontext/DefaultRenderContext.kt @@ -4,9 +4,9 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.UriHandler data class DefaultRenderContext( - val emojiMap: Map, - val mentionMap: Map, + val emojiMap: Map, // shortcode: url + val mentionMap: Map, // username to id val linkColor: Color, val uriHandler: UriHandler, - val clickActionHandler: (String) -> Unit + val clickActionHandler: (String) -> Unit // Is passed the action name (Ex. onUserClick) ) \ No newline at end of file diff --git a/app/src/main/java/xyz/wingio/dimett/di/HttpModule.kt b/app/src/main/java/xyz/wingio/dimett/di/HttpModule.kt index 720aae3..ccb0084 100644 --- a/app/src/main/java/xyz/wingio/dimett/di/HttpModule.kt +++ b/app/src/main/java/xyz/wingio/dimett/di/HttpModule.kt @@ -27,7 +27,7 @@ val httpModule = module { defaultRequest { header( HttpHeaders.UserAgent, - "Dimett/${BuildConfig.APPLICATION_ID} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})${if (BuildConfig.DEBUG) " - Debug" else ""}" + "Dimett/${BuildConfig.APPLICATION_ID} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" // Dimett/xyz.wingio.dimett v1.0.0 (1) ) } install(Logging) {