Skip to content

Instantly share code, notes, and snippets.

@hupili
Last active December 30, 2015 02:58
Show Gist options
  • Save hupili/7765790 to your computer and use it in GitHub Desktop.
Save hupili/7765790 to your computer and use it in GitHub Desktop.
Add MathJax support to GitLab 5.x (?)

http://haml.info/docs/yardoc/file.REFERENCE.html#javascript-filter

HAML:

%script{:type => "text/javascript", 
        :src  => "javascripts/script_#{2 + 7}"}

MathJax

    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
    tex2jax: {
    inlineMath: [['$','$']],
    processEscapes: true
    }
    });
    </script>
    <script type="text/javascript"
      src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>

Git Diff

diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 375f886..773c440 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -34,7 +34,7 @@ module GitlabMarkdownHelper
                           # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-
                           filter_html: true,
                           with_toc_data: true,
-                          hard_wrap: true)
+                          hard_wrap: false)
       @markdown = Redcarpet::Markdown.new(gitlab_renderer,
                       # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
                       no_intra_emphasis: true,
@@ -44,7 +44,7 @@ module GitlabMarkdownHelper
                       strikethrough: true,
                       lax_html_blocks: true,
                       space_after_headers: true,
-                      superscript: true)
+                      superscript: false)
     end

     @markdown.render(text).html_safe
diff --git a/app/views/wikis/show.html.haml b/app/views/wikis/show.html.haml
index b237bc5..368c21d 100644
--- a/app/views/wikis/show.html.haml
+++ b/app/views/wikis/show.html.haml
@@ -1,4 +1,11 @@
 = render 'wikis/nav'
+
+%script{:type => "text/javascript",
+        :src  => "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"}
+
+%script{:type => "text/javascript",
+        :src  => "/mathjax_config.js"}
+
 %h3.page_title
   = @wiki.title.titleize
   = render partial: 'main_links'
diff --git a/public/mathjax_config.js b/public/mathjax_config.js
new file mode 100644
index 0000000..40bee60
--- /dev/null
+++ b/public/mathjax_config.js
@@ -0,0 +1,12 @@
+MathJax.Hub.Config({
+tex2jax: {
+inlineMath: [['$','$']],
+processEscapes: true
+}
+});
+
+$(document).ready(function(){
+       $('.file_content.wiki').map(function(){
+               MathJax.Hub.Queue(["Typeset",MathJax.Hub,$(this).get(0)]);
+       });
+});

Path: app/views/wikis/show.html.haml

@hupili
Copy link
Author

hupili commented Dec 3, 2013

This was a modification for GL 5.x back in July 2013. We are using newer version now. The diff here is not meant to be a copy-and-paste solution. It was done in a two-hour pair hack and none of us are ruby/JS/HTML professional. Just a hint for users to enable Mathjax in GL's wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment