ultraviolet 0.10.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitmodules +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +28 -0
- data/Rakefile +18 -47
- data/Readme.md +89 -0
- data/bin/theme2latexrender +0 -0
- data/bin/theme2xhtmlrender +0 -0
- data/bin/uv +0 -0
- data/lib/uv.rb +78 -75
- data/lib/uv/render_processor.rb +128 -119
- data/lib/uv/utility.rb +62 -62
- data/lib/uv/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/ultraviolet_spec.rb +13 -0
- data/ultraviolet.gemspec +15 -0
- metadata +123 -271
- data/History.txt +0 -25
- data/Manifest.txt +0 -233
- data/README.txt +0 -52
- data/syntax/actionscript.syntax +0 -97
- data/syntax/active4d.syntax +0 -276
- data/syntax/active4d_html.syntax +0 -311
- data/syntax/active4d_ini.syntax +0 -50
- data/syntax/active4d_library.syntax +0 -21
- data/syntax/ada.syntax +0 -33
- data/syntax/antlr.syntax +0 -151
- data/syntax/apache.syntax +0 -191
- data/syntax/applescript.syntax +0 -384
- data/syntax/asp.syntax +0 -70
- data/syntax/asp_vb.net.syntax +0 -129
- data/syntax/bibtex.syntax +0 -151
- data/syntax/blog_html.syntax +0 -41
- data/syntax/blog_markdown.syntax +0 -42
- data/syntax/blog_text.syntax +0 -27
- data/syntax/blog_textile.syntax +0 -27
- data/syntax/build.syntax +0 -53
- data/syntax/bulletin_board.syntax +0 -287
- data/syntax/c++.syntax +0 -109
- data/syntax/c.syntax +0 -326
- data/syntax/cake.syntax +0 -55
- data/syntax/camlp4.syntax +0 -36
- data/syntax/cm.syntax +0 -32
- data/syntax/coldfusion.syntax +0 -119
- data/syntax/context_free.syntax +0 -176
- data/syntax/cs.syntax +0 -59
- data/syntax/css.syntax +0 -195
- data/syntax/css_experimental.syntax +0 -1925
- data/syntax/csv.syntax +0 -68
- data/syntax/d.syntax +0 -142
- data/syntax/diff.syntax +0 -81
- data/syntax/dokuwiki.syntax +0 -204
- data/syntax/dot.syntax +0 -47
- data/syntax/doxygen.syntax +0 -43
- data/syntax/dylan.syntax +0 -62
- data/syntax/eiffel.syntax +0 -78
- data/syntax/erlang.syntax +0 -922
- data/syntax/f-script.syntax +0 -80
- data/syntax/fortran.syntax +0 -141
- data/syntax/fxscript.syntax +0 -142
- data/syntax/greasemonkey.syntax +0 -34
- data/syntax/gri.syntax +0 -83
- data/syntax/groovy.syntax +0 -191
- data/syntax/gtd.syntax +0 -22
- data/syntax/gtdalt.syntax +0 -143
- data/syntax/haml.syntax +0 -88
- data/syntax/haskell.syntax +0 -88
- data/syntax/html-asp.syntax +0 -27
- data/syntax/html.syntax +0 -362
- data/syntax/html_django.syntax +0 -36
- data/syntax/html_for_asp.net.syntax +0 -424
- data/syntax/html_mason.syntax +0 -119
- data/syntax/html_rails.syntax +0 -40
- data/syntax/html_tcl.syntax +0 -26
- data/syntax/icalendar.syntax +0 -32
- data/syntax/inform.syntax +0 -48
- data/syntax/ini.syntax +0 -55
- data/syntax/installer_distribution_script.syntax +0 -77
- data/syntax/io.syntax +0 -81
- data/syntax/java.syntax +0 -211
- data/syntax/javaproperties.syntax +0 -20
- data/syntax/javascript.syntax +0 -256
- data/syntax/javascript_+_prototype.syntax +0 -72
- data/syntax/javascript_+_prototype_bracketed.syntax +0 -140
- data/syntax/jquery_javascript.syntax +0 -114
- data/syntax/json.syntax +0 -136
- data/syntax/languagedefinition.syntax +0 -708
- data/syntax/latex.syntax +0 -566
- data/syntax/latex_beamer.syntax +0 -41
- data/syntax/latex_log.syntax +0 -50
- data/syntax/latex_memoir.syntax +0 -64
- data/syntax/lexflex.syntax +0 -219
- data/syntax/lighttpd.syntax +0 -54
- data/syntax/lilypond.syntax +0 -492
- data/syntax/lisp.syntax +0 -61
- data/syntax/literate_haskell.syntax +0 -24
- data/syntax/logo.syntax +0 -29
- data/syntax/logtalk.syntax +0 -152
- data/syntax/lua.syntax +0 -86
- data/syntax/m.syntax +0 -142
- data/syntax/macports_portfile.syntax +0 -163
- data/syntax/mail.syntax +0 -118
- data/syntax/makefile.syntax +0 -36
- data/syntax/man.syntax +0 -17
- data/syntax/markdown.syntax +0 -543
- data/syntax/mediawiki.syntax +0 -567
- data/syntax/mel.syntax +0 -92
- data/syntax/mips.syntax +0 -66
- data/syntax/mod_perl.syntax +0 -50
- data/syntax/modula-3.syntax +0 -47
- data/syntax/moinmoin.syntax +0 -189
- data/syntax/mootools.syntax +0 -572
- data/syntax/movable_type.syntax +0 -162
- data/syntax/multimarkdown.syntax +0 -39
- data/syntax/objective-c++.syntax +0 -18
- data/syntax/objective-c.syntax +0 -233
- data/syntax/ocaml.syntax +0 -764
- data/syntax/ocamllex.syntax +0 -167
- data/syntax/ocamlyacc.syntax +0 -184
- data/syntax/opengl.syntax +0 -14
- data/syntax/pascal.syntax +0 -77
- data/syntax/perl.syntax +0 -1115
- data/syntax/php.syntax +0 -1253
- data/syntax/plain_text.syntax +0 -32
- data/syntax/pmwiki.syntax +0 -113
- data/syntax/postscript.syntax +0 -114
- data/syntax/processing.syntax +0 -106
- data/syntax/prolog.syntax +0 -40
- data/syntax/property_list.syntax +0 -635
- data/syntax/python.syntax +0 -868
- data/syntax/python_django.syntax +0 -21
- data/syntax/qmake_project.syntax +0 -114
- data/syntax/qt_c++.syntax +0 -26
- data/syntax/quake3_config.syntax +0 -32
- data/syntax/r.syntax +0 -81
- data/syntax/r_console.syntax +0 -16
- data/syntax/ragel.syntax +0 -201
- data/syntax/rd_r_documentation.syntax +0 -91
- data/syntax/regexp.syntax +0 -50
- data/syntax/regular_expressions_oniguruma.syntax +0 -107
- data/syntax/regular_expressions_python.syntax +0 -109
- data/syntax/release_notes.syntax +0 -46
- data/syntax/remind.syntax +0 -253
- data/syntax/restructuredtext.syntax +0 -250
- data/syntax/rez.syntax +0 -80
- data/syntax/ruby.syntax +0 -1035
- data/syntax/ruby_experimental.syntax +0 -145
- data/syntax/ruby_on_rails.syntax +0 -88
- data/syntax/s5.syntax +0 -69
- data/syntax/scheme.syntax +0 -347
- data/syntax/scilab.syntax +0 -41
- data/syntax/setext.syntax +0 -147
- data/syntax/shell-unix-generic.syntax +0 -384
- data/syntax/slate.syntax +0 -149
- data/syntax/smarty.syntax +0 -63
- data/syntax/sql.syntax +0 -237
- data/syntax/sql_rails.syntax +0 -18
- data/syntax/ssh-config.syntax +0 -33
- data/syntax/standard_ml.syntax +0 -121
- data/syntax/strings_file.syntax +0 -39
- data/syntax/subversion_commit_message.syntax +0 -36
- data/syntax/sweave.syntax +0 -84
- data/syntax/swig.syntax +0 -57
- data/syntax/tcl.syntax +0 -152
- data/syntax/template_toolkit.syntax +0 -121
- data/syntax/tex.syntax +0 -86
- data/syntax/tex_math.syntax +0 -49
- data/syntax/textile.syntax +0 -215
- data/syntax/tsv.syntax +0 -50
- data/syntax/twiki.syntax +0 -241
- data/syntax/txt2tags.syntax +0 -79
- data/syntax/vectorscript.syntax +0 -57
- data/syntax/xhtml_1.0.syntax +0 -4027
- data/syntax/xml.syntax +0 -180
- data/syntax/xml_strict.syntax +0 -92
- data/syntax/xsl.syntax +0 -60
- data/syntax/yaml.syntax +0 -160
- data/syntax/yui_javascript.syntax +0 -176
- data/test/test_uv.rb +0 -0
data/.gitmodules
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
diff-lcs (1.1.3)
|
|
5
|
+
oniguruma (1.1.0)
|
|
6
|
+
plist (3.1.0)
|
|
7
|
+
rack (1.4.1)
|
|
8
|
+
rake (0.9.2.2)
|
|
9
|
+
rspec (2.11.0)
|
|
10
|
+
rspec-core (~> 2.11.0)
|
|
11
|
+
rspec-expectations (~> 2.11.0)
|
|
12
|
+
rspec-mocks (~> 2.11.0)
|
|
13
|
+
rspec-core (2.11.1)
|
|
14
|
+
rspec-expectations (2.11.2)
|
|
15
|
+
diff-lcs (~> 1.1.3)
|
|
16
|
+
rspec-mocks (2.11.2)
|
|
17
|
+
textpow (1.3.0)
|
|
18
|
+
plist (>= 3.0.1)
|
|
19
|
+
|
|
20
|
+
PLATFORMS
|
|
21
|
+
ruby
|
|
22
|
+
|
|
23
|
+
DEPENDENCIES
|
|
24
|
+
oniguruma
|
|
25
|
+
rack
|
|
26
|
+
rake
|
|
27
|
+
rspec
|
|
28
|
+
textpow (>= 1.3)
|
data/Rakefile
CHANGED
|
@@ -1,51 +1,22 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'fileutils'
|
|
1
|
+
require "bundler/gem_tasks"
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
task :default do
|
|
4
|
+
sh "rspec spec/"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# extracted from https://github.com/grosser/project_template
|
|
8
|
+
rule /^version:bump:.*/ do |t|
|
|
9
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
|
10
|
+
index = ['major', 'minor','patch'].index(t.name.split(':').last)
|
|
11
|
+
file = 'lib/uv/version.rb'
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
version = /^== *(\d+\.\d+\.\d+)/.match( File.read( 'History.txt' ) )[1]
|
|
17
|
-
|
|
18
|
-
h = Hoe.new('ultraviolet', version) do |p|
|
|
19
|
-
p.rubyforge_name = 'ultraviolet'
|
|
20
|
-
p.author = ['Dizan Vasquez']
|
|
21
|
-
p.email = ['dichodaemon@gmail.com']
|
|
22
|
-
p.email = 'dichodaemon@gmail.com'
|
|
23
|
-
p.summary = 'Syntax highlighting engine'
|
|
24
|
-
p.description = p.paragraphs_of('README.txt', 1 ).join('\n\n')
|
|
25
|
-
p.url = 'http://ultraviolet.rubyforge.org'
|
|
26
|
-
p.rdoc_pattern = /^(lib|bin|ext)|txt$/
|
|
27
|
-
p.changes = p.paragraphs_of('History.txt', 0).join("\n\n")
|
|
28
|
-
p.extra_deps << ['textpow', '>= 0.10.0']
|
|
29
|
-
p.clean_globs = ["manual/*"]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
desc 'Create MaMa documentation'
|
|
33
|
-
task :mama => :clean do
|
|
34
|
-
system "mm -c -t refresh -o manual mm/manual.mm"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
desc 'Publish MaMa documentation to RubyForge'
|
|
38
|
-
task :mama_publish => [:clean, :mama] do
|
|
39
|
-
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
|
|
40
|
-
host = "#{config["username"]}@rubyforge.org"
|
|
41
|
-
remote_dir = "/var/www/gforge-projects/#{h.rubyforge_name}"
|
|
42
|
-
local_dir = 'manual'
|
|
43
|
-
system "rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}"
|
|
44
|
-
end
|
|
13
|
+
version_file = File.read(file)
|
|
14
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
|
15
|
+
version_parts[index] = version_parts[index].to_i + 1
|
|
16
|
+
version_parts[2] = 0 if index < 2 # remove patch for minor
|
|
17
|
+
version_parts[1] = 0 if index < 1 # remove minor for major
|
|
18
|
+
new_version = version_parts * '.'
|
|
19
|
+
File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
|
|
45
20
|
|
|
46
|
-
|
|
47
|
-
desc 'Run the test suite.'
|
|
48
|
-
task :test do
|
|
49
|
-
system "ruby -Ibin:lib:test test_#{rubyforge_name}.rb"
|
|
50
|
-
end
|
|
21
|
+
sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
|
51
22
|
end
|
data/Readme.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Ultraviolet is a html syntax highlighting library.<br/>
|
|
2
|
+
It uses [Textpow](https://github.com/grosser/textpow) to supports more than 60 programming languages.
|
|
3
|
+
|
|
4
|
+
# INSTALL
|
|
5
|
+
|
|
6
|
+
gem install ultraviolet
|
|
7
|
+
|
|
8
|
+
Ruby 1.8: [Install onigumura](https://github.com/grosser/textpow#ruby-18)
|
|
9
|
+
|
|
10
|
+
# [Demo](http://grosser.github.com/ultraviolet)
|
|
11
|
+
|
|
12
|
+
# Usage
|
|
13
|
+
|
|
14
|
+
### Commandline interface
|
|
15
|
+
|
|
16
|
+
uv -l syntax # Listing available syntaxes:
|
|
17
|
+
uv -l themes # Listing available themes:
|
|
18
|
+
uv lib/uv.rb # Letting to guess the parameters
|
|
19
|
+
uv -s yaml -t espresso_libre syntax/ini.syntax Specifying a syntax and a theme
|
|
20
|
+
|
|
21
|
+
# Output results to `index.html` and copy required files (/eg/ css):
|
|
22
|
+
uv -c . syntax/ini.syntax > index.html
|
|
23
|
+
|
|
24
|
+
# Producing output in latex and converting to pdf:
|
|
25
|
+
uv -h -o latex lib/uv.rb > uv.tex
|
|
26
|
+
pdflatex uv.tex
|
|
27
|
+
|
|
28
|
+
### Ruby interface
|
|
29
|
+
|
|
30
|
+
# List of available syntaxes
|
|
31
|
+
puts Uv.syntaxes.join( ", " )
|
|
32
|
+
|
|
33
|
+
# Listing available themes
|
|
34
|
+
puts Uv.themes.join( ", " )
|
|
35
|
+
|
|
36
|
+
# Parsing a css string. Produce xhtml output, with line numbers using amy theme
|
|
37
|
+
result = Uv.parse( text, "xhtml", "css", true, "amy")
|
|
38
|
+
|
|
39
|
+
# Output copy required files for `xhtml` format to directory `site`
|
|
40
|
+
Uv.copy_files "xhtml", "site"
|
|
41
|
+
|
|
42
|
+
### Examples
|
|
43
|
+
- [Macaronic markup engine](http://mama.rubyforge.org)
|
|
44
|
+
- [Radiograph rails plugin](http://agilewebdevelopment.com/plugins/radiograph)
|
|
45
|
+
- [SimpleHighlight plugin for SimpleLog](http://www.daikini.com/past/2007/6/14/simplehighlight_syntax_highlighting_for_simplelog)
|
|
46
|
+
|
|
47
|
+
# TODO
|
|
48
|
+
- less crazy Uv.parse interface -> options hash
|
|
49
|
+
- replace them gallery example with some nice example code
|
|
50
|
+
|
|
51
|
+
# Maintainer info
|
|
52
|
+
|
|
53
|
+
### Updating demo
|
|
54
|
+
|
|
55
|
+
cd _pages
|
|
56
|
+
bundle exec ruby generate.rb
|
|
57
|
+
bundle exec rackup
|
|
58
|
+
|
|
59
|
+
open http://localhost:9292
|
|
60
|
+
|
|
61
|
+
### Updating theme files
|
|
62
|
+
|
|
63
|
+
Currently only XHTML is "officially" supported by ultraviolet, nevertheless,
|
|
64
|
+
experimental latex output support already exists and other output formats can
|
|
65
|
+
be included in the future. This is important because theme conversion is format
|
|
66
|
+
dependent. For xhmtl, the command is `theme2xhtmlrender` as shown in the
|
|
67
|
+
following example.
|
|
68
|
+
|
|
69
|
+
theme2xhtmlrender Amy.tmTheme
|
|
70
|
+
|
|
71
|
+
For latex, the command `theme2latexrender` is used instead.
|
|
72
|
+
|
|
73
|
+
theme2latexrender Amy.tmTheme
|
|
74
|
+
|
|
75
|
+
Authors
|
|
76
|
+
=======
|
|
77
|
+
|
|
78
|
+
Original author [Dizan Vasquez](https://github.com/dichodaemon).
|
|
79
|
+
|
|
80
|
+
### [Contributors](https://github.com/grosser/ultraviolet/contributors)
|
|
81
|
+
- [Chris Hoffman](https://github.com/cehoffman)
|
|
82
|
+
- [Spox](https://github.com/spox)
|
|
83
|
+
- [Richard Ramsden](https://github.com/rramsden)
|
|
84
|
+
- [Humza](https://github.com/secondplanet)
|
|
85
|
+
- [Harry Brundage](https://github.com/hornairs)
|
|
86
|
+
|
|
87
|
+
[Michael Grosser](http://grosser.it)<br/>
|
|
88
|
+
michael@grosser.it<br/>
|
|
89
|
+
License: MIT<br/>
|
data/bin/theme2latexrender
CHANGED
|
File without changes
|
data/bin/theme2xhtmlrender
CHANGED
|
File without changes
|
data/bin/uv
CHANGED
|
File without changes
|
data/lib/uv.rb
CHANGED
|
@@ -1,89 +1,92 @@
|
|
|
1
|
+
#encoding: ascii-8bit
|
|
1
2
|
require 'fileutils'
|
|
2
3
|
require 'textpow'
|
|
3
4
|
require 'uv/render_processor.rb'
|
|
5
|
+
require "uv/version"
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
module Uv
|
|
9
|
+
class << self
|
|
10
|
+
attr_accessor :render_path, :theme_path, :syntax_path, :default_style, :syntaxes
|
|
11
|
+
end
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
13
|
+
self.syntax_path = Textpow.syntax_path
|
|
14
|
+
self.render_path = File.join(File.dirname(__FILE__), '..', 'render')
|
|
15
|
+
self.theme_path = File.join(render_path, 'xhtml', 'files', 'css')
|
|
16
|
+
self.default_style = 'mac_classic'
|
|
17
|
+
self.syntaxes = {}
|
|
18
|
+
|
|
19
|
+
def self.path
|
|
20
|
+
result = []
|
|
21
|
+
result << File.join(File.dirname(__FILE__), ".." )
|
|
22
|
+
end
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
def self.syntax_node_for(syntax)
|
|
25
|
+
if @syntaxes.key?(syntax)
|
|
26
|
+
@syntaxes[syntax]
|
|
27
|
+
else
|
|
28
|
+
@syntaxes[syntax] = Textpow.syntax(syntax) || raise(ArgumentError, "No syntax found for #{syntax}")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def Uv.themes
|
|
34
|
-
Dir.glob( File.join(File.dirname(__FILE__), '..', 'render', 'xhtml', 'files', 'css', '*.css') ).collect do |f|
|
|
35
|
-
File.basename(f, '.css')
|
|
36
|
-
end
|
|
37
|
-
end
|
|
32
|
+
def self.copy_files(output, output_dir)
|
|
33
|
+
Uv.path.each do |dir|
|
|
34
|
+
dir_name = File.join( dir, "render", output, "files" )
|
|
35
|
+
FileUtils.cp_r( Dir.glob(File.join( dir_name, "." )), output_dir ) if File.exists?( dir_name )
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
result = []
|
|
46
|
-
@syntaxes.each do |key, value|
|
|
47
|
-
assigned = false
|
|
48
|
-
if value.fileTypes
|
|
49
|
-
value.fileTypes.each do |t|
|
|
50
|
-
if t == File.basename( file_name ) || t == File.extname( file_name )[1..-1]
|
|
51
|
-
result << [key, value]
|
|
52
|
-
assigned = true
|
|
53
|
-
break
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
unless assigned
|
|
58
|
-
if value.firstLineMatch && value.firstLineMatch =~ first_line
|
|
59
|
-
result << [key, value]
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
result
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def Uv.parse text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = "classic", headers = false
|
|
67
|
-
init_syntaxes unless @syntaxes
|
|
68
|
-
renderer = File.join( File.dirname(__FILE__), '..',"render", output,"#{render_style}.render")
|
|
69
|
-
raise( ArgumentError, "Output for #{output} is not yet implemented" ) unless File.exists?(renderer)
|
|
70
|
-
css_class = render_style
|
|
71
|
-
render_options = YAML.load( File.open( renderer ) )
|
|
72
|
-
render_processor = RenderProcessor.new( render_options, line_numbers, headers )
|
|
73
|
-
@syntaxes[syntax_name].parse( text, render_processor )
|
|
74
|
-
render_processor.string
|
|
75
|
-
end
|
|
39
|
+
def self.syntaxes
|
|
40
|
+
Dir.glob( File.join(@syntax_path, '*.syntax') ).collect do |f|
|
|
41
|
+
File.basename(f, '.syntax')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
76
44
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
45
|
+
def self.themes
|
|
46
|
+
Dir.glob( File.join(@theme_path, '*.css') ).collect do |f|
|
|
47
|
+
File.basename(f, '.css')
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.syntax_for_file(file_name)
|
|
52
|
+
init_syntaxes unless @syntaxes
|
|
53
|
+
|
|
54
|
+
# get first non-empty line
|
|
55
|
+
first_line = ""
|
|
56
|
+
File.open( file_name, 'r' ) { |f|
|
|
57
|
+
while (first_line = f.readline).strip.size == 0; end
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# find syntax by file-extension
|
|
62
|
+
result = []
|
|
63
|
+
@syntaxes.each do |key, syntax|
|
|
64
|
+
assigned = false
|
|
65
|
+
if syntax.fileTypes
|
|
66
|
+
syntax.fileTypes.each do |t|
|
|
67
|
+
if t == File.basename( file_name ) || t == File.extname( file_name )[1..-1]
|
|
68
|
+
result << [key, syntax]
|
|
69
|
+
assigned = true
|
|
70
|
+
break
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
unless assigned
|
|
75
|
+
if syntax.firstLineMatch && syntax.firstLineMatch =~ first_line
|
|
76
|
+
result << [key, syntax]
|
|
77
|
+
end
|
|
83
78
|
end
|
|
84
|
-
|
|
79
|
+
end
|
|
80
|
+
result
|
|
81
|
+
end
|
|
85
82
|
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
def self.parse(text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = nil, headers = false)
|
|
84
|
+
RenderProcessor.load(output, render_style, line_numbers, headers) do |processor|
|
|
85
|
+
syntax_node_for(syntax_name).parse(text, processor)
|
|
86
|
+
end.string
|
|
87
|
+
end
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
def self.debug(text, syntax_name)
|
|
90
|
+
syntax_node_for(syntax_name).parse(text, Textpow::DebugProcessor.new)
|
|
91
|
+
end
|
|
92
|
+
end
|
data/lib/uv/render_processor.rb
CHANGED
|
@@ -1,131 +1,140 @@
|
|
|
1
1
|
require 'cgi'
|
|
2
2
|
|
|
3
|
-
module Uv
|
|
4
|
-
|
|
3
|
+
module Uv
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
5
|
+
class RenderProcessor
|
|
6
|
+
@@score_manager = Textpow::ScoreManager.new
|
|
7
|
+
|
|
8
|
+
attr_reader :string
|
|
9
|
+
attr_accessor :escapeHTML
|
|
10
|
+
|
|
11
|
+
def self.load(output, style = nil, line_numbers = false, headers = false)
|
|
12
|
+
style ||= Uv.default_style
|
|
13
|
+
renderer = File.join( Uv.render_path, output,"#{style}.render")
|
|
14
|
+
raise( ArgumentError, "Output for #{output} in #{style} style is not yet implemented" ) unless File.exists?(renderer)
|
|
15
|
+
options = YAML.load_file(renderer)
|
|
16
|
+
processor = RenderProcessor.new(options, line_numbers, headers)
|
|
17
|
+
yield processor if block_given?
|
|
18
|
+
processor
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def initialize render_options, line_numbers = false, headers = true, score_manager = nil
|
|
22
|
+
@score_manager = score_manager || @@score_manager
|
|
23
|
+
@render_options = render_options
|
|
24
|
+
@options = {}
|
|
25
|
+
@headers = headers
|
|
26
|
+
@line_numbers = line_numbers
|
|
27
|
+
@escapeHTML = true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def start_parsing name
|
|
31
|
+
@stack = [name]
|
|
32
|
+
@string = ""
|
|
33
|
+
@line = nil
|
|
34
|
+
@line_number = 0
|
|
35
|
+
print @render_options["document"]["begin"] if @headers
|
|
36
|
+
print @render_options["listing"]["begin"]
|
|
37
|
+
# opt = options @stack
|
|
38
|
+
# print opt["begin"] if opt
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def print string
|
|
42
|
+
@string << string
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def escape string
|
|
46
|
+
if @render_options["filter"]
|
|
47
|
+
@escaped = string
|
|
48
|
+
@escaped = self.instance_eval( @render_options["filter"] )
|
|
49
|
+
@escaped
|
|
50
|
+
else
|
|
51
|
+
string
|
|
52
52
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def open_tag name, position
|
|
56
|
+
@stack << name
|
|
57
|
+
print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
|
|
58
|
+
@position = position
|
|
59
|
+
opt = options @stack
|
|
60
|
+
print opt["begin"] if opt
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def close_tag name, position
|
|
64
|
+
print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
|
|
65
|
+
@position = position
|
|
66
|
+
opt = options @stack
|
|
67
|
+
print opt["end"] if opt
|
|
68
|
+
@stack.pop
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def close_line
|
|
72
|
+
stack = @stack[0..-1]
|
|
73
|
+
while stack.size > 1
|
|
74
|
+
opt = options stack
|
|
75
|
+
print opt["end"] if opt
|
|
76
|
+
stack.pop
|
|
60
77
|
end
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def open_line
|
|
81
|
+
stack = [@stack.first]
|
|
82
|
+
clone = @stack[1..-1]
|
|
83
|
+
while stack.size < @stack.size
|
|
84
|
+
stack << clone.shift
|
|
85
|
+
opt = options stack
|
|
86
|
+
print opt["begin"] if opt
|
|
69
87
|
end
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def new_line line
|
|
91
|
+
if @line
|
|
92
|
+
print escape(@line[@position..-1].gsub(/\n|\r/, ''))
|
|
93
|
+
close_line
|
|
94
|
+
print @render_options["line"]["end"]
|
|
95
|
+
print "\n"
|
|
79
96
|
end
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
@line_number += 1
|
|
90
|
-
@line = line
|
|
91
|
-
print @render_options["line"]["begin"]
|
|
92
|
-
if @line_numbers
|
|
93
|
-
print @render_options["line-numbers"]["begin"]
|
|
94
|
-
print @line_number.to_s.rjust(4).ljust(5)
|
|
95
|
-
print @render_options["line-numbers"]["end"]
|
|
96
|
-
print " "
|
|
97
|
-
end
|
|
98
|
-
open_line
|
|
97
|
+
@position = 0
|
|
98
|
+
@line_number += 1
|
|
99
|
+
@line = line
|
|
100
|
+
print @render_options["line"]["begin"]
|
|
101
|
+
if @line_numbers
|
|
102
|
+
print @render_options["line-numbers"]["begin"]
|
|
103
|
+
print @line_number.to_s.rjust(4).ljust(5)
|
|
104
|
+
print @render_options["line-numbers"]["end"]
|
|
105
|
+
print " "
|
|
99
106
|
end
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# print opt["end"] if opt
|
|
114
|
-
@stack.pop
|
|
115
|
-
print @render_options["listing"]["end"]
|
|
116
|
-
print @render_options["document"]["end"] if @headers
|
|
107
|
+
open_line
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def end_parsing name
|
|
111
|
+
if @line
|
|
112
|
+
print escape(@line[@position..-1].gsub(/\n|\r/, ''))
|
|
113
|
+
while @stack.size > 1
|
|
114
|
+
opt = options @stack
|
|
115
|
+
print opt["end"] if opt
|
|
116
|
+
@stack.pop
|
|
117
|
+
end
|
|
118
|
+
print @render_options["line"]["end"]
|
|
119
|
+
print "\n"
|
|
117
120
|
end
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
# opt = options @stack
|
|
122
|
+
# print opt["end"] if opt
|
|
123
|
+
@stack.pop
|
|
124
|
+
print @render_options["listing"]["end"]
|
|
125
|
+
print @render_options["document"]["end"] if @headers
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def options stack
|
|
129
|
+
ref = stack.join ' '
|
|
130
|
+
return @options[ref] if @options.has_key? ref
|
|
131
|
+
|
|
132
|
+
result = @render_options['tags'].max do |a, b|
|
|
133
|
+
@score_manager.score( a['selector'], ref ) <=> @score_manager.score( b['selector'], ref )
|
|
128
134
|
end
|
|
129
|
-
|
|
135
|
+
result = nil if @score_manager.score( result['selector'], ref ) == 0
|
|
136
|
+
@options[ref] = result
|
|
137
|
+
end
|
|
138
|
+
end
|
|
130
139
|
end
|
|
131
140
|
|