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
|
2023-10-06 13:53:19 +00:00
|
|
|
#
|
|
|
|
# @todo Deprecar
|
2021-03-03 12:46:02 +00:00
|
|
|
class MetadataMarkdownContent < MetadataText
|
2023-10-06 13:53:19 +00:00
|
|
|
include Metadata::ContentConcern
|
|
|
|
|
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
|
|
|
|
|
2023-10-06 13:53:19 +00:00
|
|
|
# @return [String]
|
2021-03-03 12:46:02 +00:00
|
|
|
def value
|
2021-06-16 14:35:37 +00:00
|
|
|
self[:value] || document_value || default_value
|
2021-03-03 12:46:02 +00:00
|
|
|
end
|
|
|
|
|
2023-10-06 13:53:19 +00:00
|
|
|
# Obtener el contenido desde el documento
|
|
|
|
#
|
2021-06-16 14:35:37 +00:00
|
|
|
# @return [String]
|
|
|
|
def document_value
|
2021-03-03 12:46:02 +00:00
|
|
|
document.content
|
|
|
|
end
|
|
|
|
|
2023-10-06 13:53:19 +00:00
|
|
|
private
|
|
|
|
|
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.
|
2023-10-06 13:53:19 +00:00
|
|
|
#
|
|
|
|
# @param :string [String]
|
|
|
|
# @return [String]
|
2020-06-25 19:29:14 +00:00
|
|
|
def sanitize(string)
|
2022-04-28 13:34:57 +00:00
|
|
|
string.tr("\r", '').unicode_normalize
|
2020-06-09 14:28:18 +00:00
|
|
|
end
|
2020-05-26 22:26:19 +00:00
|
|
|
end
|