deplate 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/AUTHORS.TXT +26 -0
  2. data/CHANGES.TXT +177 -0
  3. data/LICENSE.TXT +340 -0
  4. data/NEWS.TXT +29 -0
  5. data/README.TXT +86 -0
  6. data/TODO.TXT +202 -0
  7. data/VERSION.TXT +1 -0
  8. data/bin/deplate +3 -0
  9. data/bin/deplate.bat +2 -0
  10. data/etc/deplate.ini +361 -0
  11. data/lib/deplate.rb +31 -0
  12. data/lib/deplate/abstract-class.rb +30 -0
  13. data/lib/deplate/builtin.rb +11 -0
  14. data/lib/deplate/cache.rb +59 -0
  15. data/lib/deplate/commands.rb +693 -0
  16. data/lib/deplate/common.rb +335 -0
  17. data/lib/deplate/converter.rb +99 -0
  18. data/lib/deplate/core.rb +2705 -0
  19. data/lib/deplate/css/article.css +545 -0
  20. data/lib/deplate/css/deplate.css +699 -0
  21. data/lib/deplate/css/heading-navbar.css +29 -0
  22. data/lib/deplate/css/layout-deplate-print.css +540 -0
  23. data/lib/deplate/css/layout-deplate.css +764 -0
  24. data/lib/deplate/css/sans-serif.css +160 -0
  25. data/lib/deplate/css/serif-e.css +170 -0
  26. data/lib/deplate/css/serif-rel.css +121 -0
  27. data/lib/deplate/css/serif.css +190 -0
  28. data/lib/deplate/css/slides.css +11 -0
  29. data/lib/deplate/css/tabbar-left.css +91 -0
  30. data/lib/deplate/css/tabbar-right-ie.css +14 -0
  31. data/lib/deplate/css/tabbar-right.css +118 -0
  32. data/lib/deplate/css/tabbar-top.css +64 -0
  33. data/lib/deplate/css/tabbar.css +81 -0
  34. data/lib/deplate/css/text-sans-serif.css +154 -0
  35. data/lib/deplate/css/text-serif.css +175 -0
  36. data/lib/deplate/define.rb +439 -0
  37. data/lib/deplate/docbook.rb +738 -0
  38. data/lib/deplate/elements.rb +1355 -0
  39. data/lib/deplate/etc.rb +199 -0
  40. data/lib/deplate/external.rb +135 -0
  41. data/lib/deplate/fmt/dbk-article-4.1.2.rb +21 -0
  42. data/lib/deplate/fmt/dbk-article.rb +46 -0
  43. data/lib/deplate/fmt/dbk-book.rb +46 -0
  44. data/lib/deplate/fmt/dbk-ref.rb +105 -0
  45. data/lib/deplate/fmt/dbk-slides.rb +47 -0
  46. data/lib/deplate/fmt/dbk-snippet.rb +21 -0
  47. data/lib/deplate/fmt/html-snippet.rb +21 -0
  48. data/lib/deplate/fmt/html.rb +1696 -0
  49. data/lib/deplate/fmt/htmlsite.rb +419 -0
  50. data/lib/deplate/fmt/htmlslides.rb +21 -0
  51. data/lib/deplate/fmt/htmlwebsite.rb +70 -0
  52. data/lib/deplate/fmt/latex-snippet.rb +22 -0
  53. data/lib/deplate/fmt/latex.rb +1242 -0
  54. data/lib/deplate/fmt/php.rb +19 -0
  55. data/lib/deplate/fmt/phpsite.rb +19 -0
  56. data/lib/deplate/fmt/plain.rb +598 -0
  57. data/lib/deplate/fmt/template.rb +34 -0
  58. data/lib/deplate/fmt/xhtml10t.rb +41 -0
  59. data/lib/deplate/formatter-snippet.rb +17 -0
  60. data/lib/deplate/formatter.rb +1210 -0
  61. data/lib/deplate/input.rb +492 -0
  62. data/lib/deplate/input/deplate-headings.rb +48 -0
  63. data/lib/deplate/input/deplate-restricted.rb +70 -0
  64. data/lib/deplate/input/deplate.rb +28 -0
  65. data/lib/deplate/input/rdoc.rb +277 -0
  66. data/lib/deplate/input/template.rb +29 -0
  67. data/lib/deplate/lib/latex/highlight-extra.sty +15 -0
  68. data/lib/deplate/lib/latex/highlight-typical.sty +15 -0
  69. data/lib/deplate/lib/tabmenu.js +146 -0
  70. data/lib/deplate/locale/de.latin1 +708 -0
  71. data/lib/deplate/locale/ru.koi8-r +48 -0
  72. data/lib/deplate/locale/zh_cn.gb2312 +35 -0
  73. data/lib/deplate/macros.rb +639 -0
  74. data/lib/deplate/messages.rb +120 -0
  75. data/lib/deplate/metadata.rb +77 -0
  76. data/lib/deplate/metadata/marshal.rb +24 -0
  77. data/lib/deplate/metadata/xml.rb +42 -0
  78. data/lib/deplate/metadata/yaml.rb +26 -0
  79. data/lib/deplate/mod/anyword.rb +56 -0
  80. data/lib/deplate/mod/babelfish.rb +27 -0
  81. data/lib/deplate/mod/code-gvim.rb +52 -0
  82. data/lib/deplate/mod/code-highlight.rb +91 -0
  83. data/lib/deplate/mod/colored-log.rb +17 -0
  84. data/lib/deplate/mod/de.rb +19 -0
  85. data/lib/deplate/mod/en.rb +17 -0
  86. data/lib/deplate/mod/endnotes.rb +60 -0
  87. data/lib/deplate/mod/fr.rb +46 -0
  88. data/lib/deplate/mod/html-asciimath.rb +40 -0
  89. data/lib/deplate/mod/html-deplate-button.rb +15 -0
  90. data/lib/deplate/mod/html-headings-navbar.rb +39 -0
  91. data/lib/deplate/mod/html-obfuscate-email.rb +47 -0
  92. data/lib/deplate/mod/html-sidebar.rb +232 -0
  93. data/lib/deplate/mod/htmlslides-navbar-fh.rb +32 -0
  94. data/lib/deplate/mod/iconv.rb +35 -0
  95. data/lib/deplate/mod/imgurl.rb +30 -0
  96. data/lib/deplate/mod/inlatex-compound.rb +69 -0
  97. data/lib/deplate/mod/koma.rb +109 -0
  98. data/lib/deplate/mod/latex-emph-table-head.rb +38 -0
  99. data/lib/deplate/mod/latex-styles.rb +461 -0
  100. data/lib/deplate/mod/latex-verbatim-small.rb +29 -0
  101. data/lib/deplate/mod/makefile.rb +194 -0
  102. data/lib/deplate/mod/mark-external-urls.rb +38 -0
  103. data/lib/deplate/mod/markup-1-warn.rb +37 -0
  104. data/lib/deplate/mod/markup-1.rb +41 -0
  105. data/lib/deplate/mod/navbar-png.rb +33 -0
  106. data/lib/deplate/mod/noindent.rb +32 -0
  107. data/lib/deplate/mod/numpara.rb +40 -0
  108. data/lib/deplate/mod/particle-math.rb +34 -0
  109. data/lib/deplate/mod/php-extra.rb +44 -0
  110. data/lib/deplate/mod/pstoedit.rb +71 -0
  111. data/lib/deplate/mod/recode.rb +57 -0
  112. data/lib/deplate/mod/ru_koi8-r.rb +20 -0
  113. data/lib/deplate/mod/smiley.rb +50 -0
  114. data/lib/deplate/mod/soffice.rb +23 -0
  115. data/lib/deplate/mod/symbols-latin1.rb +58 -0
  116. data/lib/deplate/mod/symbols-od-utf-8.rb +16 -0
  117. data/lib/deplate/mod/symbols-plain.rb +58 -0
  118. data/lib/deplate/mod/symbols-sgml.rb +97 -0
  119. data/lib/deplate/mod/symbols-utf-8.rb +81 -0
  120. data/lib/deplate/mod/symbols-xml.rb +34 -0
  121. data/lib/deplate/mod/syntax-region-alt.rb +37 -0
  122. data/lib/deplate/mod/utf8.rb +49 -0
  123. data/lib/deplate/mod/validate-html.rb +35 -0
  124. data/lib/deplate/mod/xmlrpc.rb +233 -0
  125. data/lib/deplate/mod/zh-cn-autospace.rb +108 -0
  126. data/lib/deplate/mod/zh-cn.rb +59 -0
  127. data/lib/deplate/once-method.rb +44 -0
  128. data/lib/deplate/output.rb +249 -0
  129. data/lib/deplate/particles.rb +815 -0
  130. data/lib/deplate/regions.rb +1076 -0
  131. data/lib/deplate/structured.rb +763 -0
  132. data/lib/deplate/template.rb +430 -0
  133. data/lib/deplate/templates/html-doc.html +28 -0
  134. data/lib/deplate/templates/html-left-tabbar-js.html +37 -0
  135. data/lib/deplate/templates/html-left-tabbar.html +31 -0
  136. data/lib/deplate/templates/html-tabbar-right-table.html +43 -0
  137. data/lib/deplate/templates/html-tabbar-right.html +23 -0
  138. data/lib/deplate/templates/html-tabbar-top.html +43 -0
  139. data/lib/deplate/templates/html-tabbar.html +31 -0
  140. data/lib/deplate/wiki-markup.rb +117 -0
  141. data/lib/deplate/xml.rb +109 -0
  142. data/lib/deplate/zh-cn.rb +59 -0
  143. data/lib/ps2ppm.rb +239 -0
  144. data/man/man1/deplate.1 +692 -0
  145. metadata +210 -0
