diff options
author | Steffen van Bergerem <svbergerem@online.de> | 2015-05-02 17:36:18 +0300 |
---|---|---|
committer | Jonne Haß <me@jhass.eu> | 2015-05-04 05:04:34 +0300 |
commit | 0cffa00004cb495d4d4acdd8792254a51cbe457b (patch) | |
tree | 648556064135c2972ff5feabefb6c05f513317cc /app | |
parent | dd2e1ea29e38d4dc9c585da7971fd8621a88bb20 (diff) |
Add syntax highlighting for markdown content
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/app/helpers/text_formatter.js | 20 | ||||
-rw-r--r-- | app/assets/javascripts/main.js | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/application.scss | 1 |
3 files changed, 21 insertions, 1 deletions
diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index 5bdfd5830..163f938ed 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -8,7 +8,8 @@ breaks: true, html: true, linkify: true, - typographer: true + typographer: true, + langPrefix: "" }); var inlinePlugin = window.markdownitForInline; @@ -50,6 +51,23 @@ var sanitizerPlugin = window.markdownitSanitizer; md.use(sanitizerPlugin); + var hljs = window.hljs; + md.set({ + highlight: function(str, lang) { + if (lang && hljs.getLanguage(lang)) { + try { + return hljs.highlight(lang, str).value; + } catch (__) {} + } + + try { + return hljs.highlightAuto(str).value; + } catch (__) {} + + return ""; + } + }); + // xmpp: should behave like mailto: md.linkify.add("xmpp:","mailto:"); // mumble:// should behave like http://: diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 452235f9b..7114600e6 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -35,6 +35,7 @@ //= require markdown-it-sanitizer //= require markdown-it-sub //= require markdown-it-sup +//= require highlightjs //= require clear-form //= require app/app //= require diaspora diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 4d3bd3df3..a4f8ce423 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -92,6 +92,7 @@ /* code */ @import 'new_styles/code'; +@import 'highlightjs/github'; /* statistics */ @import 'new_styles/statistics'; |