aboutsummaryrefslogtreecommitdiff
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index aa3a8d7..15d5082 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,3 +1,7 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
module ApplicationHelper
def current_agency
current_user.agencies.where(agent: current_agent).first
@@ -21,4 +25,47 @@ module ApplicationHelper
'map-zoom': map.zoom
})
end
+
+ # Markdown helper
+ # Always use all extensions. Additional parser and render options may be
+ # passed as a second argument.
+ #
+ # @param markdown (String) a string to parse as Markdown source
+ # @param options (String or Array) an optional parser/renderer option
+ # @return String HTML-formatted from Mardkown source
+ def m(markdown, options = nil)
+ tag.div(
+ CommonMarker.render_doc(
+ markdown.to_s,
+ options.to_a + default_commonmarker_options,
+ default_commonmarker_extensions
+ ).to_html.html_safe, class: 'markdown')
+ end
+
+ private
+
+ # CommonMarker extensions
+ # See https://github.com/gjtorikian/commonmarker#extensions
+ def default_commonmarker_extensions
+ [
+ :table,
+ :tasklist,
+ :strikethrough,
+ :autolink,
+ :tagfilter
+ ]
+ end
+
+ # CommonMarker options
+ # See https://github.com/gjtorikian/commonmarker#options
+ def default_commonmarker_options
+ [
+ #:HARDBREAKS, # only seems to work with render_html, but then all others
+ # only work with render_doc
+ :FOOTNOTES,
+ :SMART,
+ :STRIKETHROUGH_DOUBLE_TILDE,
+ :VALIDATE_UTF8
+ ]
+ end
end