Compare commits

...

93 Commits

Author SHA1 Message Date
bootstraponline 52c6e7474c Release 2.3.4 2012-10-28 20:59:06 -06:00
bootstraponline be81f09b0e Update gemspec 2012-10-28 12:43:51 -06:00
bootstraponline 6fa4504e31 Fix #551 2012-10-28 12:37:02 -06:00
bootstraponline 992ba01a12 Fix page file dir 2012-10-28 11:57:25 -06:00
bootstraponline 72c5a74cf1 Update test
The test passes when verified manually using bin/gollum. Without a running server the test
will fail so it has been commented out. If there's an easy way to mock Rack::Server
then the test can be restored.
2012-10-27 23:44:11 -06:00
bootstraponline 919f41a0f1 Fix #559 2012-10-27 23:44:11 -06:00
bootstraponline 785921cb0f Fix toc generation 2012-10-27 21:46:30 -06:00
bootstraponline 8c8cda5e7d Fix comment 2012-10-27 21:05:56 -06:00
bootstraponline 64ef74e7e9 Add preview button to live preview 2012-10-27 20:52:54 -06:00
bootstraponline 776df4e6ee Fix nokogiri rendering
https://github.com/sparklemotion/nokogiri/issues/782
2012-10-27 19:52:26 -06:00
bootstraponline 68465a8651 Set indent and encoding 2012-10-27 18:12:32 -06:00
bootstraponline fa16c8960c Fix #560 2012-10-27 17:58:14 -06:00
bootstraponline 2c57915781 Refactor fileview 2012-10-23 23:27:31 -06:00
bootstraponline d0527f1aeb Release 2.3.3 2012-10-23 22:58:41 -06:00
bootstraponline 75083c5b56 Fix collapse tree 2012-10-23 22:36:17 -06:00
bootstraponline 82526594db Add attr reader for collapse tree 2012-10-23 22:22:56 -06:00
bootstraponline 941d39800c Merge pull request #556 from adiknoth/fileview
Documentation and usability enhancement of recent fileview fix
2012-10-23 21:20:28 -07:00
bootstraponline a1ae2e8bc0 Fix #554 2012-10-23 22:14:45 -06:00
bootstraponline 4af6f366ca Fix show_all /pages 2012-10-23 22:09:27 -06:00
Adrian Knoth c7a9534ed9 Add --collapse-tree command line option 2012-10-23 14:27:15 +02:00
Adrian Knoth 00bcbbf72b File View: Add option to collapse file trees.
For potentially large repositories, starting with a collapsed tree may
be beneficial.
2012-10-23 14:27:12 +02:00
Adrian Knoth ed2254ff9f Add missing documentation for --show-all 2012-10-23 14:22:54 +02:00
bootstraponline b6633f0ecb Release 2.3.2 2012-10-22 19:21:10 -06:00
bootstraponline e08d2d3052 Enable show_all for /pages 2012-10-22 19:10:40 -06:00
bootstraponline fbc0548b43 Add --show-all
--show-all will show all files in file view (not just valid pages). Default is false.
2012-10-22 19:03:21 -06:00
bootstraponline a9807bd1e1 Update math note 2012-10-21 17:22:31 -06:00
bootstraponline 554b80b39d Add MathJax examples 2012-10-21 17:21:24 -06:00
bootstraponline 99e74bf00b Release 2.3.1 2012-10-21 17:16:40 -06:00
bootstraponline f48e923f28 Fix release 2012-10-21 17:15:09 -06:00
bootstraponline 5400b4bfdd Support inline and display math.
$$2^2$$

$2^2$

\\(2^2\\)

[2^2]
2012-10-21 17:15:09 -06:00
bootstraponline f68bebe0f6 Update math note 2012-10-21 16:26:35 -06:00
bootstraponline 4c6019b439 Update math note 2012-10-21 16:23:58 -06:00
bootstraponline 66e08a6b17 Release 2.3.0 2012-10-21 16:19:05 -06:00
bootstraponline 7898db70ed Auto load all MathJax extensions
Fix #549
2012-10-21 16:14:04 -06:00
bootstraponline 7c357116ff Remove TeX
As discussed with @vmg
MathJax is available via a flag for those self hosting gollum
2012-10-18 23:36:05 -06:00
bootstraponline 69ce0eb0d0 Update rake 2012-10-17 21:04:20 -06:00
bootstraponline 4db31a297b Update rake
Jekyll uses rake ~> 0.9
2012-10-17 21:03:29 -06:00
bootstraponline e1fca457e4 Restore gemnasium
Gemnasium fixed the missing pygments.rb issue.

https://github.com/laserlemon/gemnasium-parser/commit/c9b3e43c3021967d5c1bb115e7dd1555e01c6444
2012-10-17 20:54:01 -06:00
bootstraponline 7f8485ce80 Improve system requirements language 2012-10-16 22:31:25 -06:00
bootstraponline 290061fd11 Add system requirements to readme 2012-10-16 22:15:26 -06:00
bootstraponline a507836936 Update dependencies 2012-10-16 21:39:22 -06:00
bootstraponline 6524d20a96 Use pygments.rb 0.3.2 2012-10-16 21:36:37 -06:00
bootstraponline f1c523aa30 Release 2.2.9 2012-10-14 22:26:17 -06:00
bootstraponline 87c08f5613 Escape " in headers 2012-10-14 22:21:00 -06:00
bootstraponline 82913cea20 Improve base path note 2012-10-14 21:42:25 -06:00
bootstraponline 2ad743e4bd Release 2.2.8 2012-10-14 21:28:43 -06:00
bootstraponline fa97b57a96 Define default map as suggested on #460
Base path now sets a default map without having to use an external config.ru.
2012-10-14 20:57:27 -06:00
bootstraponline 1b952b6d56 Release 2.2.7 2012-10-14 17:24:33 -06:00
bootstraponline 90cc512bd1 Fix home loop with page-file-dir #491 2012-10-14 15:45:26 -06:00
bootstraponline b82556c9c0 Fix #460 2012-10-14 15:42:06 -06:00
bootstraponline fbe3b4bb3b Fix #460 2012-10-14 15:23:52 -06:00
bootstraponline 5ffd98ad31 Fix #491 2012-10-14 15:15:55 -06:00
bootstraponline cb9dd4d228 Fix formatting 2012-10-14 14:31:40 -06:00
bootstraponline cd823bf10c Add doc from wiki.rb 2012-10-14 14:31:00 -06:00
bootstraponline 5560ec52c2 Add base_path doc 2012-10-14 14:27:08 -06:00
bootstraponline 065151a77f Add base_path disclaimer 2012-10-14 14:25:27 -06:00
bootstraponline 23454f556c Release 2.2.6 2012-10-14 13:14:08 -06:00
bootstraponline a2b3ddf931 Update tests to XHTML 2012-10-14 13:07:18 -06:00
bootstraponline 44b0d2fcfc Remove old comment 2012-10-14 12:26:23 -06:00
bootstraponline aed4cc590a Fix unicode characters
Fix #547

Update test
2012-10-14 12:21:31 -06:00
bootstraponline 72ee08b5ab Release 2.2.5 2012-10-14 11:21:56 -06:00
bootstraponline 45547624e4 Improve tilde fence support
More than 3 tildes can be used. The code block must end with the same amount of tildes used to open the code block.

Fix #537

