Skip to content

Commit

Permalink
Ensure existing marked renderer code runs with customization (#4078)
Browse files Browse the repository at this point in the history
* 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 63973f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
28 changes: 22 additions & 6 deletions angular/core/config/marked.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)
20 changes: 0 additions & 20 deletions angular/core/services/render_service.coffee

This file was deleted.

0 comments on commit 63973f7

Please sign in to comment.