5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-25 23:06:22 +00:00
panel/app/models/metadata_markdown_content.rb

31 lines
761 B
Ruby
Raw Normal View History

2020-05-26 22:26:19 +00:00
# frozen_string_literal: true
2020-06-09 14:28:18 +00:00
# Contenido con el editor de Markdown
2021-03-03 12:46:02 +00:00
class MetadataMarkdownContent < MetadataText
2020-06-25 19:29:14 +00:00
# Renderizar a HTML y sanitizar
def to_s
sanitize CommonMarker.render_doc(value, %i[FOOTNOTES SMART],
%i[table strikethrough autolink]).to_html
end
2021-03-03 12:46:02 +00:00
def value
self[:value] || document_value || default_value
2021-03-03 12:46:02 +00:00
end
def front_matter?
false
end
# @return [String]
def document_value
2021-03-03 12:46:02 +00:00
document.content
end
2020-06-25 19:29:14 +00:00
# XXX: No sanitizamos acá porque se escapan varios símbolos de
2020-07-02 14:26:00 +00:00
# markdown y se eliminan autolinks. Mejor es deshabilitar la
# generación SAFE de CommonMark en la configuración del sitio.
2020-06-25 19:29:14 +00:00
def sanitize(string)
string.tr("\r", '').unicode_normalize
2020-06-09 14:28:18 +00:00
end
2020-05-26 22:26:19 +00:00
end