@@ -0,0 +1,120 @@
1
+ # mod-en.rb -- Standard messages
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 07-Mai-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.193
8
+
9
+ # The base class for localizations
10
+ class Deplate::Messages
11
+ class << self
12
+ def setup(lang)
13
+ @properties ||= {}
14
+ @catalog ||= {}
15
+ Deplate::Core.module_eval <<-CODE
16
+ @@messages['#{lang}'] = #{self.name}
17
+ @@messages_last = #{self.name}
18
+ CODE
19
+ end
20
+
21
+ # Obsolete. Messages should be defined in a file in the locale
22
+ # subdirectory
23
+ def def_msg(id, text)
24
+ @catalog[id] = text
25
+ end
26
+
27
+ # Define a "property" like lang, latex_cmd etc.
28
+ def def_prop(key, val)
29
+ @properties[key] = val
30
+ end
31
+
32
+ # Get the localized message with this id
33
+ def msg(id)
34
+ case id
35
+ when Symbol
36
+ mid = "@#{id}"
37
+ else
38
+ mid = id
39
+ end
40
+ rv = @catalog[mid] || (id.kind_of?(String) ? id : nil)
41
+ rv
42
+ end
43
+
44
+ # was property key defined?
45
+ def has_property?(key)
46
+ @properties.keys.include?(key)
47
+ end
48
+
49
+ # get property key; check if there exists a specific property for
50
+ # the formatter fmt (e.g., latex_lang instead of lang)
51
+ def prop(key, fmt=nil)
52
+ if fmt
53
+ af = [fmt.formatter_name, key].join('_')
54
+ if has_property?(af)
55
+ return @properties[af]
56
+ end
57
+ end
58
+ return @properties[key]
59
+ end
60
+
61
+ # Load the message catalog for lang from the locale subdirectory
62
+ #
63
+ # The format is simply (repeating):
64
+ # MESSAGE/ID/HEAD/KEY
65
+ # LOCALIZED TEXT
66
+ # <BLANK LINE>
67
+ #
68
+ # Filter out comments -- lines starting with # in the first
69
+ # position. Comments can only occur in the head/key position as
70
+ # there is no message starting with #.
71
+ def load_catalog(lang)
72
+ langs, catalogs = Deplate::Core.collect_deplate_options('locale', 'locale', '')
73
+ fname = catalogs[lang]
74
+ if fname
75
+ cat = []
76
+ File.open(fname) do |io|
77
+ cat = io.readlines
78
+ end
79
+ key = nil
80
+ text = []
81
+ for e in cat
82
+ e.chomp!
83
+ if key
84
+ if e =~ /^\s*$/
85
+ @catalog[key] = text.join("\n")
86
+ key = nil
87
+ text = []
88
+ else
89
+ text << e
90
+ end
91
+ elsif e !~ /^#/ and e !~ /^\s*$/
92
+ key = e
93
+ end
94
+ end
95
+ else
96
+ raise "Unknown language: #{lang} (#{catalogs.keys.join(', ')})"
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ def initialize(deplate)
103
+ @deplate = deplate
104
+ @deplate.variables['encoding'] = prop('encoding')
105
+ @deplate.options.lang = prop('lang', false)
106
+ end
107
+
108
+ # See Deplate::Messages.msg
109
+ def msg(key)
110
+ self.class.msg(key)
111
+ end
112
+
113
+ # See Deplate::Messages.prop
114
+ def prop(key, fmt=nil)
115
+ fmt = @deplate.formatter if fmt.nil?
116
+ self.class.prop(key, fmt)
117
+ end
118
+
119
+ end
120
+
@@ -0,0 +1,77 @@
1
+ # metadata.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 15-Aug-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.6
8
+ #
9
+ # = Description
10
+ # = Usage
11
+ # = TODO
12
+ # = CHANGES
13
+
14
+ # require ''
15
+
16
+ # Metadata:
17
+ class Deplate::Metadata
18
+ attr_accessor :metadata
19
+
20
+ def initialize(deplate, output=nil)
21
+ @deplate = deplate
22
+ @output = output
23
+ @metadata = {}
24
+ end
25
+
26
+ def merge_metadata(metadata)
27
+ if @deplate.options.metadata_model
28
+ for e in metadata
29
+ push_metadata(e)
30
+ end
31
+ end
32
+ end
33
+
34
+ def push_metadata(data)
35
+ if @deplate.options.metadata_model
36
+ type = data["type"]
37
+ @metadata[type] ||= []
38
+ @metadata[type] << data
39
+ end
40
+ end
41
+
42
+ def metadata_available?
43
+ !@metadata.empty?
44
+ end
45
+
46
+ def destination(destination=nil)
47
+ if destination
48
+ destination
49
+ elsif @output
50
+ @output.destination
51
+ else
52
+ # <+TBD+>
53
+ ''
54
+ end
55
+ end
56
+
57
+ def metadata_destination(master_file=nil)
58
+ dest = destination(master_file)
59
+ Deplate::Core.canonic_file_name(dest, @deplate.options.metadata_suffix)
60
+ end
61
+
62
+ def format_metadata(metadata=@metadata)
63
+ unless metadata.nil? or metadata.empty?
64
+ for type, value in metadata
65
+ if value
66
+ for e in value
67
+ e['file'] = destination.dup
68
+ end
69
+ end
70
+ end
71
+ metadata['creator'] = 'deplate'
72
+ metadata['creator_version'] = Deplate::Core.version
73
+ @deplate.dump_metadata(metadata)
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,24 @@
1
+ # yaml.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 20-M�r-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.13
8
+ #
9
+ # = Description
10
+ # = Usage
11
+ # = TODO
12
+ # = CHANGES
13
+
14
+ class Deplate::Core
15
+ def module_initialize_metadata_marshal
16
+ @options.metadata_model = "marshal"
17
+ @options.metadata_suffix = ".dat"
18
+ end
19
+
20
+ def put_metadata(io, metadata)
21
+ Marshal.dump(metadata, io)
22
+ end
23
+ end
24
+
@@ -0,0 +1,42 @@
1
+ # xml.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 20-M�r-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.29
8
+ #
9
+ # = Description
10
+ # = Usage
11
+ # = TODO
12
+ # = CHANGES
13
+
14
+ require 'rexml/document'
15
+
16
+ class Deplate::Core
17
+ def module_initialize_metadata_marshal
18
+ @options.metadata_model = "xml"
19
+ @options.metadata_suffix = ".xml"
20
+ @options.metadata_xml = REXML::Document.new <<EOXML
21
+ <deplate>
22
+ </deplate>
23
+ EOXML
24
+ @options.metadata_xml << REXML::XMLDecl.new
25
+ end
26
+
27
+ def put_metadata(io, metadata)
28
+ @options.metadata_xml.write(io, 2)
29
+ end
30
+
31
+ alias :push_metadata_re_metadata_xml :push_metadata
32
+ def push_metadata(data, array=@metadata)
33
+ if @options.metadata_model
34
+ type = data["type"]
35
+ d = data.dup
36
+ d.delete('type')
37
+ @options.metadata_xml.root.add_element(type, d)
38
+ push_metadata_re_metadata_xml(data, array)
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,26 @@
1
+ # yaml.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 20-M�r-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.10
8
+ #
9
+ # = Description
10
+ # = Usage
11
+ # = TODO
12
+ # = CHANGES
13
+
14
+ require 'yaml'
15
+
16
+ class Deplate::Core
17
+ def module_initialize_metadata_yaml
18
+ @options.metadata_model = "yaml"
19
+ @options.metadata_suffix = ".yml"
20
+ end
21
+
22
+ def dump_metadata(data)
23
+ YAML.dump(data)
24
+ end
25
+ end
26
+
@@ -0,0 +1,56 @@
1
+ # anyword.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 11-Sep-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.93
8
+
9
+ class Deplate::Core
10
+ def module_initialize_anyword
11
+ list = @variables["anyword_list"]
12
+ acc = list ? list.split(/\s*,\s*/) : []
13
+
14
+ cat = @variables["anyword_catalog"]
15
+ if cat
16
+ acc += File.open(cat) do |io|
17
+ io.readlines.collect {|l| l.chomp}
18
+ end
19
+ end
20
+
21
+ suffix = @variables["anyword_suffix"] || ""
22
+
23
+ pattern = @variables["anyword_pattern"]
24
+ if pattern
25
+ acc += Dir[pattern].collect {|f| File.basename(f, suffix)}
26
+ end
27
+
28
+ unless list or cat or pattern
29
+ files = @options.files.collect do |src|
30
+ Dir[File.join(File.dirname(src), "*" + suffix)]
31
+ end
32
+ acc += files.flatten.collect {|f| File.basename(f, suffix)}
33
+ end
34
+
35
+ rx = acc.collect {|n| "(?i:\\b%s\\b)" % Regexp.escape(n)}.join("|")
36
+ body = <<-EOR
37
+ @rx = /^#{rx}/
38
+ def setup_element
39
+ @inter = nil
40
+ @literal = nil
41
+ @anchor = ""
42
+ @dest = @match[0]
43
+ @name = @dest
44
+ idx = [@deplate.add_index(self, @name)]
45
+ @idx = indexing(idx)
46
+ end
47
+ def process
48
+ @name = @deplate.formatter.plain_text(Deplate::Core.remove_backslashes(@name))
49
+ @elt = [@name, @dest, @anchor]
50
+ super
51
+ end
52
+ EOR
53
+ cls = Deplate::Cache.particle(deplate, body, :register => true)
54
+ end
55
+ end
56
+
@@ -0,0 +1,27 @@
1
+ # babelfish.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 05-Sep-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.21
8
+ #
9
+ # Description:
10
+ #
11
+ # Usage:
12
+ #
13
+ # TODO:
14
+ #
15
+ # CHANGES:
16
+ #
17
+
18
+ class Deplate::Formatter::HTML
19
+ def prepare_babelfish
20
+ if @deplate.formatter.matches?("html")
21
+ babel = %{<script type="text/javascript" language="JavaScript1.2" src="http://www.altavista.com/r?entr"></script>}
22
+ # babel = %{<script type="text/javascript" language="JavaScript1.2" src="http://www.altavista.com/r?inc_translate"></script>}
23
+ output_at(:post, :pre_body_end, %{<div align="right" class="pageicons">%s</div>} % babel)
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,52 @@
1
+ # code-gvim.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 26-Feb-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.93
8
+ #
9
+ # = Description
10
+ # This module provides a specialized syntax highlighter using gvim. Adds
11
+ # Deplate::Regions::Code#gvim_to_html.
12
+ #
13
+ # = Usage
14
+ # = TODO
15
+ # = CHANGES
16
+
17
+ require 'fileutils'
18
+ require 'tmpdir'
19
+
20
+ class Deplate::Regions::Code
21
+ add_highlighter(nil, "html", :gvim_to_html)
22
+ add_highlighter(nil, "htmlslides", :gvim_to_html)
23
+ add_highlighter(nil, "htmlsite", :gvim_to_html)
24
+
25
+ def gvim_to_html(syntax, style, text)
26
+ unless @deplate.options.allow_external
27
+ return
28
+ end
29
+ gvim = %{#{Deplate::External.get_app('gvim')} -f +"syn on" +"let use_xhtml = 1" +"setf #{syntax}" +"colorscheme #{style || "default"}" +"run! syntax/2html.vim" +"wq" +"q" deplateGvim}
30
+ @deplate.in_working_dir(Dir.tmpdir) do
31
+ FileUtils.rm("deplateGvim.html") if File.exist?("deplateGvim.html")
32
+ Deplate::External.write_file(self, "deplateGvim") {|io| io.puts(text)}
33
+ IO.popen(gvim) {|io| puts io.gets until io.eof }
34
+ if File.exist?("deplateGvim.html")
35
+ rv = [%{<div class="code">}]
36
+ File.open("deplateGvim.html") do |io|
37
+ until io.eof?
38
+ line = io.gets
39
+ line.chomp!
40
+ rv << line if line =~ /^<pre>$/ .. line =~ /^<\/pre\>$/
41
+ end
42
+ end
43
+ rv << %{</div>}
44
+ return rv.join("\n")
45
+ else
46
+ log("Error when running gvim", :error)
47
+ end
48
+ end
49
+ return nil
50
+ end
51
+ end
52
+
@@ -0,0 +1,91 @@
1
+ # code-highlight.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 27-Feb-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.41
8
+ #
9
+ # = Description
10
+ # Highlight code regions using Andr� Simon's
11
+ # highlight[http://www.andre-simon.de/]. Adds
12
+ # Deplate::Regions::Code#highlight.
13
+ #
14
+ # = Usage
15
+ # = TODO
16
+ # = CHANGES
17
+
18
+
19
+ class Deplate::Formatter::LaTeX
20
+ def hook_code_process_highlight(style)
21
+ unless @deplate.options.did_highlight_init
22
+ style_ext = Deplate::Regions::Code::get_style_ext(style)
23
+ add_package(%{color})
24
+ add_package(%{alltt})
25
+ add_package(%{highlight#{style_ext}})
26
+ @deplate.options.did_highlight_init = true
27
+ end
28
+ end
29
+ end
30
+
31
+ class Deplate::Regions::Code
32
+ add_highlighter(nil, "html", :highlight)
33
+ add_highlighter(nil, "htmlslides", :highlight)
34
+ add_highlighter(nil, "xhtml", :highlight)
35
+ add_highlighter(nil, "latex", :highlight)
36
+
37
+ class << self
38
+ def get_style_ext(style)
39
+ style_ext = style ? "-#{style}" : nil
40
+ end
41
+ end
42
+
43
+ def highlight(syntax, style, text)
44
+ unless @deplate.options.allow_external
45
+ return
46
+ end
47
+ formatter = @deplate.formatter
48
+ style_ext = Deplate::Regions::Code::get_style_ext(style)
49
+ if defined?(Deplate::Formatter::XHTML10transitional) and formatter.kind_of?(Deplate::Formatter::XHTML10transitional)
50
+ mode = :xhtml
51
+ args = "--xhtml"
52
+ style_out = "highlight#{style_ext}.css"
53
+ elsif defined?(Deplate::Formatter::HTML) and formatter.kind_of?(Deplate::Formatter::HTML)
54
+ mode = :html
55
+ args = "--css-outfile=highlight#{style_ext}.css"
56
+ style_out = "highlight#{style_ext}.css"
57
+ css = formatter.head_link_tag(%{rel="stylesheet" type="text/css" href="#{style_out}"})
58
+ log(["Code: You need to copy highlight's style definition", "highlight#{style_ext}.css"], :anyway)
59
+ @postponed_format << Proc.new do |container|
60
+ container.deplate.formatter.union_at(:pre, :css, css)
61
+ end
62
+ elsif defined?(Deplate::Formatter::LaTeX) and formatter.kind_of?(Deplate::Formatter::LaTeX)
63
+ mode = :latex
64
+ args = "--latex"
65
+ style_out = "highlight#{style_ext}.sty"
66
+ log(["Code: You need to copy highlight's style definition", "highlight#{style_ext}.sty"], :anyway)
67
+ elsif defined?(Deplate::Formatter::Docbook) and formatter.kind_of?(Deplate::Formatter::Docbook)
68
+ log("Code: ''highlight'' doesn't support docbook!", :error)
69
+ return nil
70
+ else
71
+ log("Code: ''highlight'' can't create output for this formatter!", :error)
72
+ return nil
73
+ end
74
+ if style
75
+ style = %{--style=#{style}}
76
+ end
77
+ tw = @deplate.variables["tabwidth"] || 4
78
+ cmd = "#{Deplate::External.get_app('highlight')} --fragment --wrap --replace-tabs=#{tw} --syntax #{syntax} --style-outfile=#{style_out} #{style} #{args}"
79
+ Deplate::External.log_popen(self, cmd) do |io|
80
+ io.puts(text)
81
+ io.close_write
82
+ text = io.read
83
+ end
84
+ case mode
85
+ when :html, :xhtml
86
+ text = [%{<div class="code">}, "<pre>", text, "</pre>", %{</div>}].join
87
+ end
88
+ return text
89
+ end
90
+ end
91
+