5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-30 06:06:07 +00:00
panel/app/models/metadata_markdown_content.rb
2021-03-03 09:46:02 -03:00

30 lines
732 B
Ruby

# frozen_string_literal: true
# Contenido con el editor de Markdown
class MetadataMarkdownContent < MetadataText
# Renderizar a HTML y sanitizar
def to_s
sanitize CommonMarker.render_doc(value, %i[FOOTNOTES SMART],
%i[table strikethrough autolink]).to_html
end
def value
self[:value] || value_from_document || default_value
end
def front_matter?
false
end
def value_from_document
document.content
end
# XXX: No sanitizamos acá porque se escapan varios símbolos de
# markdown y se eliminan autolinks. Mejor es deshabilitar la
# generación SAFE de CommonMark en la configuración del sitio.
def sanitize(string)
string.tr("\r", '')
end
end