Skip to content
Permalink
Browse files
Ensure existing marked renderer code runs with customization (#4078)
* Ensure existing marked renderer code runs with customization

* Use noopener / noreferrer for marked links
  • Loading branch information
gdpelican committed May 15, 2017
1 parent fc7fc35 commit 63973f71e337ead8ca7b7ae2a043b837032dc3fe
Showing with 22 additions and 26 deletions.
  1. +22 −6 angular/core/config/marked.coffee
  2. +0 −20 angular/core/services/render_service.coffee
@@ -1,6 +1,22 @@
angular.module('loomioApp').config (markedProvider, renderProvider) ->
markedProvider.setOptions
gfm: true
sanitize: true
breaks: true
markedProvider.setRenderer(renderProvider.$get(0).createRenderer())
angular.module('loomioApp').config (markedProvider) ->
customRenderer = (opts) ->
_super = new marked.Renderer(opts)
renderer = _.clone(_super)
cook = (text) ->
text = emojione.shortnameToImage(text)
text = text.replace(/\[\[@([a-zA-Z0-9]+)\]\]/g, "<a class='lmo-user-mention' href='/u/$1'>@$1</a>")
text

renderer.paragraph = (text) -> _super.paragraph cook(text)
renderer.listitem = (text) -> _super.listitem cook(text)
renderer.tablecell = (text) -> _super.tablecell cook(text)

renderer.heading = (text, level) ->
_super.heading(emojione.shortnameToImage(text), level, text)

renderer.link = (href, title, text) ->
_super.link(href, title, text).replace('<a ', '<a rel="noopener noreferrer" target="_blank" ')

renderer

markedProvider.setRenderer customRenderer(gfm: true, sanitize: true, breaks: true)

This file was deleted.

0 comments on commit 63973f7

Please sign in to comment.