diff options
author | hellekin <hellekin@cepheide.org> | 2020-10-27 20:01:32 +0100 |
---|---|---|
committer | hellekin <hellekin@cepheide.org> | 2020-10-27 20:01:32 +0100 |
commit | bcd0f419b6ae5142c6a41ac5ace0f881808eb136 (patch) | |
tree | 9dd0d9b087042661c3bfefe539e0e83d65cbea83 /app | |
parent | eca6705b299c5afe2e8ed995529f7afc5559ae0b (diff) | |
parent | c3f4936dbb524237d1e3d465d2301627758c2180 (diff) | |
download | incommon-map-bcd0f419b6ae5142c6a41ac5ace0f881808eb136.tar.gz |
Merge branch 'markdown'
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/application_helper.rb | 43 | ||||
-rw-r--r-- | app/views/resources/_resource.html.erb | 2 |
2 files changed, 44 insertions, 1 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0b22f4b..2b6e109 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,4 +7,47 @@ module ApplicationHelper current_agency.send(:"#{role}?") end 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 diff --git a/app/views/resources/_resource.html.erb b/app/views/resources/_resource.html.erb index 585bed8..2debec2 100644 --- a/app/views/resources/_resource.html.erb +++ b/app/views/resources/_resource.html.erb @@ -5,7 +5,7 @@ <time datetime="<%= h resource.updated_at %>" class="updated_at"> <p class="identifier"><%= resource_url(resource) %></p> </header> - <div><%= h resource.description %></div> + <%= m resource.description %> <hr> <code><pre><%= h JSON.pretty_generate(resource.feature.as_json) %></pre></code> <p>... <%= session[:current_agent] %>...</p> |