diff --git a/slices/main/decorators/posts/decorator.rb b/slices/main/decorators/posts/decorator.rb index 388f2ba..6dd2ecd 100644 --- a/slices/main/decorators/posts/decorator.rb +++ b/slices/main/decorators/posts/decorator.rb @@ -12,6 +12,8 @@ module Main module Decorators module Posts class Decorator < SimpleDelegator + REGEXP = URI::DEFAULT_PARSER.make_regexp + def syndicated? !syndication_sources.empty? end @@ -111,6 +113,14 @@ module Main photos? ? "
#{photos.map { |p| "" }.join("")} #{content}
" : content end + def rendered_content + html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content)) + res = Sanitize.fragment(html_text, + elements: ["img", "p", "object", "a"], + attributes: {"img" => ["alt", "src", "title"], "a" => ["href"]}) + res.gsub(prefix_emoji[0], "") if prefix_emoji + end + def raw_content res = Sanitize.fragment(content) res.gsub(prefix_emoji[0], "") if prefix_emoji @@ -174,6 +184,24 @@ module Main private + def replace_urls_with_anchors(text) + url_regex = %r{(?]*(|/>))} + + text.gsub(url_regex) do |url| + %(#{url}) + end + end + + def wrap_anchors_in_object_tags(text) + # Regular expression to match tags + anchor_regex = /(]*>.*?<\/a>)/ + + # Replace the matched anchor tags with wrapped anchor tags + text.gsub(anchor_regex) do |anchor_tag| + %(#{anchor_tag}) + end + end + # e.g. geo:-37.75188,144.90417;u=35 def geo loc = location.split(":")[1] @@ -211,8 +239,8 @@ module Main results << "" end results - rescue REXML::ParseException => e - return "

No excerpt

" + rescue REXML::ParseException + "

No excerpt

" end def attrs_to_s(attrs) diff --git a/slices/main/decorators/statuses/decorator.rb b/slices/main/decorators/statuses/decorator.rb index 16583b8..747cf84 100644 --- a/slices/main/decorators/statuses/decorator.rb +++ b/slices/main/decorators/statuses/decorator.rb @@ -10,13 +10,36 @@ module Main module Decorators module Statuses class Decorator < Main::Decorators::Posts::Decorator + REGEXP = URI::DEFAULT_PARSER.make_regexp + def raw_content - res = Sanitize.fragment(content, - elements: ["img", "p"], - attributes: {"img" => ["alt", "src", "title"]}) + html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content)) + res = Sanitize.fragment(html_text, + elements: ["img", "p", "object", "a"], + attributes: {"img" => ["alt", "src", "title"], "a" => ["href"]}) res.gsub(prefix_emoji[0], "") if prefix_emoji end + + private + + def replace_urls_with_anchors(text) + url_regex = %r{(?]*(|/>))} + + text.gsub(url_regex) do |url| + %(#{url}) + end + end + + def wrap_anchors_in_object_tags(text) + # Regular expression to match tags + anchor_regex = /(]*>.*?<\/a>)/ + + # Replace the matched anchor tags with wrapped anchor tags + text.gsub(anchor_regex) do |anchor_tag| + %(#{anchor_tag}) + end + end end end end diff --git a/slices/main/templates/shared/_status.html.slim b/slices/main/templates/shared/_status.html.slim index b57e431..ec0763e 100644 --- a/slices/main/templates/shared/_status.html.slim +++ b/slices/main/templates/shared/_status.html.slim @@ -42,7 +42,7 @@ div class="mb-8 h-entry border border-gray-200 m-2 p-4 bg-gray-50 hover:bg-gray- video class="rounded w-max" autoplay=false loop=false muted=true controls=true source type="video/mp4" src="#{video["value"]}" div class="mb-8" - p class="text-sm text-blue-400 dark:text-indigo-400" + p class="mt-4 text-sm text-blue-400 dark:text-indigo-400" a class="u-url float-left mr-0 border-dotted border-b-2 border-blue-100 hover:border-blue-200 dark:border-indigo-900 dark:hover:border-indigo-800" href="#{post.permalink}" time class="dt-published" datetime=post.machine_published_at = post.display_published_at