FEATURE: add HTML replacements

This adds support for Watched Words to allow replacement with HTML content rather than always replacing with text.

Can be useful when automatically replacing with the '<abbr>' tag for example.

Discussion - https://meta.discourse.org/t/replace-text-with-more-than-just-links/305672
This commit is contained in:
Régis Hanol
2024-05-06 17:08:34 +02:00
parent 9b70cbf4bb
commit 1eec8c3fa6
13 changed files with 65 additions and 22 deletions

View File

@@ -31,12 +31,11 @@ class WordWatcher
.where(action: WatchedWord.actions[action.to_sym])
.limit(WatchedWord::MAX_WORDS_PER_ACTION)
.order(:id)
.pluck(:word, :replacement, :case_sensitive)
.to_h do |w, r, c|
[
word_to_regexp(w, match_word: false),
{ word: w, replacement: r, case_sensitive: c }.compact,
]
.pluck(:word, :replacement, :case_sensitive, :html)
.to_h do |w, r, c, h|
opts = { word: w, replacement: r, case_sensitive: c }.compact
opts[:html] = true if h
[word_to_regexp(w, match_word: false), opts]
end
end