Skip to content
Snippets Groups Projects
Verified Commit e24f84d2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Drop pygments

parent 2c07c50a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -314,53 +314,6 @@ table of contents at the top of all your wiki pages if it is enabled:
Gollum::Wiki.new("my-gollum-repo.git", {:universal_toc => true})
```
 
## SYNTAX HIGHLIGHTING
In page files you can get automatic syntax highlighting for a wide range of
languages (courtesy of [Pygments](http://pygments.org/) - must install
separately) by using the following syntax:
```ruby
def foo
puts 'bar'
end
```
The block must start with three backticks, at the beginning of a line or
indented with any number of spaces or tabs.
After that comes the name of the language that is contained by the
block. The language must be one of the `short name` lexer strings supported by
Pygments. See the [list of lexers](http://pygments.org/docs/lexers/) for valid
options.
The block contents should be indented at the same level than the opening backticks.
If the block contents are indented with an additional two spaces or one tab,
then that whitespace will be ignored (this makes the blocks easier to read in plaintext).
The block must end with three backticks indented at the same level than the opening
backticks.
### GITHUB SYNTAX HIGHLIGHTING
As an extra feature, you can syntax highlight a file from your repository, allowing
you keep some of your sample code in the main repository. The code-snippet is
updated when the wiki is rebuilt. You include github code like this:
```html:github:gollum/gollum-lib/master/test/file_view/1_file.txt```
This will make the builder look at the **gollum user**, in the **gollum-lib project**,
in the **master branch**, at path **test/file_view/1_file.txt**. It will be
rewritten to:
```html
<ol class="tree">
<li class="file"><a href="0">0</a></li>
</ol>
```
Which will be parsed as HTML code during the Pygments run, and thereby coloured
appropriately.
## MATHEMATICAL EQUATIONS
 
Start gollum with the `--mathjax` flag. Read more about [MathJax](http://docs.mathjax.org/en/latest/index.html) on the web. Gollum uses the `TeX-AMS-MML_HTMLorMML` config with the `autoload-all` extension.
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.rubygems_version = '0.0.1'
s.required_ruby_version = ">= 1.8.7"
 
s.name = 'gitlab-gollum-lib'
s.name = 'gitlab-gollum-lib'
s.version = `cat VERSION`
s.date = Time.now.strftime("%Y-%m-%d")
s.rubyforge_project = 'gollum-lib'
Loading
Loading
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = %w[README.md LICENSE]
 
s.add_dependency('gitlab-grit', '~> 2.6.1')
s.add_dependency('gitlab-pygments.rb', '~> 0.5.4')
s.add_dependency('github-markup', ['>= 0.7.5', '< 1.0.0'])
s.add_dependency('github-markdown', '~> 0.5.3')
s.add_dependency('sanitize', '~> 2.0.3')
Loading
Loading
@@ -43,6 +42,7 @@ Gem::Specification.new do |s|
 
# = MANIFEST =
s.files = %w[
VERSION
Gemfile
HISTORY.md
LICENSE
Loading
Loading
# ~*~ encoding: utf-8 ~*~
require 'digest/sha1'
require 'cgi'
require 'pygments'
require 'base64'
 
require File.expand_path '../helpers', __FILE__
require File.expand_path '../remote_code', __FILE__
 
# initialize Pygments
Pygments.start
module Gollum
 
class Markup
Loading
Loading
@@ -580,13 +576,7 @@ module Gollum
highlighted = []
blocks.each do |lang, code|
encoding ||= 'utf-8'
begin
# must set startinline to true for php to be highlighted without <?
# http://pygments.org/docs/lexers/
hl_code = Pygments.highlight(code, :lexer => lang, :options => {:encoding => encoding.to_s, :startinline => true})
rescue
hl_code = code
end
hl_code = code
highlighted << hl_code
end
 
Loading
Loading
Loading
Loading
@@ -196,74 +196,6 @@ context "Markup" do
assert_html_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
end
 
test "regexp gsub! backref (#383)" do
# bug only triggers on "```" syntax
# not `code`
page = 'test_rgx'
@wiki.write_page(page, :markdown,
(<<-'DATA'
```
rot13='tr '\''A-Za-z'\'' '\''N-ZA-Mn-za-m'\'
```
DATA
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<pre><code> <div class=\"highlight\"><pre><span class=\"n\">rot13</span><span class=\"o\">=</span><span class=\"err\">'</span><span class=\"n\">tr</span> <span class=\"sc\">'\\''</span><span class=\"n\">A</span><span class=\"o\">-</span><span class=\"n\">Za</span><span class=\"o\">-</span><span class=\"n\">z</span><span class=\"sc\">'\\''</span> <span class=\"sc\">'\\''</span><span class=\"n\">N</span><span class=\"o\">-</span><span class=\"n\">ZA</span><span class=\"o\">-</span><span class=\"n\">Mn</span><span class=\"o\">-</span><span class=\"n\">za</span><span class=\"o\">-</span><span class=\"n\">m</span><span class=\"err\">'\\'</span>\n</pre></div>\n</code></pre>}
assert_html_equal expected, output
end
# Issue #568
test "tilde code blocks without a language" do
page = 'test_rgx'
@wiki.write_page(page, :markdown,
%Q(~~~
'hi'
~~~
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"err\">'</span><span class=\"n\">hi</span><span class=\"err\">'</span>\n</pre></div>}
assert_html_equal expected, output
end
test "tilde code blocks #537" do
page = 'test_rgx'
@wiki.write_page(page, :markdown,
%Q(~~~ {.ruby}
'hi'
~~~
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
assert_html_equal expected, output
end
# Issue #537
test "tilde code blocks with more than one class" do
page = 'test_rgx'
@wiki.write_page(page, :markdown,
%Q(~~~ {#hi .ruby .sauce}
'hi'
~~~
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
assert_html_equal expected, output
end
# Issue #537
test "tilde code blocks with lots of tildes" do
page = 'test_rgx'
@wiki.write_page(page, :markdown,
%Q(~~~~~~ {#hi .ruby .sauce}
~~
'hi'~
~~~~~~
), commit_details)
output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\"><pre><span class=\"o\">~~</span>\n<span class=\"s1\">'hi'</span><span class=\"o\">~</span>\n</pre></div>}
assert_html_equal expected, output
end
test "four space indented code block" do
page = 'test_four'
@wiki.write_page(page, :markdown,
Loading
Loading
@@ -478,108 +410,6 @@ context "Markup" do
assert_html_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
end
 
#########################################################################
#
# Code
#
#########################################################################
test "regular code blocks" do
content = "a\n\n```ruby\nx = 1\n```\n\nb"
output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>\n\n<p>b</p>}
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_html_equal output, rendered
end
test "code blocks with carriage returns" do
content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>\n\n<p>b</p>}
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_html_equal output, rendered
end
test "code blocks with two-space indent" do
content = "a\n\n```ruby\n x = 1\n\n y = 2\n```\n\nb"
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
"x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
"</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
compare(content, output)
end
test "code blocks with one-tab indent" do
content = "a\n\n```ruby\n\tx = 1\n\n\ty = 2\n```\n\nb"
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
"x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
"</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
compare(content, output)
end
test "code blocks with multibyte caracters indent" do
content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb"
output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'</span>\n</pre></div>\n\n<p>b</p>}
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render(false, 'utf-8')
assert_html_equal output, rendered
end
test "code blocks with ascii characters" do
content = "a\n\n```\n├─foo\n```\n\nb"
output = %(<p>a</p><divclass=\"highlight\"><pre><spanclass=\"err\">├─</span><spanclass=\"n\">foo</span></pre></div><p>b</p>)
compare(content, output)
end
test "code with wiki links" do
content = <<-END
booya
``` python
np.array([[2,2],[1,3]],np.float)
```
END
# rendered with Gollum::Markup
page, rendered = render_page(content)
assert_markup_highlights_code Gollum::Markup, rendered
end
test "code with trailing whitespace" do
content = <<-END
shoop da woop
``` python
np.array([[2,2],[1,3]],np.float)
```
END
# rendered with Gollum::Markup
page, rendered = render_page(content)
assert_markup_highlights_code Gollum::Markup, rendered
end
def assert_markup_highlights_code(markup_class, rendered)
assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
end
test "embed code page absolute link" do
@wiki.write_page("base", :markdown, "a\n!base\b", commit_details)
@wiki.write_page("a", :markdown, "a\n```html:/base```\b", commit_details)
Loading
Loading
Loading
Loading
@@ -18,18 +18,6 @@ context "remote_code" do
@wiki, @path, @cleanup = WikiFactory.create 'examples/test.git'
end
 
test 'that the rendered output is correctly fetched and rendered as html code' do
# given
p = page_with_content "a\n\n```html:https://raw.github.com/gollum/gollum-lib/master/test/file_view/1_file.txt```\n\nb"
# when rendering the page
rendered = Gollum::Markup.new(p).render
# we expect
expected = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"nt\">&lt;ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">&gt;</span>\n <span class=\"nt\">&lt;li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">&gt;</span>\n <span class=\"nt\">&lt;a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">&gt;&lt;span</span> <span class=\"na\">class=</span><span class=\"s\">\"icon\"</span><span class=\"nt\">&gt;&lt;/span&gt;</span>0<span class=\"nt\">&lt;/a&gt;</span>\n <span class=\"nt\">&lt;/li&gt;</span>\n<span class=\"nt\">&lt;/ol&gt;</span>\n</pre></div>\n\n<p>b</p>}
assert_html_equal expected, rendered
end
test 'contents' do
g = Gollum::RemoteCode.new 'https://raw.github.com/gollum/gollum-lib/master/test/file_view/1_file.txt'
 
Loading
Loading
@@ -37,32 +25,6 @@ context "remote_code" do
assert_html_equal expected, g.contents
end
 
test "remote_code relative local file" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:file-exists.py```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
index = @wiki.repo.index
index.add("file-exists.py", "import sys\n\nprint sys.maxint\n")
index.commit("Add file-exists.py")
@wiki.clear_cache
output = page.formatted_data
assert_html_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
end
test "remote_code relative local file in subdir" do
index = @wiki.repo.index
index.add("foo/file-exists.py", "import sys\n\nprint sys.maxint\n")
index.commit("Add file-exists.py")
@wiki.write_page("Pippin", :markdown, "a\n```python:file-exists.py```\nb", commit_details, 'foo')
page = @wiki.paged('Pippin', 'foo')
output = page.formatted_data
assert_html_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
end
test "remote_code relative no file" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:no-file-exists.py```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
Loading
Loading
@@ -70,19 +32,6 @@ context "remote_code" do
assert_html_equal %Q{<p>a\nFile not found: no-file-exists.py\nb</p>}, output
end
 
test "remote_code absolute local file" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:/monkey/file-exists.py```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
index = @wiki.repo.index
index.add("monkey/file-exists.py", "import sys\n\nprint sys.platform\n")
index.commit("Add monkey/file-exists.py")
@wiki.clear_cache
output = page.formatted_data
assert_html_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span>\n</pre></div>\n\n<p>b</p>}, output
end
test "remote_code absolute no file" do
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:/monkey/no-file-exists.py```\nb", commit_details)
page = @wiki.page('Bilbo Baggins')
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment