docs: add documentation for various classes in app/logical.

This commit is contained in:
evazion
2021-06-23 05:09:55 -05:00
parent e5cfb7904c
commit ed302fdf4d
33 changed files with 518 additions and 25 deletions

View File

@@ -1,3 +1,5 @@
# Sanitizes the HTML used in notes. Only safe HTML tags, HTML attributes, and
# CSS properties are allowed.
module NoteSanitizer
ALLOWED_ELEMENTS = %w[
code center tn h1 h2 h3 h4 h5 h6 a span div blockquote br p ul li ol em
@@ -50,6 +52,9 @@ module NoteSanitizer
vertical-align
]
# Sanitize a string of HTML.
# @param text [String] the HTML to sanitize
# @return [String] the sanitized HTML
def self.sanitize(text)
text.gsub!(/<( |-|3|:|>|\Z)/, "&lt;\\1")
@@ -76,6 +81,8 @@ module NoteSanitizer
)
end
# Convert absolute Danbooru links inside notes to relative links.
# https://danbooru.donmai.us/posts/1 is converted to /posts/1.
def self.relativize_links(node:, **env)
return unless node.name == "a" && node["href"].present?