From 2d2c6832430cc51559afc6012a00a4b7b05c83b6 Mon Sep 17 00:00:00 2001 From: Lanius Trolling Date: Thu, 24 Aug 2023 14:54:18 -0400 Subject: [PATCH] Add image tags for commenting --- .../info/mechyrdia/data/views_comment.kt | 23 +++++++++++++++++++ .../kotlin/info/mechyrdia/lore/parser_tags.kt | 20 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/main/kotlin/info/mechyrdia/data/views_comment.kt b/src/main/kotlin/info/mechyrdia/data/views_comment.kt index 9ca1be5..ed64c34 100644 --- a/src/main/kotlin/info/mechyrdia/data/views_comment.kt +++ b/src/main/kotlin/info/mechyrdia/data/views_comment.kt @@ -459,6 +459,29 @@ suspend fun ApplicationCall.commentHelpPage(): HTML.() -> Unit = page("Commentin a(href = "https://google.com/") { +"HTML link" } } } + tr { + td { +"[imgbb=256x256]Lns12z1/robert-sparr.png[/imgbb]" } + td { + p { + +"Creates an embedded image:" + br + unsafe { + raw("") + } + br + +"The tag param controls the width and height, much like a table cell. The size unit is viewport-responsive and has no correlation with pixels." + } + p { + +"A similar tag is used to embed images that are hosted on Imgur, e.g. the image at https://i.imgur.com/dd0mmQ1.png" + br + unsafe { + raw("") + } + br + +"can be embedded using [imgur=250x323]dd0mmQ1.png[/imgur]" + } + } + } tr { td { +"[reply](comment id)[/reply]" } td { +"Creates a reply link to a comment" } diff --git a/src/main/kotlin/info/mechyrdia/lore/parser_tags.kt b/src/main/kotlin/info/mechyrdia/lore/parser_tags.kt index 5765f7f..70bd963 100644 --- a/src/main/kotlin/info/mechyrdia/lore/parser_tags.kt +++ b/src/main/kotlin/info/mechyrdia/lore/parser_tags.kt @@ -356,6 +356,23 @@ enum class TextParserCommentTags(val type: TextParserTagType) { LANG(TextParserFormattingTag.LANG.type), + IMGUR( + TextParserTagType.Indirect { tagParam, content, _ -> + val imageUrl = sanitizeExtLink(content) + val (width, height) = getSizeParam(tagParam) + + "" + } + ), + IMGBB( + TextParserTagType.Indirect { tagParam, content, _ -> + val imageUrl = sanitizeExtLink(content) + val (width, height) = getSizeParam(tagParam) + + "" + } + ), + REPLY( TextParserTagType.Indirect { _, content, _ -> sanitizeId(content)?.let { id -> @@ -383,6 +400,9 @@ val NON_LINK_CHAR = Regex("[^#a-zA-Z\\d\\-._]") val DOT_CHARS = Regex("\\.+") fun sanitizeLink(html: String) = html.replace(NON_LINK_CHAR, "").replace(DOT_CHARS, ".") +val NON_EXT_LINK_CHAR = Regex("[^#a-zA-Z\\d\\-._/]") +fun sanitizeExtLink(html: String) = html.replace(NON_EXT_LINK_CHAR, "").replace(DOT_CHARS, ".") + val ID_REGEX = Regex("[A-IL-TVX-Z0-9]{24}") fun sanitizeId(html: String) = ID_REGEX.matchEntire(html)?.value -- 2.25.1