diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-09-11 11:47:13 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-09-11 11:47:13 +0300 |
commit | 4f461fd45f65dbd6900088149b48649b27a7c2ce (patch) | |
tree | 2a05b8ef187db81f059b59f71a6cdcbbc2c465c1 /spec | |
parent | a5bb85f8a234b2d8463656877712faf10f5bb842 (diff) | |
parent | e3c97ede9663fe7905fcb350875c46526cb4f832 (diff) |
Merge branch 'rs-fix-highlighting' into 'master'
Syntax highlighting improvements
On the server side:
During development I would occasionally see SanitizationFilter sanitizing
the result of SyntaxHighlightFilter, even though its attributes were
whitelisted. This updates the `clean_spans` transformer to return the
whitelisted node as [suggested by the Sanitize docs](http://git.io/vZR8i).
On the client side:
- Makes the syntax_highlight JS more flexible
- Adds JS specs
- Simplifies highlighting of new notes
- Adds highlighting to Markdown preview
See merge request !1278
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/syntax_highlight_spec.js.coffee | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/javascripts/syntax_highlight_spec.js.coffee b/spec/javascripts/syntax_highlight_spec.js.coffee new file mode 100644 index 00000000000..6a73b6bf32c --- /dev/null +++ b/spec/javascripts/syntax_highlight_spec.js.coffee @@ -0,0 +1,42 @@ +#= require syntax_highlight + +describe 'Syntax Highlighter', -> + stubUserColorScheme = (value) -> + window.gon ?= {} + window.gon.user_color_scheme = value + + describe 'on a js-syntax-highlight element', -> + beforeEach -> + fixture.set('<div class="js-syntax-highlight"></div>') + + it 'applies syntax highlighting', -> + stubUserColorScheme('monokai') + + $('.js-syntax-highlight').syntaxHighlight() + + expect($('.js-syntax-highlight')).toHaveClass('monokai') + + describe 'on a parent element', -> + beforeEach -> + fixture.set """ + <div class="parent"> + <div class="js-syntax-highlight"></div> + <div class="foo"></div> + <div class="js-syntax-highlight"></div> + </div> + """ + + it 'applies highlighting to all applicable children', -> + stubUserColorScheme('monokai') + + $('.parent').syntaxHighlight() + + expect($('.parent, .foo')).not.toHaveClass('monokai') + expect($('.monokai').length).toBe(2) + + it 'prevents an infinite loop when no matches exist', -> + fixture.set('<div></div>') + + highlight = -> $('div').syntaxHighlight() + + expect(highlight).not.toThrow() |