From 41c802321843eea63a22f5285b9c5863b12e210b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 31 Jul 2020 11:19:42 +0200 Subject: [PATCH] Insert spaces before stripping HTML when inserting search data Signed-off-by: Thomas Citharel --- lib/service/formatter/html.ex | 12 ++++++++++++ lib/service/workers/build_search.ex | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/service/formatter/html.ex b/lib/service/formatter/html.ex index 2f0857800..96780267d 100644 --- a/lib/service/formatter/html.ex +++ b/lib/service/formatter/html.ex @@ -24,5 +24,17 @@ defmodule Mobilizon.Service.Formatter.HTML do end end + @doc """ + Inserts a space before tags closing so that words are not attached once tags stripped + + `

test

next` thing becomes `test next` instead of `testnext` + """ + @spec strip_tags_and_insert_spaces(String.t()) :: String.t() + def strip_tags_and_insert_spaces(html) do + html + |> String.replace(" strip_tags() + end + def filter_tags_for_oembed(html), do: Sanitizer.scrub(html, OEmbed) end diff --git a/lib/service/workers/build_search.ex b/lib/service/workers/build_search.ex index fc51b7a7d..85913aabd 100644 --- a/lib/service/workers/build_search.ex +++ b/lib/service/workers/build_search.ex @@ -45,7 +45,7 @@ defmodule Mobilizon.Service.Workers.BuildSearch do [ event.id, event.title, - HTML.strip_tags(event.description), + HTML.strip_tags_and_insert_spaces(event.description), get_tags_string(event) ] )