http://johnmacfarlane.net/pandoc/README.html#delimited-code-blocks
2012-10-14 11:02:45 -06:00
bootstraponline f928cfa8be Don't ship Lorem ipsum in gem 2012-10-13 20:21:08 -06:00
bootstraponline 988984846a Release 2.2.4 2012-10-13 20:01:57 -06:00
bootstraponline 1149618653 Fix #537 2012-10-13 19:53:41 -06:00
bootstraponline 168a033903 Remove old comment 2012-10-13 14:59:42 -06:00
bootstraponline 6a765c9791 Fix #537 2012-10-13 14:52:28 -06:00
bootstraponline e16ae7b511 Travis is having a bad day
E: There are problems and -y was used without --force-yes
before_install: 'sudo apt-get install -y asciidoc' returned false.
Done. Build script exited with: 1
2012-10-13 14:07:15 -06:00
bootstraponline 174334ea44 Remove comment 2012-10-13 13:58:56 -06:00
bootstraponline dbdf06930d Fix 2012-10-13 13:55:20 -06:00
bootstraponline c93e65ddc3 Merge branch 'master' of github.com:github/gollum 2012-10-13 13:32:19 -06:00
bootstraponline 56101ed264 Fix #535 and add test 2012-10-13 13:32:08 -06:00
bootstraponline 8269c8e574 TOC doesn't require ' 2012-10-13 13:11:31 -06:00
bootstraponline 2246419d1e Fix spacing 2012-10-13 13:09:20 -06:00
bootstraponline 118a0c318b Update comment 2012-10-13 13:06:15 -06:00
bootstraponline 5401cf2910 Fix #542 2012-10-13 13:04:51 -06:00
bootstraponline 432f9b8d2f Add test for #542 2012-10-13 12:57:58 -06:00
bootstraponline 66fc8a2d31 Revert "Fix #542"
This reverts commit 2f3dd3d227.
2012-10-13 12:55:43 -06:00
bootstraponline 2f3dd3d227 Fix #542
Page link may contain duplicate starting forward slashes.
//page points to http://page/ when what we want is
/page pointing to http://localhost:1234/page
2012-10-13 09:53:25 -06:00
bootstraponline c43fd9fa6c Update language comment 2012-10-12 21:19:24 -06:00
bootstraponline 868518e0f5 Bash is Ace mode sh 2012-10-12 20:58:05 -06:00
bootstraponline 039b5cce98 Try to fix Travis
FFI is no longer used in the new pygments.rb.
apt-get update may resolve the asciidoc install failure.
2012-10-12 20:24:31 -06:00
bootstraponline 4a421842d5 https://github.com/travis-ci/travis-ci/issues/725
Modified README to trigger a Travis CI build. It's currently broken.
2012-10-12 20:22:10 -06:00
bootstraponline cfbb124f81 Update README.md 2012-10-12 20:16:43 -06:00
bootstraponline dcb147cde2 Ensure declaredLanguage is lower case 2012-10-10 20:20:33 -06:00
bootstraponline 8d06b5e67e Fix pygments language to Ace mode translation 2012-10-10 20:16:04 -06:00
bootstraponline 4776d0b422 Use rake release in readme 2012-10-10 19:45:42 -06:00
bootstraponline 58bb340c33 Release 2.2.3 2012-10-10 19:43:30 -06:00
bootstraponline ee790a9b7c Add rake bump to readme 2012-10-10 19:38:53 -06:00
bootstraponline ac432aad78 Add bump task to Rakefile 2012-10-10 19:35:04 -06:00
bootstraponline 30207e0a39 Merge pull request #533 from wrs/wrs_syntaxfixes
Two little syntax highlighting fixes
2012-10-10 16:56:37 -07:00
Walter Smith d98547a33c Fix lack of CoffeeScript livepreview
Pygments calls it coffeescript, but Ace calls it coffee.
2012-10-10 14:20:50 -07:00
Walter Smith b7cdeabbf6 Catch all Pygments errors
An unrecognized language was generating a MentosError rather than a
PythonError. Just catch anything that goes wrong in Pygments.
2012-10-10 14:20:50 -07:00
33 changed files with 500 additions and 190 deletions
+2 -2
View File
@@ -4,5 +4,5 @@ rvm:
notifications: notifications:
disabled: true disabled: true
before_install: before_install:
- gem uninstall ffi -a - sudo apt-get update
- sudo apt-get install -y asciidoc - sudo apt-get install -y --force-yes asciidoc
+2 -2
View File
@@ -1,4 +1,4 @@
source "http://rubygems.org" source 'http://rubygems.org'
gemspec gemspec
gem "rake", "~> 0.9.2.2" gem 'rake', '~> 0.9'
+31 -20
View File
@@ -2,6 +2,7 @@ gollum -- A wiki built on top of Git
==================================== ====================================
[![Build Status](https://secure.travis-ci.org/github/gollum.png?branch=master)](http://travis-ci.org/github/gollum) [![Build Status](https://secure.travis-ci.org/github/gollum.png?branch=master)](http://travis-ci.org/github/gollum)
[![Dependency Status](https://gemnasium.com/github/gollum.png)](https://gemnasium.com/github/gollum)
## DESCRIPTION ## DESCRIPTION
@@ -18,6 +19,11 @@ number of ways depending on your needs. You can edit your wiki locally:
Gollum follows the rules of [Semantic Versioning](http://semver.org/) and uses Gollum follows the rules of [Semantic Versioning](http://semver.org/) and uses
[TomDoc](http://tomdoc.org/) for inline documentation. [TomDoc](http://tomdoc.org/) for inline documentation.
## SYSTEM REQUIREMENTS
- Python 2.5+ (2.7.3 recommended)
- Ruby 1.8.7+ (1.9.3 recommended)
- Unix like operating system (OS X, Ubuntu, Debian, and more)
- Will not work on Windows (because of [grit](https://github.com/github/grit))
## INSTALLATION ## INSTALLATION
@@ -295,7 +301,7 @@ This is useful for writing about the link syntax in your wiki pages.
Gollum has a special tag to insert a table of contents (new in v2.1) Gollum has a special tag to insert a table of contents (new in v2.1)
'[[_TOC_]] [[_TOC_]]
This tag is case sensitive, use all upper case. The TOC tag can be inserted This tag is case sensitive, use all upper case. The TOC tag can be inserted
into the `_Header`, `_Footer` or `_Sidebar` files too. into the `_Header`, `_Footer` or `_Sidebar` files too.
@@ -357,25 +363,17 @@ appropriately.
## MATHEMATICAL EQUATIONS ## 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.
Page files may contain mathematic equations in TeX syntax that will be nicely Inline math:
typeset into the expected output. A block-style equation is delimited by `\[`
and `\]`. For example:
\[ P(E) = {n \choose k} p^k (1-p)^{ n-k} \] - $2^2$
- `\\(2^2\\)`
Inline equations are delimited by `\(` and `\)`. These equations will appear Display math:
inline with regular text. For example:
The Pythagorean theorem is \( a^2 + b^2 = c^2 \). - $$2^2$$
- [2^2]
### INSTALLATION REQUIREMENTS
In order to get the mathematical equations rendering to work, you need the following binaries:
* LaTex, TeTex or MacTex/BasicTeX (pdflatex)
* Netpbm (pnmcrop, pnmpad, pnmscale, ppmtopgm, pnmgamma, pnmtopng)
* Ghostscript (gs)
## SEQUENCE DIAGRAMS ## SEQUENCE DIAGRAMS
@@ -413,6 +411,17 @@ By default, internal wiki links are all absolute from the root. To specify a dif
wiki = Gollum::Wiki.new("my-gollum-repo.git", :base_path => "/wiki") wiki = Gollum::Wiki.new("my-gollum-repo.git", :base_path => "/wiki")
Note that base_path just modifies the links. To map gollum to a non-root location:
- Use the gollum binary: `gollum path/to/wiki --base-path mywiki`
- Define config.ru with `map`. See [#532](https://github.com/github/gollum/issues/532) for an example.
> :base_path - String base path for all Wiki links.
>
> The String base path to prefix to internal links. For example, when set
> to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults
> to "/".
Get the latest version of the given human or canonical page name: Get the latest version of the given human or canonical page name:
page = wiki.page('page-name') page = wiki.page('page-name')
@@ -547,12 +556,14 @@ your changes merged back into core is as follows:
1. Send a pull request to the github/gollum project. 1. Send a pull request to the github/gollum project.
## RELEASING ## RELEASING
For z releases:
$ rake bump
$ rake release
For x.y releases:
Update VERSION in lib/gollum.rb Update VERSION in lib/gollum.rb
$ rake gemspec $ rake gemspec
$ git tag vX.Y.Z $ rake release
$ git push origin vX.Y.Z
$ gem build gollum.gemspec
$ gem push gollum-X.Y.Z.gem
## BUILDING THE GEM FROM MASTER ## BUILDING THE GEM FROM MASTER
$ gem uninstall -aIx gollum $ gem uninstall -aIx gollum
+31 -2
View File
@@ -17,6 +17,27 @@ def version
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1] line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end end
# assumes x.y.z all digit version
def next_version
# x.y.z
v = version.split '.'
# bump z
v[-1] = v[-1].to_i + 1
v.join '.'
end
def bump_version
old_file = File.read("lib/#{name}.rb")
old_version_line = old_file[/^\s*VERSION\s*=\s*.*/]
new_version = next_version
# replace first match of old vesion with new version
old_file.sub!(old_version_line, " VERSION = '#{new_version}'")
File.write("lib/#{name}.rb", old_file)
new_version
end
def date def date
Date.today.to_s Date.today.to_s
end end
@@ -71,7 +92,14 @@ end
# #
############################################################################# #############################################################################
desc "Update version number and gemspec"
task :bump do
puts "Updated version to #{bump_version}"
# Execute does not invoke dependencies.
# Manually invoke gemspec then validate.
Rake::Task[:gemspec].execute
Rake::Task[:validate].execute
end
############################################################################# #############################################################################
# #
@@ -86,6 +114,7 @@ task :release => :build do
exit! exit!
end end
sh "git commit --allow-empty -a -m 'Release #{version}'" sh "git commit --allow-empty -a -m 'Release #{version}'"
sh "git pull"
sh "git tag v#{version}" sh "git tag v#{version}"
sh "git push origin master" sh "git push origin master"
sh "git push origin v#{version}" sh "git push origin v#{version}"
@@ -117,7 +146,7 @@ task :gemspec => :validate do
split("\n"). split("\n").
sort. sort.
reject { |file| file =~ /^\./ }. reject { |file| file =~ /^\./ }.
reject { |file| file =~ /^(rdoc|pkg|test)/ }. reject { |file| file =~ /^(rdoc|pkg|test|Home\.md)/ }.
map { |file| " #{file}" }. map { |file| " #{file}" }.
join("\n") join("\n")
+35 -1
View File
@@ -68,6 +68,14 @@ opts = OptionParser.new do |opts|
opts.on("--mathjax", "Enables mathjax.") do opts.on("--mathjax", "Enables mathjax.") do
wiki_options[:mathjax] = true wiki_options[:mathjax] = true
end end
opts.on("--show-all", "Shows all files in file view. By default only valid pages are shown.") do
wiki_options[:show_all] = true
end
opts.on("--collapse-tree", "Collapse file view tree. By default, expanded tree is shown.") do
wiki_options[:collapse_tree] = true
end
end end
# Read command line options into `options` hash # Read command line options into `options` hash
@@ -141,5 +149,31 @@ else
require cfg require cfg
end end
Precious::App.run!(options) base_path = wiki_options[:base_path]
if wiki_options[:base_path].nil?
Precious::App.run!(options)
else
require 'rack'
class MapGollum
def initialize base_path
@mg = Rack::Builder.new do
map '/' do
run Proc.new { [ 302, {'Location'=> "/#{base_path}" }, [] ] }
end
map "/#{base_path}" do
run Precious::App
end
end
end
def call(env)
@mg.call(env)
end
end
# Rack::Handler does not work with Ctrl + C. Use Rack::Server instead.
Rack::Server.new(:app => MapGollum.new(base_path), :Port => options['port']).start
end
end end
+13 -12
View File
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 1.8.7" s.required_ruby_version = ">= 1.8.7"
s.name = 'gollum' s.name = 'gollum'
s.version = '2.2.2' s.version = '2.3.4'
s.date = '2012-10-04' s.date = '2012-10-28'
s.rubyforge_project = 'gollum' s.rubyforge_project = 'gollum'
s.summary = "A simple, Git-powered wiki." s.summary = "A simple, Git-powered wiki."
@@ -26,28 +26,29 @@ Gem::Specification.new do |s|
s.add_dependency('grit', '~> 2.5.0') s.add_dependency('grit', '~> 2.5.0')
s.add_dependency('github-markup', ['>= 0.7.4', '< 1.0.0']) s.add_dependency('github-markup', ['>= 0.7.4', '< 1.0.0'])
s.add_dependency('github-markdown', '~> 0.5.1') s.add_dependency('github-markdown', '~> 0.5.1')
s.add_dependency('pygments.rb', '~> 0.3.1') s.add_dependency('pygments.rb', '~> 0.3.2')
s.add_dependency('escape_utils', '0.2.4')
s.add_dependency('sinatra', '~> 1.3.3') s.add_dependency('sinatra', '~> 1.3.3')
s.add_dependency('mustache', ['>= 0.99.4', '< 1.0.0']) s.add_dependency('mustache', ['>= 0.99.4', '< 1.0.0'])
s.add_dependency('sanitize', '~> 2.0.3') s.add_dependency('sanitize', '~> 2.0.3')
s.add_dependency('nokogiri', '~> 1.5.5') s.add_dependency('nokogiri', '~> 1.5.5')
s.add_dependency('useragent', '~> 0.4.10') s.add_dependency('useragent', '~> 0.4.12')
s.add_dependency('stringex', '~> 1.4.0') s.add_dependency('stringex', '~> 1.4.0')
s.add_development_dependency('RedCloth', '~> 4.2.9') s.add_development_dependency('RedCloth', '~> 4.2.9')
s.add_development_dependency('mocha', '~> 0.12.6') s.add_development_dependency('mocha', '~> 0.12.7')
s.add_development_dependency('org-ruby', '~> 0.7.1') s.add_development_dependency('org-ruby', '~> 0.7.2')
s.add_development_dependency('shoulda', '~> 3.1.1') s.add_development_dependency('shoulda', '~> 3.3.1')
s.add_development_dependency('rack-test', '~> 0.6.2') s.add_development_dependency('rack-test', '~> 0.6.2')
s.add_development_dependency('wikicloth', '~> 0.8.0') s.add_development_dependency('wikicloth', '~> 0.8.0')
s.add_development_dependency('rake', '~> 0.9.2.2') s.add_development_dependency('rake', '~> 0.9')
s.add_development_dependency('pry', '~> 0.9.10')
# required by pry
s.add_development_dependency('rb-readline', '~> 0.4.2')
# = MANIFEST = # = MANIFEST =
s.files = %w[ s.files = %w[
Gemfile Gemfile
HISTORY.md HISTORY.md
Home.md
LICENSE LICENSE
README.md README.md
Rakefile Rakefile
@@ -94,6 +95,7 @@ Gem::Specification.new do |s|
lib/gollum/frontend/public/gollum/javascript/mousetrap.min.js lib/gollum/frontend/public/gollum/javascript/mousetrap.min.js
lib/gollum/frontend/public/gollum/livepreview/css/custom.css lib/gollum/frontend/public/gollum/livepreview/css/custom.css
lib/gollum/frontend/public/gollum/livepreview/images/cancel_24.png lib/gollum/frontend/public/gollum/livepreview/images/cancel_24.png
lib/gollum/frontend/public/gollum/livepreview/images/globe_24.png
lib/gollum/frontend/public/gollum/livepreview/images/lr_24.png lib/gollum/frontend/public/gollum/livepreview/images/lr_24.png
lib/gollum/frontend/public/gollum/livepreview/images/save_24.png lib/gollum/frontend/public/gollum/livepreview/images/save_24.png
lib/gollum/frontend/public/gollum/livepreview/images/savecomment_24.png lib/gollum/frontend/public/gollum/livepreview/images/savecomment_24.png
@@ -459,7 +461,6 @@ Gem::Specification.new do |s|
lib/gollum/page.rb lib/gollum/page.rb
lib/gollum/pagination.rb lib/gollum/pagination.rb
lib/gollum/sanitization.rb lib/gollum/sanitization.rb
lib/gollum/tex.rb
lib/gollum/web_sequence_diagram.rb lib/gollum/web_sequence_diagram.rb
lib/gollum/wiki.rb lib/gollum/wiki.rb
licenses/css_tree_menu_thecssninja/license.txt licenses/css_tree_menu_thecssninja/license.txt
@@ -471,4 +472,4 @@ Gem::Specification.new do |s|
# = MANIFEST = # = MANIFEST =
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ } s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
end end
+2 -2
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
# stdlib # stdlib
require 'digest/md5' require 'digest/md5'
require 'ostruct' require 'ostruct'
@@ -18,12 +19,11 @@ require File.expand_path('../gollum/file', __FILE__)
require File.expand_path('../gollum/file_view', __FILE__) require File.expand_path('../gollum/file_view', __FILE__)
require File.expand_path('../gollum/markup', __FILE__) require File.expand_path('../gollum/markup', __FILE__)
require File.expand_path('../gollum/sanitization', __FILE__) require File.expand_path('../gollum/sanitization', __FILE__)
require File.expand_path('../gollum/tex', __FILE__)
require File.expand_path('../gollum/web_sequence_diagram', __FILE__) require File.expand_path('../gollum/web_sequence_diagram', __FILE__)
require File.expand_path('../gollum/frontend/uri_encode_component', __FILE__) require File.expand_path('../gollum/frontend/uri_encode_component', __FILE__)
module Gollum module Gollum
VERSION = '2.2.2' VERSION = '2.3.4'
def self.assets_path def self.assets_path
::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__)) ::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__))
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class BlobEntry class BlobEntry
# Gets the String SHA for this blob. # Gets the String SHA for this blob.
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
# Responsible for handling the commit process for a Wiki. It sets up the # Responsible for handling the commit process for a Wiki. It sets up the
# Git index, provides methods for modifying the tree, and stores callbacks # Git index, provides methods for modifying the tree, and stores callbacks
+17
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class File class File
Wiki.file_class = self Wiki.file_class = self
@@ -13,6 +14,22 @@ module Gollum
@path = nil @path = nil
end end
# Public: The url path required to reach this page within the repo.
#
# Returns the String url_path
def url_path
path = self.path
path = path.sub(/\/[^\/]+$/, '/') if path.include?('/')
path
end
# Public: The url_path, but CGI escaped.
#
# Returns the String url_path
def escaped_url_path
CGI.escape(self.url_path).gsub('%2F','/')
end
# Public: The on-disk filename of the file. # Public: The on-disk filename of the file.
# #
# Returns the String name. # Returns the String name.
+19 -4
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
=begin =begin
FileView requires that: FileView requires that:
@@ -5,8 +6,13 @@ module Gollum
- Then all the folders are sorted and processed - Then all the folders are sorted and processed
=end =end
class FileView class FileView
def initialize pages # common use cases:
# set pages to wiki.pages and show_all to false
# set pages to wiki.pages + wiki.files and show_all to true
def initialize pages, options = {}
@pages = pages @pages = pages
@show_all = options[:show_all] || false
@checked = options[:collapse_tree] ? '' : "checked"
end end
def enclose_tree string def enclose_tree string
@@ -26,7 +32,7 @@ module Gollum
def new_sub_folder path def new_sub_folder path
<<-HTML <<-HTML
<li> <li>
<label>#{path}</label> <input type="checkbox" checked /> <label>#{path}</label> <input type="checkbox" #{@checked} />
<ol> <ol>
HTML HTML
end end
@@ -39,7 +45,16 @@ module Gollum
end end
def url_for_page page def url_for_page page
url = ::File.join(::File.dirname(page.path), page.filename_stripped) url = ''
if @show_all
# Remove ext for valid pages.
filename = page.filename
filename = Page::valid_page_name?(filename) ? filename.chomp(::File.extname(filename)) : filename
url = ::File.join(::File.dirname(page.path), filename)
else
url = ::File.join(::File.dirname(page.path), page.filename_stripped)
end
url = url[2..-1] if url[0,2] == './' url = url[2..-1] if url[0,2] == './'
url url
end end
@@ -74,7 +89,7 @@ module Gollum
url = url_for_page page url = url_for_page page
html += <<-HTML html += <<-HTML
<li> <li>
<label>#{::File.dirname(page.path)}</label> <input type="checkbox" checked /> <label>#{::File.dirname(page.path)}</label> <input type="checkbox" #{@checked} />
<ol> <ol>
<li class="file"><a href="#{url}">#{name}</a></li> <li class="file"><a href="#{url}">#{name}</a></li>
</ol> </ol>
+24 -9
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'cgi' require 'cgi'
require 'sinatra' require 'sinatra'
require 'gollum' require 'gollum'
@@ -82,11 +83,12 @@ module Precious
before do before do
@base_url = url('/', false).chomp('/') @base_url = url('/', false).chomp('/')
settings.wiki_options.merge!({ :base_path => @base_url }) unless settings.wiki_options.has_key? :base_path # above will detect base_path when it's used with map in a config.ru
settings.wiki_options.merge!({ :base_path => @base_url })
end end
get '/' do get '/' do
redirect File.join(settings.wiki_options[:base_path].to_s, 'Home') redirect ::File.join(@base_url, 'Home')
end end
# path is set to name if path is nil. # path is set to name if path is nil.
@@ -145,6 +147,7 @@ module Precious
page_name = CGI.unescape(params[:page]) page_name = CGI.unescape(params[:page])
wiki = wiki_new wiki = wiki_new
page = wiki.paged(page_name, path, exact = true) page = wiki.paged(page_name, path, exact = true)
return if page.nil?
rename = params[:rename].to_url if params[:rename] rename = params[:rename].to_url if params[:rename]
name = rename || page.name name = rename || page.name
committer = Gollum::Committer.new(wiki, commit_message) committer = Gollum::Committer.new(wiki, commit_message)
@@ -186,17 +189,20 @@ module Precious
post '/create' do post '/create' do
name = params[:page].to_url name = params[:page].to_url
path = sanitize_empty_params(params[:path]) path = sanitize_empty_params(params[:path]) || ''
path = '' if path.nil?
format = params[:format].intern format = params[:format].intern
# ensure pages are created in page_file_dir
page_dir = settings.wiki_options[:page_file_dir].to_s
path = clean_url(::File.join(page_dir, path)) unless path.start_with?(page_dir)
# write_page is not directory aware so use wiki_options to emulate dir support. # write_page is not directory aware so use wiki_options to emulate dir support.
wiki_options = settings.wiki_options.merge({ :page_file_dir => path }) wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
begin begin
wiki.write_page(name, format, params[:content], commit_message) wiki.write_page(name, format, params[:content], commit_message)
redirect to("/#{clean_url(CGI.escape(::File.join(path,name)))}") redirect to("/#{clean_url(::File.join(path,name))}")
rescue Gollum::DuplicatePageError => e rescue Gollum::DuplicatePageError => e
@message = "Duplicate page: #{e.message}" @message = "Duplicate page: #{e.message}"
mustache :error mustache :error
@@ -315,13 +321,21 @@ module Precious
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path }) wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
@results = wiki.pages @results = wiki.pages
@results += wiki.files if settings.wiki_options[:show_all]
@ref = wiki.ref @ref = wiki.ref
mustache :pages mustache :pages
end end
get '/fileview' do get '/fileview' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) wiki = wiki_new
@results = Gollum::FileView.new(wiki.pages).render_files options = settings.wiki_options
content = wiki.pages
# if showing all files include wiki.files
content += wiki.files if options[:show_all]
# must pass wiki_options to FileView
# --show-all and --collapse-tree can be set.
@results = Gollum::FileView.new(content, options).render_files
@ref = wiki.ref @ref = wiki.ref
mustache :file_view, { :layout => false } mustache :file_view, { :layout => false }
end end
@@ -332,10 +346,11 @@ module Precious
def show_page_or_file(fullpath) def show_page_or_file(fullpath)
name = extract_name(fullpath) name = extract_name(fullpath)
path = extract_path(fullpath) path = extract_path(fullpath) || '/'
wiki = wiki_new wiki = wiki_new
path = '/' if path.nil? page_dir = settings.wiki_options[:page_file_dir].to_s
path = ::File.join(page_dir, path) unless path.start_with?(page_dir)
if page = wiki.paged(name, path, exact = true) if page = wiki.paged(name, path, exact = true)
@page = page @page = page
+10 -1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Precious module Precious
module Helpers module Helpers
# Extract the path string that Gollum::Wiki expects # Extract the path string that Gollum::Wiki expects
@@ -19,9 +20,17 @@ module Precious
end end
# Remove all slashes from the start of string. # Remove all slashes from the start of string.
# Remove all double slashes
def clean_url url def clean_url url
return url if url.nil? return url if url.nil?
url.gsub('%2F','/').gsub(/^\/+/,'') url.gsub('%2F','/').gsub(/^\/+/,'').gsub('//','/')
end
def trim_leading_slash url
return url if url.nil?
url.gsub!('%2F','/')
return '/' + url.gsub(/^\/+/,'') if url[0,1] == '/'
url
end end
end end
end end
Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

@@ -11,6 +11,7 @@
<div id='previewframe'><div id='contentframe' class='markdown-body'></div></div> <div id='previewframe'><div id='contentframe' class='markdown-body'></div></div>
<!-- tool panel from notepage.es. save & savecomment icons from Retina Display Icon Set. --> <!-- tool panel from notepage.es. save & savecomment icons from Retina Display Icon Set. -->
<div id='toolpanel' class='toolpanel edit' style='width: 500px; right: 0px; visibility: hidden;'> <div id='toolpanel' class='toolpanel edit' style='width: 500px; right: 0px; visibility: hidden;'>
<a id='preview' class='edit'><img src='images/globe_24.png' alt='Preview' title='Preview'></a>
<a id='save' class='edit'><img src='images/save_24.png' alt='Save' title='Save'></a> <a id='save' class='edit'><img src='images/save_24.png' alt='Save' title='Save'></a>
<a id='savecomment' class='edit'><img src='images/savecomment_24.png' alt='Save with comment' title='Save with comment'></a> <a id='savecomment' class='edit'><img src='images/savecomment_24.png' alt='Save with comment' title='Save with comment'></a>
<a id='toggle' class='edit' href='javascript:void(0)' onclick='jsm.toggleLeftRight();'><img src='images/lr_24.png' alt='Toggle left to right' title='Toggle left to right'></a> <a id='toggle' class='edit' href='javascript:void(0)' onclick='jsm.toggleLeftRight();'><img src='images/lr_24.png' alt='Toggle left to right' title='Toggle left to right'></a>
@@ -87,6 +87,18 @@ defaultCommitMessage = function() {
// Set comment using the default commit message. // Set comment using the default commit message.
commentEditorSession.setValue( defaultCommitMessage() ); commentEditorSession.setValue( defaultCommitMessage() );
$.preview = function( previewWindow ) {
jQuery.ajax( {
type: 'POST',
url: baseUrl + '/preview',
data: { page: 'Preview: ' + pageName, format: 'markdown', content: editorSession.getValue() },
success: function( html ) {
previewWindow.document.write( html );
previewWindow.focus();
}
});
}
$.save = function( commitMessage ) { $.save = function( commitMessage ) {
win.onbeforeunload = null; win.onbeforeunload = null;
@@ -194,13 +206,14 @@ var previewSet = function( text ) {
} }
}; };
// 'c', 'c++', 'cpp' are github specific and transformed to c_cpp for Ace. // See pygmentsLanguageToAceMode for pygment to ace mode translations.
var languages = [ 'c', 'c++', 'cpp', 'clojure', 'coffee', 'coldfusion', // TODO: Update languages and translation once Ace is upgraded to v1.0.
'csharp', 'css', 'diff', 'golang', 'groovy', 'haxe', 'html', var languages = [ 'c', 'c++', 'cpp', 'clojure', 'coffee',
'java', 'javascript', 'json', 'latex', 'less', 'liquid', 'coffeescript', 'coldfusion', 'csharp', 'css', 'diff', 'golang',
'lua', 'markdown', 'ocaml', 'perl', 'pgsql', 'php', 'powershell', 'groovy', 'haxe', 'html', 'java', 'javascript', 'json', 'latex',
'python', 'ruby', 'scad', 'scala', 'scss', 'sh', 'sql', 'svg', 'less', 'liquid', 'lua', 'markdown', 'ocaml', 'perl', 'pgsql', 'php',
'textile', 'text', 'xml', 'xquery', 'yaml' ]; 'powershell', 'python', 'ruby', 'scad', 'scala', 'scss', 'sh', 'sql',
'svg', 'textile', 'text', 'xml', 'xquery', 'yaml' ];
var staticHighlight = require( 'ace/ext/static_highlight' ); var staticHighlight = require( 'ace/ext/static_highlight' );
var githubTheme = require( 'ace/theme/github' ); var githubTheme = require( 'ace/theme/github' );
@@ -243,6 +256,31 @@ function highlight( element, language ) {
element.parentNode.parentNode.replaceChild( newDiv, element.parentNode ); element.parentNode.parentNode.replaceChild( newDiv, element.parentNode );
} }
// Pygments and Ace have different names for languages.
function pygmentsLanguageToAceMode( declaredLanguage ) {
declaredLanguage = declaredLanguage.toLowerCase();
switch ( declaredLanguage ) {
case 'bash':
return 'sh';
case 'c':
case 'c++':
case 'cpp':
case 'objective-c':
return 'c_cpp';
case 'c#':
return 'csharp';
case 'coffeescript':
return 'coffee';
case 'html+erb':
return 'html'
}
// Assume language name is the same
// if it's not handled above.
return declaredLanguage;
}
var makePreviewHtml = function () { var makePreviewHtml = function () {
var text = editorSession.getValue(); var text = editorSession.getValue();
@@ -293,15 +331,7 @@ var makePreviewHtml = function () {
// the syntax for code highlighting means all code, even one line, contains newlines. // the syntax for code highlighting means all code, even one line, contains newlines.
if ( txt.length > 1 && codeHTML.match( /\n/ ) ) { if ( txt.length > 1 && codeHTML.match( /\n/ ) ) {
var declaredLanguage = element.className.toLowerCase(); var declaredLanguage = element.className.toLowerCase();
var aceMode = declaredLanguage; var aceMode = pygmentsLanguageToAceMode( declaredLanguage );
// GitHub supports 'c', 'c++', 'cpp'
// which must trigger the 'c_cpp' mode in Ace.
if ( declaredLanguage === 'c' ||
declaredLanguage === 'c++' ||
declaredLanguage === 'cpp' ) {
aceMode = 'c_cpp';
}
if ( $.inArray( declaredLanguage, languages ) === -1 ) { if ( $.inArray( declaredLanguage, languages ) === -1 ) {
// Unsupported language. // Unsupported language.
@@ -359,8 +389,16 @@ var applyTimeout = function () {
}); });
} }
$( '#preview' ).click( function() {
$(this).target = "_blank";
// pass window into preview
$.preview( window.open() );
return false;
});
$( '#save' ).click( function() { $( '#save' ).click( function() {
$.save(); $.save();
return false;
}); });
// Hide dimmer, comment tool panel, and comment. // Hide dimmer, comment tool panel, and comment.
@@ -15,7 +15,10 @@ CC BY-SA 3.0 Unported
http://blog.twg.ca/2010/11/retina-display-icon-set/ http://blog.twg.ca/2010/11/retina-display-icon-set/
http://creativecommons.org/licenses/by-sa/3.0/legalcode.txt http://creativecommons.org/licenses/by-sa/3.0/legalcode.txt
lib/gollum/frontend/public/images/savecomment_24.png
lib/gollum/frontend/public/images/cancel_24.png
lib/gollum/frontend/public/images/save_24.png lib/gollum/frontend/public/images/save_24.png
lib/gollum/frontend/public/images/globe_24.png
--- ---
+11 -1
View File
@@ -18,7 +18,17 @@
<script type="text/javascript" src="{{base_url}}/javascript/gollum.dialog.js"></script> <script type="text/javascript" src="{{base_url}}/javascript/gollum.dialog.js"></script>
<script type="text/javascript" src="{{base_url}}/javascript/gollum.placeholder.js"></script> <script type="text/javascript" src="{{base_url}}/javascript/gollum.placeholder.js"></script>
<script type="text/javascript" src="{{base_url}}/javascript/editor/gollum.editor.js"></script> <script type="text/javascript" src="{{base_url}}/javascript/editor/gollum.editor.js"></script>
{{#mathjax}}<script>(function(d,j){ {{#mathjax}}
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)']],
displayMath: [ ['$$','$$'], ['\[','\]'] ],
processEscapes: true
},
TeX: { extensions: ["autoload-all.js"] }});
</script>
<script>(function(d,j){
j = d.createElement('script'); j = d.createElement('script');
j.src = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'; j.src = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
(d.head || d.getElementsByTagName('head')[0]).appendChild(j); (d.head || d.getElementsByTagName('head')[0]).appendChild(j);
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
# Controls all access to the Git objects from Gollum. Extend this class to # Controls all access to the Git objects from Gollum. Extend this class to
# add custom caching for special cases. # add custom caching for special cases.
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'net/http' require 'net/http'
require 'net/https' # ruby 1.8.7 fix, remove at upgrade require 'net/https' # ruby 1.8.7 fix, remove at upgrade
require 'uri' require 'uri'
+52 -57
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'digest/sha1' require 'digest/sha1'
require 'cgi' require 'cgi'
require 'pygments' require 'pygments'
@@ -33,11 +34,11 @@ module Gollum
@dir = ::File.dirname(page.path) @dir = ::File.dirname(page.path)
@tagmap = {} @tagmap = {}
@codemap = {} @codemap = {}
@texmap = {}
@wsdmap = {} @wsdmap = {}
@premap = {} @premap = {}
@toc = nil @toc = nil
@metadata = nil @metadata = nil
@to_xml = { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' }
end end
# Render the content with Gollum wiki syntax on top of the file's own # Render the content with Gollum wiki syntax on top of the file's own
@@ -57,7 +58,6 @@ module Gollum
data = extract_metadata(data) data = extract_metadata(data)
data = extract_gitcode(data) data = extract_gitcode(data)
data = extract_code(data) data = extract_code(data)
data = extract_tex(data)
data = extract_wsd(data) data = extract_wsd(data)
data = extract_tags(data) data = extract_tags(data)
begin begin
@@ -76,14 +76,18 @@ module Gollum
doc,toc = process_headers(doc) doc,toc = process_headers(doc)
@toc = @sub_page ? ( @parent_page ? @parent_page.toc_data : "[[_TOC_]]" ) : toc @toc = @sub_page ? ( @parent_page ? @parent_page.toc_data : "[[_TOC_]]" ) : toc
yield doc if block_given? yield doc if block_given?
data = doc.to_html # nokogiri's save options are ored together. FORMAT has a value of 1 so ^ 1 removes it.
# formatting will create extra spaces in pre tags.
# https://github.com/sparklemotion/nokogiri/issues/782
# DEFAULT_HTML encodes unicode so XHTML is used for proper unicode support in href.
data = doc.to_xml( @to_xml )
data = process_toc_tags(data) data = process_toc_tags(data)
data = process_tex(data)
data = process_wsd(data) data = process_wsd(data)
data.gsub!(/<p><\/p>/) do data.gsub!(/<p><\/p>/) do
'' ''
end end
data data
end end
@@ -95,16 +99,13 @@ module Gollum
def process_headers(doc) def process_headers(doc)
toc = nil toc = nil
doc.css('h1,h2,h3,h4,h5,h6').each do |h| doc.css('h1,h2,h3,h4,h5,h6').each do |h|
id = encodeURIComponent(h.content.gsub(' ','-')) # must escape "
h_name = h.content.gsub(' ','-').gsub('"','%22')
level = h.name.gsub(/[hH]/,'').to_i level = h.name.gsub(/[hH]/,'').to_i
# Add anchors # Add anchors
anchor = Nokogiri::XML::Node.new('a', doc) h.add_child(%Q{<a class="anchor" id="#{h_name}" href="##{h_name}"></a>})
anchor['class'] = 'anchor'
anchor['id'] = id
# % -> %25 so anchors work on Firefox. See issue #475
anchor['href'] = '#' + id.gsub('%', '%25')
h.add_child(anchor)
# Build TOC # Build TOC
toc ||= Nokogiri::XML::DocumentFragment.parse('<div class="toc"><div class="toc-title">Table of Contents</div></div>') toc ||= Nokogiri::XML::DocumentFragment.parse('<div class="toc"><div class="toc-title">Table of Contents</div></div>')
@@ -122,54 +123,13 @@ module Gollum
end end
node = Nokogiri::XML::Node.new('li', doc) node = Nokogiri::XML::Node.new('li', doc)
# % -> %25 so anchors work on Firefox. See issue #475 # % -> %25 so anchors work on Firefox. See issue #475
node.add_child("<a href='##{id.gsub('%', '%25')}'>#{h.content}</a>") node.add_child(%Q{<a href="##{h_name}">#{h.content}</a>})
tail.add_child(node) tail.add_child(node)
end end
toc = toc.to_xhtml if toc != nil toc = toc.to_xml(@to_xml) if toc != nil
[doc, toc] [doc, toc]
end end
#########################################################################
#
# TeX
#
#########################################################################
# Extract all TeX into the texmap and replace with placeholders.
#
# data - The raw String data.
#
# Returns the placeholder'd String data.
def extract_tex(data)
data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do
tag = CGI.escapeHTML($1)
id = Digest::SHA1.hexdigest(tag)
@texmap[id] = [:block, tag]
id
end.gsub(/\\\(\s*(.*?)\s*\\\)/m) do
tag = CGI.escapeHTML($1)
id = Digest::SHA1.hexdigest(tag)
@texmap[id] = [:inline, tag]
id
end
end
# Process all TeX from the texmap and replace the placeholders with the
# final markup.
#
# data - The String data (with placeholders).
#
# Returns the marked up String data.
def process_tex(data)
@texmap.each do |id, spec|
type, tex = *spec
data.gsub!(id) do
Gollum::Tex.to_html(tex, type)
end
end
data
end
######################################################################### #########################################################################
# #
# Tags # Tags
@@ -407,6 +367,12 @@ module Gollum
presence = "present" presence = "present"
end end
link = ::File.join(@wiki.base_path, page ? page.escaped_url_path : CGI.escape(link_name)) link = ::File.join(@wiki.base_path, page ? page.escaped_url_path : CGI.escape(link_name))
# //page is invalid
# strip all duplicate forward slashes using helpers.rb trim_leading_slash
# //page => /page
link = trim_leading_slash link
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>} %{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
end end
end end
@@ -505,6 +471,33 @@ module Gollum
# #
# Returns the placeholder'd String data. # Returns the placeholder'd String data.
def extract_code(data) def extract_code(data)
data.gsub!(/^([ \t]*)(~~~+) ?([^\r\n]+)?\r?\n(.+?)\r?\n\1(~~~+)\r?$/m) do
m_indent = $1
m_start = $2 # ~~~
m_lang = $3
m_code = $4
m_end = $5 # ~~~
# start and finish tilde fence must be the same length
return '' if m_start.length != m_end.length
lang = m_lang ? m_lang.strip : nil
id = Digest::SHA1.hexdigest("#{lang}.#{m_code}")
cached = check_cache(:code, id)
# extract lang from { .ruby } or { #stuff .ruby .indent }
# see http://johnmacfarlane.net/pandoc/README.html#delimited-code-blocks
lang = lang.match(/\.([^}\s]+)/)
lang = lang[1] unless lang.nil?
@codemap[id] = cached ?
{ :output => cached } :
{ :lang => lang, :code => m_code, :indent => m_indent }
"#{m_indent}#{id}" # print the SHA1 ID with the proper indentation
end
data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do
lang = $2 ? $2.strip : nil lang = $2 ? $2.strip : nil
id = Digest::SHA1.hexdigest("#{lang}.#{$3}") id = Digest::SHA1.hexdigest("#{lang}.#{$3}")
@@ -557,13 +550,15 @@ module Gollum
blocks.each do |lang, code| blocks.each do |lang, code|
encoding ||= 'utf-8' encoding ||= 'utf-8'
begin begin
hl_code = Pygments.highlight(code, :lexer => lang, :options => {:encoding => encoding.to_s}) # must set startinline to true for php to be highlighted without <?
rescue ::RubyPython::PythonError # http://pygments.org/docs/lexers/
hl_code = Pygments.highlight(code, :lexer => lang, :options => {:encoding => encoding.to_s, :startinline => true})
rescue
hl_code = code hl_code = code
end end
highlighted << hl_code highlighted << hl_code
end end
@codemap.each do |id, spec| @codemap.each do |id, spec|
body = spec[:output] || begin body = spec[:output] || begin
if (body = highlighted.shift.to_s).size > 0 if (body = highlighted.shift.to_s).size > 0
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class Page class Page
include Pagination include Pagination
+2 -1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
module Pagination module Pagination
def self.included(klass) def self.included(klass)
@@ -58,4 +59,4 @@ module Gollum
self.class.log_pagination_options(options) self.class.log_pagination_options(options)
end end
end end
end end
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
# Encapsulate sanitization options. # Encapsulate sanitization options.
# #
-14
View File
@@ -1,14 +0,0 @@
require 'escape_utils'
module Gollum
module Tex
TEX_URL = "http://www.mathtran.org/cgi-bin/toy/"
TEX_SIZES = { :inline => 2, :block => 4 }
def self.to_html(tex, type = :inline)
tex_uri = EscapeUtils.escape_uri(tex)
tex_alt = EscapeUtils.escape_html(tex)
%{<img src="#{TEX_URL}?D=#{TEX_SIZES[type]};tex=#{tex_uri}" alt="#{tex_alt}">}
end
end
end
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'net/http' require 'net/http'
require 'uri' require 'uri'
require 'open-uri' require 'open-uri'
+13
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class Wiki class Wiki
include Pagination include Pagination
@@ -154,6 +155,9 @@ module Gollum
# :ref - String the repository ref to retrieve pages from # :ref - String the repository ref to retrieve pages from
# :ws_subs - Array of chars to sub for ws in filenames. # :ws_subs - Array of chars to sub for ws in filenames.
# :mathjax - Set to false to disable mathjax. # :mathjax - Set to false to disable mathjax.
# :show_all - Show all files in file view, not just valid pages.
# Default: false
# :collapse_tree - Start with collapsed file view. Default: false
# #
# Returns a fresh Gollum::Repo. # Returns a fresh Gollum::Repo.
def initialize(path, options = {}) def initialize(path, options = {})
@@ -180,6 +184,8 @@ module Gollum
@live_preview = options.fetch(:live_preview, true) @live_preview = options.fetch(:live_preview, true)
@universal_toc = options.fetch(:universal_toc, false) @universal_toc = options.fetch(:universal_toc, false)
@mathjax = options[:mathjax] || false @mathjax = options[:mathjax] || false
@show_all = options[:show_all] || false
@collapse_tree = options[:collapse_tree] || false
end end
# Public: check whether the wiki's git repo exists on the filesystem. # Public: check whether the wiki's git repo exists on the filesystem.
@@ -588,6 +594,13 @@ module Gollum
# Toggles mathjax. # Toggles mathjax.
attr_reader :mathjax attr_reader :mathjax
# Toggles showing all files in files view. Default is false.
# When false, only valid pages in the git repo are displayed.
attr_reader :show_all
# Start with collapsed file view. Default: false
attr_reader :collapse_tree
# Normalize the data. # Normalize the data.
# #
# data - The String data to be normalized. # data - The String data to be normalized.
+40
View File
@@ -184,7 +184,9 @@ context "Frontend" do
name = "A" name = "A"
post "/create", :content => 'abc', :page => name, post "/create", :content => 'abc', :page => name,
:format => 'markdown', :message => 'def' :format => 'markdown', :message => 'def'
follow_redirect! follow_redirect!
assert last_response.ok? assert last_response.ok?
@wiki.clear_cache @wiki.clear_cache
@@ -260,6 +262,9 @@ context "Frontend" do
page2 = @wiki.page('A') page2 = @wiki.page('A')
assert_equal page1.version.sha, page2.version.sha assert_equal page1.version.sha, page2.version.sha
end end
=begin
# redirects are now handled by class MapGollum in bin/gollum
# they should be set in config.ru
test "redirects from 'base_path' or 'base_path/' to 'base_path/Home'" do test "redirects from 'base_path' or 'base_path/' to 'base_path/Home'" do
Precious::App.set(:wiki_options, {}) Precious::App.set(:wiki_options, {})
@@ -273,7 +278,11 @@ context "Frontend" do
Precious::App.set(:wiki_options, { :base_path => '/wiki/' }) Precious::App.set(:wiki_options, { :base_path => '/wiki/' })
get "/" get "/"
assert_match "http://example.org/wiki/Home", last_response.headers['Location'] assert_match "http://example.org/wiki/Home", last_response.headers['Location']
# Reset base path
Precious::App.set(:wiki_options, { :base_path => nil })
end end
=end
test "author details in session are used" do test "author details in session are used" do
page1 = @wiki.page('A') page1 = @wiki.page('A')
@@ -360,6 +369,36 @@ context "Frontend with lotr" do
assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'" assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'"
end end
# base path requires 'map' in a config.ru to work correctly.
test "create pages within sub-directories using base path" do
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
page = 'path'
post "/create", :content => '123', :page => page,
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
# should be wiki/Mordor/path
assert_equal 'http://example.org/Mordor/' + page, last_response.headers['Location']
get '/Mordor/' + page
assert_match /123/, last_response.body
# Reset base path
Precious::App.set(:wiki_options, { :base_path => nil })
end
test "create pages within sub-directories using page file dir" do
Precious::App.set(:wiki_options, { :page_file_dir => 'wiki' })
post "/create", :content => 'one two', :page => 'base',
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
assert_equal 'http://example.org/wiki/Mordor/base', last_response.headers['Location']
get "/wiki/Mordor/base"
# Reset page_file_dir after request but before matching.
Precious::App.set(:wiki_options, { :page_file_dir => nil })
assert_match /one two/, last_response.body
end
test "create pages within sub-directories" do test "create pages within sub-directories" do
post "/create", :content => 'big smelly creatures', :page => 'Orc', post "/create", :content => 'big smelly creatures', :page => 'Orc',
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary' :path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
@@ -377,6 +416,7 @@ context "Frontend with lotr" do
test "edit pages within sub-directories" do test "edit pages within sub-directories" do
post "/create", :content => 'big smelly creatures', :page => 'Orc', post "/create", :content => 'big smelly creatures', :page => 'Orc',
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary' :path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
assert_equal 'http://example.org/Mordor/orc', last_response.headers['Location'] assert_equal 'http://example.org/Mordor/orc', last_response.headers['Location']
post "/edit/Mordor/Orc", :content => 'not so big smelly creatures', post "/edit/Mordor/Orc", :content => 'not so big smelly creatures',
+4
View File
@@ -12,6 +12,10 @@ class FakePage
::File.basename(@filepath, ::File.extname(@filepath)) ::File.basename(@filepath, ::File.extname(@filepath))
end end
def filename
::File.basename(@filepath)
end
def path def path
return @filepath return @filepath
end end
+91 -37
View File
@@ -55,6 +55,21 @@ context "Markup" do
# #
######################################################################### #########################################################################
test "absolute link to non-existent page" do
@wiki.write_page("linktest", :markdown, "[[/Page]]", commit_details)
page = @wiki.page("linktest")
doc = Nokogiri::HTML page.formatted_data
paras = doc / :p
para = paras.first
anchors = para / :a
assert_equal 1, paras.size
assert_equal 1, anchors.size
assert_equal 'internal absent', anchors[0]['class']
assert_equal '/Page', anchors[0]['href']
assert_equal '/Page', anchors[0].text
end
test "double page links no space" do test "double page links no space" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details) @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
@@ -193,7 +208,56 @@ context "Markup" do
DATA DATA
), commit_details) ), commit_details)
output = @wiki.page(page).formatted_data output = @wiki.page(page).formatted_data
expected = %Q{<pre><code> <div class=\"highlight\"><pre><span class=\"n\">rot13</span><span class=\"p\">=</span><span class=\"s\">'tr '</span><span class=\"o\">\\</span><span class=\"s\">''</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=\"o\">'\\</span><span class=\"s\">''</span> <span class=\"s\">'\\''N-ZA-Mn-za-m'</span><span class=\"o\">\\</span><span class=\"s\">'</span>\n</pre></div>\n</code></pre>}.strip # remove trailing \n expected = %Q{<pre><code> <div class=\"highlight\"><pre><span class=\"n\">rot13</span><span class=\"p\">=</span><span class=\"s\">'tr '</span><span class=\"o\">\\</span><span class=\"s\">''</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=\"o\">'\\</span><span class=\"s\">''</span> <span class=\"s\">'\\''N-ZA-Mn-za-m'</span><span class=\"o\">\\</span><span class=\"s\">'</span>\n</pre></div>\n</code></pre>}
assert_equal expected, output
end
test "tilda 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_equal expected, output
end
# Issue #537
test "tilda 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_equal expected, output
end
# Issue #537
test "tilda 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_equal expected, output
end
test "four space indented code block" do
page = 'test_four'
@wiki.write_page(page, :markdown,
%( test
test), commit_details)
output = @wiki.page(page).formatted_data
expected = %(<pre><code>test\ntest\n</code></pre>)
assert_equal expected, output assert_equal expected, output
end end
@@ -222,7 +286,7 @@ context "Markup" do
page = @wiki.page(name) page = @wiki.page(name)
output = page.formatted_data output = page.formatted_data
assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg"> b</p>}, output assert_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.jpg\" /> b</p>}, output
end end
end end
@@ -233,7 +297,7 @@ context "Markup" do
page = @wiki.page(name) page = @wiki.page(name)
output = page.formatted_data output = page.formatted_data
assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.JPG"> b</p>}, output assert_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.JPG\" /> b</p>}, output
end end
end end
@@ -245,7 +309,7 @@ context "Markup" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details) @wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
page = @wiki.page("Bilbo Baggins") page = @wiki.page("Bilbo Baggins")
assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
end end
test "image with relative path on root" do test "image with relative path on root" do
@@ -256,7 +320,7 @@ context "Markup" do
index.commit("Add alpha.jpg") index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins") page = @wiki.page("Bilbo Baggins")
assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data assert_equal %Q{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
end end
test "image with relative path" do test "image with relative path" do
@@ -268,7 +332,7 @@ context "Markup" do
page = @wiki.page("Bilbo Baggins") page = @wiki.page("Bilbo Baggins")
output = page.formatted_data output = page.formatted_data
assert_equal %{<p>a <img src="/wiki/greek/alpha.jpg"><a href="/wiki/greek/alpha.jpg">a</a> b</p>}, output assert_equal %{<p>a <img src=\"/wiki/greek/alpha.jpg\" /><a href=\"/wiki/greek/alpha.jpg\">a</a> b</p>}, output
end end
test "image with absolute path on a preview" do test "image with absolute path on a preview" do
@@ -278,7 +342,7 @@ context "Markup" do
index.commit("Add alpha.jpg") index.commit("Add alpha.jpg")
page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown) page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown)
assert_equal %{<p>a <img src="/wiki/alpha.jpg"> b</p>}, page.formatted_data assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /> b</p>}, page.formatted_data
end end
test "image with relative path on a preview" do test "image with relative path on a preview" do
@@ -289,12 +353,12 @@ context "Markup" do
index.commit("Add alpha.jpg") index.commit("Add alpha.jpg")
page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown) page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown)
assert_equal %{<p>a <img src="/wiki/alpha.jpg"><img src="/wiki/greek/alpha.jpg"> b</p>}, page.formatted_data assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><img src=\"/wiki/greek/alpha.jpg\" /> b</p>}, page.formatted_data
end end
test "image with alt" do test "image with alt" do
content = "a [[alpha.jpg|alt=Alpha Dog]] b" content = "a [[alpha.jpg|alt=Alpha Dog]] b"
output = %{<p>a <img src="/greek/alpha.jpg" alt="Alpha Dog"> b</p>} output = %{<p>a<imgsrc=\"/greek/alpha.jpg\"alt=\"AlphaDog\"/>b</p>}
relative_image(content, output) relative_image(content, output)
end end
@@ -302,7 +366,7 @@ context "Markup" do
%w{em px}.each do |unit| %w{em px}.each do |unit|
%w{width height}.each do |dim| %w{width height}.each do |dim|
content = "a [[alpha.jpg|#{dim}=100#{unit}]] b" content = "a [[alpha.jpg|#{dim}=100#{unit}]] b"
output = "<p>a <img src=\"/greek/alpha.jpg\" #{dim}=\"100#{unit}\"> b</p>" output = "<p>a<imgsrc=\"/greek/alpha.jpg\"#{dim}=\"100#{unit}\"/>b</p>"
relative_image(content, output) relative_image(content, output)
end end
end end
@@ -311,7 +375,7 @@ context "Markup" do
test "image with bogus dimension" do test "image with bogus dimension" do
%w{width height}.each do |dim| %w{width height}.each do |dim|
content = "a [[alpha.jpg|#{dim}=100]] b" content = "a [[alpha.jpg|#{dim}=100]] b"
output = "<p>a <img src=\"/greek/alpha.jpg\"> b</p>" output = "<p>a<imgsrc=\"/greek/alpha.jpg\"/>b</p>"
relative_image(content, output) relative_image(content, output)
end end
end end
@@ -319,7 +383,7 @@ context "Markup" do
test "image with vertical align" do test "image with vertical align" do
%w{top texttop middle absmiddle bottom absbottom baseline}.each do |align| %w{top texttop middle absmiddle bottom absbottom baseline}.each do |align|
content = "a [[alpha.jpg|align=#{align}]] b" content = "a [[alpha.jpg|align=#{align}]] b"
output = "<p>a <img src=\"/greek/alpha.jpg\" align=\"#{align}\"> b</p>" output = %Q{<p>a<imgsrc=\"/greek/alpha.jpg\"align=\"#{align}\"/>b</p>}
relative_image(content, output) relative_image(content, output)
end end
end end
@@ -327,40 +391,40 @@ context "Markup" do
test "image with horizontal align" do test "image with horizontal align" do
%w{left center right}.each do |align| %w{left center right}.each do |align|
content = "a [[alpha.jpg|align=#{align}]] b" content = "a [[alpha.jpg|align=#{align}]] b"
output = "<p>a <span class=\"align-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span> b</p>" output = "<p>a<spanclass=\"align-#{align}\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span>b</p>"
relative_image(content, output) relative_image(content, output)
end end
end end
test "image with float" do test "image with float" do
content = "a\n\n[[alpha.jpg|float]]\n\nb" content = "a\n\n[[alpha.jpg|float]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"float-left\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>" output = "<p>a</p><p><spanclass=\"float-left\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span></p><p>b</p>"
relative_image(content, output) relative_image(content, output)
end end
test "image with float and align" do test "image with float and align" do
%w{left right}.each do |align| %w{left right}.each do |align|
content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb" content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"float-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>" output = "<p>a</p><p><spanclass=\"float-#{align}\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span></p><p>b</p>"
relative_image(content, output) relative_image(content, output)
end end
end end
test "image with frame" do test "image with frame" do
content = "a\n\n[[alpha.jpg|frame]]\n\nb" content = "a\n\n[[alpha.jpg|frame]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>" output = "<p>a</p><p><spanclass=\"frame\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span></p><p>b</p>"
relative_image(content, output) relative_image(content, output)
end end
test "absolute image with frame" do test "absolute image with frame" do
content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb" content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"http://example.com/bilbo.jpg\"></span></span></p>\n\n<p>b</p>" output = "<p>a</p><p><spanclass=\"frame\"><span><imgsrc=\"http://example.com/bilbo.jpg\"/></span></span></p><p>b</p>"
relative_image(content, output) relative_image(content, output)
end end
test "image with frame and alt" do test "image with frame and alt" do
content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb" content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\" alt=\"Alpha\"><span>Alpha</span></span></span></p>\n\n<p>b</p>" output = "<p>a</p><p><spanclass=\"frame\"><span><imgsrc=\"/greek/alpha.jpg\"alt=\"Alpha\"/><span>Alpha</span></span></span></p><p>b</p>"
relative_image(content, output) relative_image(content, output)
end end
@@ -407,7 +471,7 @@ context "Markup" do
# #
######################################################################### #########################################################################
test "code blocks" do test "regular code blocks" do
content = "a\n\n```ruby\nx = 1\n```\n\nb" 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>} 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>}
@@ -534,6 +598,14 @@ np.array([[2,2],[1,3]],np.float)
assert_equal %Q{<p>a\n</p><div class=\"highlight\"><pre><span class=\"nt\">&lt;p&gt;</span>a\n!rel<span class=\"nt\">&lt;/p&gt;</span>\n</pre></div>\n}, output assert_equal %Q{<p>a\n</p><div class=\"highlight\"><pre><span class=\"nt\">&lt;p&gt;</span>a\n!rel<span class=\"nt\">&lt;/p&gt;</span>\n</pre></div>\n}, output
end end
test "code block in unsupported language" do
@wiki.write_page("a", :markdown, "a\n```nonexistent\ncode\n```\nb", commit_details)
page = @wiki.page("a")
output = page.formatted_data
assert_equal %Q{<p>a\ncode\nb</p>}, output
end
######################################################################### #########################################################################
# #
# Web Sequence Diagrams # Web Sequence Diagrams
@@ -698,24 +770,6 @@ end
] ]
end end
#########################################################################
#
# TeX
#
#########################################################################
test "TeX block syntax" do
content = 'a \[ a^2 \] b'
output = "<p>a<imgsrc=\"http://www.mathtran.org/cgi-bin/toy/?D=4;tex=a%5E2\"alt=\"a^2\">b</p>"
compare(content, output, 'md')
end
test "TeX inline syntax" do
content = 'a \( a^2 \) b'
output = "<p>a<imgsrc=\"http://www.mathtran.org/cgi-bin/toy/?D=2;tex=a%5E2\"alt=\"a^2\">b</p>"
compare(content, output, 'md')
end
######################################################################### #########################################################################
# Asciidoc # Asciidoc
######################################################################### #########################################################################
+1 -1
View File
@@ -16,7 +16,7 @@ context "Page" do
page = @wiki.page('Bilbo Baggins') page = @wiki.page('Bilbo Baggins')
assert_equal Gollum::Page, page.class assert_equal Gollum::Page, page.class
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/ assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
assert page.formatted_data =~ %r{<h1>Bilbo Baggins<a class="anchor" id="Bilbo-Baggins" href="#Bilbo-Baggins"></a>\n</h1>\n\n<p>Bilbo Baggins} assert page.formatted_data =~ %r{<h1>Bilbo Baggins<a class="anchor" id="Bilbo-Baggins" href="#Bilbo-Baggins"></a></h1>\n\n<p>Bilbo Baggins}
assert_equal 'Bilbo-Baggins.md', page.path assert_equal 'Bilbo-Baggins.md', page.path
assert_equal :markdown, page.format assert_equal :markdown, page.format
assert_equal @wiki.repo.commits.first.id, page.version.id assert_equal @wiki.repo.commits.first.id, page.version.id
+24 -7
View File
@@ -29,19 +29,36 @@ context "Unicode Support" do
assert_equal "# 한글", utf8(page.raw_data) assert_equal "# 한글", utf8(page.raw_data)
# markup.rb # markup.rb
# #简介
# href.gsub('%', '%25') so the anchor works in Firefox.
# <a href="#%25ED%2595%259C%25EA%25B8%2580" id="%ED%95%9C%EA%B8%80" class="anchor"></a>
doc = Nokogiri::HTML page.formatted_data doc = Nokogiri::HTML page.formatted_data
h1s = doc / :h1 h1s = doc / :h1
h1 = h1s.first h1 = h1s.first
anchors = h1 / :a anchors = h1 / :a
assert_equal 1, h1s.size assert_equal 1, h1s.size
assert_equal 1, anchors.size assert_equal 1, anchors.size
assert_equal '#%25ED%2595%259C%25EA%25B8%2580', anchors[0]['href'] assert_equal '#한글', anchors[0]['href']
assert_equal '%ED%95%9C%EA%B8%80', anchors[0]['id'] assert_equal '한글', anchors[0]['id']
assert_equal 'anchor', anchors[0]['class'] assert_equal 'anchor', anchors[0]['class']
assert_equal '', anchors[0].text assert_equal '', anchors[0].text
end
test "create and read non-latin page with anchor 2" do
@wiki.write_page("test", :markdown, "# \"La\" faune d'Édiacara")
page = @wiki.page("test")
assert_equal Gollum::Page, page.class
assert_equal "# \"La\" faune d'Édiacara", utf8(page.raw_data)
# markup.rb test: ', ", É
doc = Nokogiri::HTML page.formatted_data
h1s = doc / :h1
h1 = h1s.first
anchors = h1 / :a
assert_equal 1, h1s.size
assert_equal 1, anchors.size
assert_equal %q(#%22La%22-faune-d'Édiacara), anchors[0]['href']
assert_equal %q(%22La%22-faune-d'Édiacara), anchors[0]['id']
assert_equal 'anchor', anchors[0]['class']
assert_equal '', anchors[0].text
end end
test "unicode with existing format rules" do test "unicode with existing format rules" do
+11 -1
View File
@@ -123,7 +123,7 @@ context "Wiki page previewing" do
test "preview_page" do test "preview_page" do
page = @wiki.preview_page("Test", "# Bilbo", :markdown) page = @wiki.preview_page("Test", "# Bilbo", :markdown)
assert_equal "# Bilbo", page.raw_data assert_equal "# Bilbo", page.raw_data
assert_equal %Q{<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a>\n</h1>}, page.formatted_data assert_equal %Q{<h1>Bilbo<a class=\"anchor\" id=\"Bilbo\" href=\"#Bilbo\"></a></h1>}, page.formatted_data
assert_equal "Test.md", page.filename assert_equal "Test.md", page.filename
assert_equal "Test", page.name assert_equal "Test", page.name
end end
@@ -142,6 +142,16 @@ context "Wiki TOC" do
assert_equal '<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a></h1>', page.formatted_data.gsub(/\n/,"") assert_equal '<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a></h1>', page.formatted_data.gsub(/\n/,"")
assert_equal %{<div class="toc"><div class="toc-title">Table of Contents</div><ul><li><a href="#Bilbo">Bilbo</a></li></ul></div>}, page.toc_data.gsub(/\n */,"") assert_equal %{<div class="toc"><div class="toc-title">Table of Contents</div><ul><li><a href="#Bilbo">Bilbo</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
end end
# Ensure ' creates valid links in TOC
# Incorrect: <a href=\"#a\" b=\"\">
# Correct: <a href=\"#a'b\">
test "' in link" do
page = @wiki.preview_page("Test", "# a'b", :markdown)
assert_equal "# a'b", page.raw_data
assert_equal %q{<h1>a'b<a class="anchor" id="a'b" href="#a'b"></a></h1>}, page.formatted_data.gsub(/\n/,"")
assert_equal %{<div class=\"toc\"><div class=\"toc-title\">Table of Contents</div><ul><li><a href=\"#a'b\">a'b</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
end
end end
context "Wiki page writing" do context "Wiki page writing" do