kitabu 0.4.5

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.
Files changed (454) hide show
  1. data/README.markdown +60 -0
  2. data/Rakefile +37 -0
  3. data/VERSION +1 -0
  4. data/bin/kitabu +8 -0
  5. data/kitabu.gemspec +497 -0
  6. data/lib/kitabu.rb +50 -0
  7. data/lib/kitabu/base.rb +271 -0
  8. data/lib/kitabu/blackcloth.rb +179 -0
  9. data/lib/kitabu/command.rb +94 -0
  10. data/lib/kitabu/redcloth.rb +964 -0
  11. data/lib/kitabu/syntax.rb +126 -0
  12. data/lib/kitabu/tasks.rb +113 -0
  13. data/lib/kitabu/templates.rb +54 -0
  14. data/lib/kitabu/toc.rb +51 -0
  15. data/lib/kitabu/vendor/colorize/colorize.rb +81 -0
  16. data/lib/kitabu/vendor/ruby1.8/plist/plist.rb +22 -0
  17. data/lib/kitabu/vendor/ruby1.8/plist/plist/generator.rb +224 -0
  18. data/lib/kitabu/vendor/ruby1.8/plist/plist/parser.rb +224 -0
  19. data/lib/kitabu/vendor/ruby1.8/textpow/textpow.rb +10 -0
  20. data/lib/kitabu/vendor/ruby1.8/textpow/textpow/debug_processor.rb +36 -0
  21. data/lib/kitabu/vendor/ruby1.8/textpow/textpow/score_manager.rb +65 -0
  22. data/lib/kitabu/vendor/ruby1.8/textpow/textpow/syntax.rb +284 -0
  23. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/active4d.render +140 -0
  24. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/all_hallows_eve.render +104 -0
  25. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/amy.render +179 -0
  26. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/blackboard.render +119 -0
  27. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/brilliance_black.render +560 -0
  28. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/brilliance_dull.render +569 -0
  29. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/cobalt.render +170 -0
  30. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/dawn.render +134 -0
  31. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/eiffel.render +140 -0
  32. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/espresso_libre.render +131 -0
  33. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/active4d.css +114 -0
  34. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/all_hallows_eve.css +72 -0
  35. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/amy.css +147 -0
  36. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/blackboard.css +88 -0
  37. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/brilliance_black.css +605 -0
  38. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/brilliance_dull.css +599 -0
  39. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/cobalt.css +149 -0
  40. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/dawn.css +121 -0
  41. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/eiffel.css +121 -0
  42. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/espresso_libre.css +109 -0
  43. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/idle.css +62 -0
  44. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/iplastic.css +80 -0
  45. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/lazy.css +73 -0
  46. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/mac_classic.css +123 -0
  47. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/magicwb_amiga.css +104 -0
  48. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/pastels_on_dark.css +188 -0
  49. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/slush_poppies.css +85 -0
  50. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/spacecadet.css +51 -0
  51. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/sunburst.css +180 -0
  52. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/twilight.css +137 -0
  53. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/files/css/zenburnesque.css +91 -0
  54. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/idle.render +101 -0
  55. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/iplastic.render +107 -0
  56. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/lazy.render +104 -0
  57. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/mac_classic.render +143 -0
  58. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/magicwb_amiga.render +125 -0
  59. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/pastels_on_dark.render +212 -0
  60. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/slush_poppies.render +131 -0
  61. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/spacecadet.render +89 -0
  62. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/sunburst.render +194 -0
  63. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/twilight.render +161 -0
  64. data/lib/kitabu/vendor/ruby1.8/uv/render/xhtml/zenburnesque.render +134 -0
  65. data/lib/kitabu/vendor/ruby1.8/uv/syntax/actionscript.syntax +97 -0
  66. data/lib/kitabu/vendor/ruby1.8/uv/syntax/active4d.syntax +276 -0
  67. data/lib/kitabu/vendor/ruby1.8/uv/syntax/active4d_html.syntax +311 -0
  68. data/lib/kitabu/vendor/ruby1.8/uv/syntax/active4d_ini.syntax +50 -0
  69. data/lib/kitabu/vendor/ruby1.8/uv/syntax/active4d_library.syntax +21 -0
  70. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ada.syntax +33 -0
  71. data/lib/kitabu/vendor/ruby1.8/uv/syntax/antlr.syntax +151 -0
  72. data/lib/kitabu/vendor/ruby1.8/uv/syntax/apache.syntax +191 -0
  73. data/lib/kitabu/vendor/ruby1.8/uv/syntax/applescript.syntax +384 -0
  74. data/lib/kitabu/vendor/ruby1.8/uv/syntax/asp.syntax +70 -0
  75. data/lib/kitabu/vendor/ruby1.8/uv/syntax/asp_vb.net.syntax +129 -0
  76. data/lib/kitabu/vendor/ruby1.8/uv/syntax/bibtex.syntax +151 -0
  77. data/lib/kitabu/vendor/ruby1.8/uv/syntax/blog_html.syntax +41 -0
  78. data/lib/kitabu/vendor/ruby1.8/uv/syntax/blog_markdown.syntax +42 -0
  79. data/lib/kitabu/vendor/ruby1.8/uv/syntax/blog_text.syntax +27 -0
  80. data/lib/kitabu/vendor/ruby1.8/uv/syntax/blog_textile.syntax +27 -0
  81. data/lib/kitabu/vendor/ruby1.8/uv/syntax/buggy/nemerle.syntax +74 -0
  82. data/lib/kitabu/vendor/ruby1.8/uv/syntax/build.syntax +53 -0
  83. data/lib/kitabu/vendor/ruby1.8/uv/syntax/bulletin_board.syntax +287 -0
  84. data/lib/kitabu/vendor/ruby1.8/uv/syntax/c++.syntax +109 -0
  85. data/lib/kitabu/vendor/ruby1.8/uv/syntax/c.syntax +326 -0
  86. data/lib/kitabu/vendor/ruby1.8/uv/syntax/cake.syntax +55 -0
  87. data/lib/kitabu/vendor/ruby1.8/uv/syntax/camlp4.syntax +36 -0
  88. data/lib/kitabu/vendor/ruby1.8/uv/syntax/cm.syntax +32 -0
  89. data/lib/kitabu/vendor/ruby1.8/uv/syntax/coldfusion.syntax +119 -0
  90. data/lib/kitabu/vendor/ruby1.8/uv/syntax/context_free.syntax +176 -0
  91. data/lib/kitabu/vendor/ruby1.8/uv/syntax/cs.syntax +59 -0
  92. data/lib/kitabu/vendor/ruby1.8/uv/syntax/css.syntax +195 -0
  93. data/lib/kitabu/vendor/ruby1.8/uv/syntax/css_experimental.syntax +1925 -0
  94. data/lib/kitabu/vendor/ruby1.8/uv/syntax/csv.syntax +68 -0
  95. data/lib/kitabu/vendor/ruby1.8/uv/syntax/d.syntax +142 -0
  96. data/lib/kitabu/vendor/ruby1.8/uv/syntax/diff.syntax +81 -0
  97. data/lib/kitabu/vendor/ruby1.8/uv/syntax/dokuwiki.syntax +204 -0
  98. data/lib/kitabu/vendor/ruby1.8/uv/syntax/dot.syntax +47 -0
  99. data/lib/kitabu/vendor/ruby1.8/uv/syntax/doxygen.syntax +43 -0
  100. data/lib/kitabu/vendor/ruby1.8/uv/syntax/dylan.syntax +62 -0
  101. data/lib/kitabu/vendor/ruby1.8/uv/syntax/eiffel.syntax +78 -0
  102. data/lib/kitabu/vendor/ruby1.8/uv/syntax/erlang.syntax +922 -0
  103. data/lib/kitabu/vendor/ruby1.8/uv/syntax/f-script.syntax +80 -0
  104. data/lib/kitabu/vendor/ruby1.8/uv/syntax/fortran.syntax +141 -0
  105. data/lib/kitabu/vendor/ruby1.8/uv/syntax/fxscript.syntax +142 -0
  106. data/lib/kitabu/vendor/ruby1.8/uv/syntax/greasemonkey.syntax +34 -0
  107. data/lib/kitabu/vendor/ruby1.8/uv/syntax/gri.syntax +83 -0
  108. data/lib/kitabu/vendor/ruby1.8/uv/syntax/groovy.syntax +191 -0
  109. data/lib/kitabu/vendor/ruby1.8/uv/syntax/gtd.syntax +22 -0
  110. data/lib/kitabu/vendor/ruby1.8/uv/syntax/gtdalt.syntax +143 -0
  111. data/lib/kitabu/vendor/ruby1.8/uv/syntax/haml.syntax +88 -0
  112. data/lib/kitabu/vendor/ruby1.8/uv/syntax/haskell.syntax +88 -0
  113. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html-asp.syntax +27 -0
  114. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html.syntax +362 -0
  115. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html_django.syntax +36 -0
  116. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html_for_asp.net.syntax +424 -0
  117. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html_mason.syntax +119 -0
  118. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html_rails.syntax +40 -0
  119. data/lib/kitabu/vendor/ruby1.8/uv/syntax/html_tcl.syntax +26 -0
  120. data/lib/kitabu/vendor/ruby1.8/uv/syntax/icalendar.syntax +32 -0
  121. data/lib/kitabu/vendor/ruby1.8/uv/syntax/inform.syntax +48 -0
  122. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ini.syntax +55 -0
  123. data/lib/kitabu/vendor/ruby1.8/uv/syntax/installer_distribution_script.syntax +77 -0
  124. data/lib/kitabu/vendor/ruby1.8/uv/syntax/io.syntax +81 -0
  125. data/lib/kitabu/vendor/ruby1.8/uv/syntax/java.syntax +211 -0
  126. data/lib/kitabu/vendor/ruby1.8/uv/syntax/javaproperties.syntax +20 -0
  127. data/lib/kitabu/vendor/ruby1.8/uv/syntax/javascript.syntax +256 -0
  128. data/lib/kitabu/vendor/ruby1.8/uv/syntax/javascript_+_prototype.syntax +72 -0
  129. data/lib/kitabu/vendor/ruby1.8/uv/syntax/javascript_+_prototype_bracketed.syntax +140 -0
  130. data/lib/kitabu/vendor/ruby1.8/uv/syntax/jquery_javascript.syntax +114 -0
  131. data/lib/kitabu/vendor/ruby1.8/uv/syntax/json.syntax +136 -0
  132. data/lib/kitabu/vendor/ruby1.8/uv/syntax/languagedefinition.syntax +708 -0
  133. data/lib/kitabu/vendor/ruby1.8/uv/syntax/latex.syntax +566 -0
  134. data/lib/kitabu/vendor/ruby1.8/uv/syntax/latex_beamer.syntax +41 -0
  135. data/lib/kitabu/vendor/ruby1.8/uv/syntax/latex_log.syntax +50 -0
  136. data/lib/kitabu/vendor/ruby1.8/uv/syntax/latex_memoir.syntax +64 -0
  137. data/lib/kitabu/vendor/ruby1.8/uv/syntax/lexflex.syntax +219 -0
  138. data/lib/kitabu/vendor/ruby1.8/uv/syntax/lighttpd.syntax +54 -0
  139. data/lib/kitabu/vendor/ruby1.8/uv/syntax/lilypond.syntax +492 -0
  140. data/lib/kitabu/vendor/ruby1.8/uv/syntax/lisp.syntax +61 -0
  141. data/lib/kitabu/vendor/ruby1.8/uv/syntax/literate_haskell.syntax +24 -0
  142. data/lib/kitabu/vendor/ruby1.8/uv/syntax/logo.syntax +29 -0
  143. data/lib/kitabu/vendor/ruby1.8/uv/syntax/logtalk.syntax +152 -0
  144. data/lib/kitabu/vendor/ruby1.8/uv/syntax/lua.syntax +86 -0
  145. data/lib/kitabu/vendor/ruby1.8/uv/syntax/m.syntax +142 -0
  146. data/lib/kitabu/vendor/ruby1.8/uv/syntax/macports_portfile.syntax +163 -0
  147. data/lib/kitabu/vendor/ruby1.8/uv/syntax/mail.syntax +118 -0
  148. data/lib/kitabu/vendor/ruby1.8/uv/syntax/makefile.syntax +36 -0
  149. data/lib/kitabu/vendor/ruby1.8/uv/syntax/man.syntax +17 -0
  150. data/lib/kitabu/vendor/ruby1.8/uv/syntax/markdown.syntax +543 -0
  151. data/lib/kitabu/vendor/ruby1.8/uv/syntax/mediawiki.syntax +567 -0
  152. data/lib/kitabu/vendor/ruby1.8/uv/syntax/mel.syntax +92 -0
  153. data/lib/kitabu/vendor/ruby1.8/uv/syntax/mips.syntax +66 -0
  154. data/lib/kitabu/vendor/ruby1.8/uv/syntax/mod_perl.syntax +50 -0
  155. data/lib/kitabu/vendor/ruby1.8/uv/syntax/modula-3.syntax +47 -0
  156. data/lib/kitabu/vendor/ruby1.8/uv/syntax/moinmoin.syntax +189 -0
  157. data/lib/kitabu/vendor/ruby1.8/uv/syntax/mootools.syntax +572 -0
  158. data/lib/kitabu/vendor/ruby1.8/uv/syntax/movable_type.syntax +162 -0
  159. data/lib/kitabu/vendor/ruby1.8/uv/syntax/multimarkdown.syntax +39 -0
  160. data/lib/kitabu/vendor/ruby1.8/uv/syntax/objective-c++.syntax +18 -0
  161. data/lib/kitabu/vendor/ruby1.8/uv/syntax/objective-c.syntax +233 -0
  162. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ocaml.syntax +764 -0
  163. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ocamllex.syntax +167 -0
  164. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ocamlyacc.syntax +184 -0
  165. data/lib/kitabu/vendor/ruby1.8/uv/syntax/old/YAML.yaml +160 -0
  166. data/lib/kitabu/vendor/ruby1.8/uv/syntax/old/txt2tags.yaml +139 -0
  167. data/lib/kitabu/vendor/ruby1.8/uv/syntax/opengl.syntax +14 -0
  168. data/lib/kitabu/vendor/ruby1.8/uv/syntax/pascal.syntax +77 -0
  169. data/lib/kitabu/vendor/ruby1.8/uv/syntax/perl.syntax +1115 -0
  170. data/lib/kitabu/vendor/ruby1.8/uv/syntax/php.syntax +1253 -0
  171. data/lib/kitabu/vendor/ruby1.8/uv/syntax/plain_text.syntax +32 -0
  172. data/lib/kitabu/vendor/ruby1.8/uv/syntax/pmwiki.syntax +113 -0
  173. data/lib/kitabu/vendor/ruby1.8/uv/syntax/postscript.syntax +114 -0
  174. data/lib/kitabu/vendor/ruby1.8/uv/syntax/processing.syntax +106 -0
  175. data/lib/kitabu/vendor/ruby1.8/uv/syntax/prolog.syntax +40 -0
  176. data/lib/kitabu/vendor/ruby1.8/uv/syntax/property_list.syntax +635 -0
  177. data/lib/kitabu/vendor/ruby1.8/uv/syntax/python.syntax +868 -0
  178. data/lib/kitabu/vendor/ruby1.8/uv/syntax/python_django.syntax +21 -0
  179. data/lib/kitabu/vendor/ruby1.8/uv/syntax/qmake_project.syntax +114 -0
  180. data/lib/kitabu/vendor/ruby1.8/uv/syntax/qt_c++.syntax +26 -0
  181. data/lib/kitabu/vendor/ruby1.8/uv/syntax/quake3_config.syntax +32 -0
  182. data/lib/kitabu/vendor/ruby1.8/uv/syntax/r.syntax +81 -0
  183. data/lib/kitabu/vendor/ruby1.8/uv/syntax/r_console.syntax +16 -0
  184. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ragel.syntax +201 -0
  185. data/lib/kitabu/vendor/ruby1.8/uv/syntax/rd_r_documentation.syntax +91 -0
  186. data/lib/kitabu/vendor/ruby1.8/uv/syntax/regexp.syntax +50 -0
  187. data/lib/kitabu/vendor/ruby1.8/uv/syntax/regular_expressions_oniguruma.syntax +107 -0
  188. data/lib/kitabu/vendor/ruby1.8/uv/syntax/regular_expressions_python.syntax +109 -0
  189. data/lib/kitabu/vendor/ruby1.8/uv/syntax/release_notes.syntax +46 -0
  190. data/lib/kitabu/vendor/ruby1.8/uv/syntax/remind.syntax +253 -0
  191. data/lib/kitabu/vendor/ruby1.8/uv/syntax/restructuredtext.syntax +250 -0
  192. data/lib/kitabu/vendor/ruby1.8/uv/syntax/rez.syntax +80 -0
  193. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ruby.syntax +1035 -0
  194. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ruby_experimental.syntax +145 -0
  195. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ruby_on_rails.syntax +88 -0
  196. data/lib/kitabu/vendor/ruby1.8/uv/syntax/s5.syntax +69 -0
  197. data/lib/kitabu/vendor/ruby1.8/uv/syntax/scheme.syntax +347 -0
  198. data/lib/kitabu/vendor/ruby1.8/uv/syntax/scilab.syntax +41 -0
  199. data/lib/kitabu/vendor/ruby1.8/uv/syntax/setext.syntax +147 -0
  200. data/lib/kitabu/vendor/ruby1.8/uv/syntax/shell-unix-generic.syntax +384 -0
  201. data/lib/kitabu/vendor/ruby1.8/uv/syntax/slate.syntax +149 -0
  202. data/lib/kitabu/vendor/ruby1.8/uv/syntax/smarty.syntax +63 -0
  203. data/lib/kitabu/vendor/ruby1.8/uv/syntax/sql.syntax +237 -0
  204. data/lib/kitabu/vendor/ruby1.8/uv/syntax/sql_rails.syntax +18 -0
  205. data/lib/kitabu/vendor/ruby1.8/uv/syntax/ssh-config.syntax +33 -0
  206. data/lib/kitabu/vendor/ruby1.8/uv/syntax/standard_ml.syntax +121 -0
  207. data/lib/kitabu/vendor/ruby1.8/uv/syntax/strings_file.syntax +39 -0
  208. data/lib/kitabu/vendor/ruby1.8/uv/syntax/subversion_commit_message.syntax +36 -0
  209. data/lib/kitabu/vendor/ruby1.8/uv/syntax/sweave.syntax +84 -0
  210. data/lib/kitabu/vendor/ruby1.8/uv/syntax/swig.syntax +57 -0
  211. data/lib/kitabu/vendor/ruby1.8/uv/syntax/tcl.syntax +152 -0
  212. data/lib/kitabu/vendor/ruby1.8/uv/syntax/template_toolkit.syntax +121 -0
  213. data/lib/kitabu/vendor/ruby1.8/uv/syntax/tex.syntax +86 -0
  214. data/lib/kitabu/vendor/ruby1.8/uv/syntax/tex_math.syntax +49 -0
  215. data/lib/kitabu/vendor/ruby1.8/uv/syntax/textile.syntax +215 -0
  216. data/lib/kitabu/vendor/ruby1.8/uv/syntax/tsv.syntax +50 -0
  217. data/lib/kitabu/vendor/ruby1.8/uv/syntax/twiki.syntax +241 -0
  218. data/lib/kitabu/vendor/ruby1.8/uv/syntax/txt2tags.syntax +79 -0
  219. data/lib/kitabu/vendor/ruby1.8/uv/syntax/vectorscript.syntax +57 -0
  220. data/lib/kitabu/vendor/ruby1.8/uv/syntax/xhtml_1.0.syntax +4027 -0
  221. data/lib/kitabu/vendor/ruby1.8/uv/syntax/xml.syntax +180 -0
  222. data/lib/kitabu/vendor/ruby1.8/uv/syntax/xml_strict.syntax +92 -0
  223. data/lib/kitabu/vendor/ruby1.8/uv/syntax/xsl.syntax +60 -0
  224. data/lib/kitabu/vendor/ruby1.8/uv/syntax/yaml.syntax +160 -0
  225. data/lib/kitabu/vendor/ruby1.8/uv/syntax/yui_javascript.syntax +176 -0
  226. data/lib/kitabu/vendor/ruby1.8/uv/uv.rb +88 -0
  227. data/lib/kitabu/vendor/ruby1.8/uv/uv/render_processor.rb +131 -0
  228. data/lib/kitabu/vendor/ruby1.8/uv/uv/utility.rb +67 -0
  229. data/lib/kitabu/vendor/ruby1.9/plist/plist.rb +23 -0
  230. data/lib/kitabu/vendor/ruby1.9/plist/plist/generator.rb +228 -0
  231. data/lib/kitabu/vendor/ruby1.9/plist/plist/parser.rb +225 -0
  232. data/lib/kitabu/vendor/ruby1.9/textpow/textpow.rb +10 -0
  233. data/lib/kitabu/vendor/ruby1.9/textpow/textpow/debug_processor.rb +37 -0
  234. data/lib/kitabu/vendor/ruby1.9/textpow/textpow/score_manager.rb +66 -0
  235. data/lib/kitabu/vendor/ruby1.9/textpow/textpow/syntax.rb +286 -0
  236. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/active4d.render +140 -0
  237. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/all_hallows_eve.render +104 -0
  238. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/amy.render +179 -0
  239. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/blackboard.render +119 -0
  240. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/brilliance_black.render +560 -0
  241. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/brilliance_dull.render +569 -0
  242. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/cobalt.render +170 -0
  243. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/dawn.render +134 -0
  244. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/eiffel.render +140 -0
  245. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/espresso_libre.render +131 -0
  246. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/active4d.css +114 -0
  247. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/all_hallows_eve.css +72 -0
  248. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/amy.css +147 -0
  249. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/blackboard.css +88 -0
  250. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/brilliance_black.css +605 -0
  251. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/brilliance_dull.css +599 -0
  252. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/cobalt.css +149 -0
  253. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/dawn.css +121 -0
  254. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/eiffel.css +121 -0
  255. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/espresso_libre.css +109 -0
  256. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/idle.css +62 -0
  257. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/iplastic.css +80 -0
  258. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/lazy.css +73 -0
  259. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/mac_classic.css +123 -0
  260. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/magicwb_amiga.css +104 -0
  261. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/pastels_on_dark.css +188 -0
  262. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/slush_poppies.css +85 -0
  263. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/spacecadet.css +51 -0
  264. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/sunburst.css +180 -0
  265. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/twilight.css +137 -0
  266. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/files/css/zenburnesque.css +91 -0
  267. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/idle.render +101 -0
  268. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/iplastic.render +107 -0
  269. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/lazy.render +104 -0
  270. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/mac_classic.render +143 -0
  271. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/magicwb_amiga.render +125 -0
  272. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/pastels_on_dark.render +212 -0
  273. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/slush_poppies.render +131 -0
  274. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/spacecadet.render +89 -0
  275. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/sunburst.render +194 -0
  276. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/twilight.render +161 -0
  277. data/lib/kitabu/vendor/ruby1.9/uv/render/xhtml/zenburnesque.render +134 -0
  278. data/lib/kitabu/vendor/ruby1.9/uv/syntax/actionscript.syntax +97 -0
  279. data/lib/kitabu/vendor/ruby1.9/uv/syntax/active4d.syntax +276 -0
  280. data/lib/kitabu/vendor/ruby1.9/uv/syntax/active4d_html.syntax +311 -0
  281. data/lib/kitabu/vendor/ruby1.9/uv/syntax/active4d_ini.syntax +50 -0
  282. data/lib/kitabu/vendor/ruby1.9/uv/syntax/active4d_library.syntax +21 -0
  283. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ada.syntax +33 -0
  284. data/lib/kitabu/vendor/ruby1.9/uv/syntax/antlr.syntax +151 -0
  285. data/lib/kitabu/vendor/ruby1.9/uv/syntax/apache.syntax +191 -0
  286. data/lib/kitabu/vendor/ruby1.9/uv/syntax/applescript.syntax +384 -0
  287. data/lib/kitabu/vendor/ruby1.9/uv/syntax/asp.syntax +70 -0
  288. data/lib/kitabu/vendor/ruby1.9/uv/syntax/asp_vb.net.syntax +129 -0
  289. data/lib/kitabu/vendor/ruby1.9/uv/syntax/bibtex.syntax +151 -0
  290. data/lib/kitabu/vendor/ruby1.9/uv/syntax/blog_html.syntax +41 -0
  291. data/lib/kitabu/vendor/ruby1.9/uv/syntax/blog_markdown.syntax +42 -0
  292. data/lib/kitabu/vendor/ruby1.9/uv/syntax/blog_text.syntax +27 -0
  293. data/lib/kitabu/vendor/ruby1.9/uv/syntax/blog_textile.syntax +27 -0
  294. data/lib/kitabu/vendor/ruby1.9/uv/syntax/build.syntax +53 -0
  295. data/lib/kitabu/vendor/ruby1.9/uv/syntax/bulletin_board.syntax +287 -0
  296. data/lib/kitabu/vendor/ruby1.9/uv/syntax/cake.syntax +55 -0
  297. data/lib/kitabu/vendor/ruby1.9/uv/syntax/camlp4.syntax +36 -0
  298. data/lib/kitabu/vendor/ruby1.9/uv/syntax/cm.syntax +32 -0
  299. data/lib/kitabu/vendor/ruby1.9/uv/syntax/coldfusion.syntax +119 -0
  300. data/lib/kitabu/vendor/ruby1.9/uv/syntax/context_free.syntax +176 -0
  301. data/lib/kitabu/vendor/ruby1.9/uv/syntax/cs.syntax +59 -0
  302. data/lib/kitabu/vendor/ruby1.9/uv/syntax/css.syntax +195 -0
  303. data/lib/kitabu/vendor/ruby1.9/uv/syntax/css_experimental.syntax +1925 -0
  304. data/lib/kitabu/vendor/ruby1.9/uv/syntax/csv.syntax +68 -0
  305. data/lib/kitabu/vendor/ruby1.9/uv/syntax/d.syntax +142 -0
  306. data/lib/kitabu/vendor/ruby1.9/uv/syntax/diff.syntax +81 -0
  307. data/lib/kitabu/vendor/ruby1.9/uv/syntax/dokuwiki.syntax +204 -0
  308. data/lib/kitabu/vendor/ruby1.9/uv/syntax/dot.syntax +47 -0
  309. data/lib/kitabu/vendor/ruby1.9/uv/syntax/doxygen.syntax +43 -0
  310. data/lib/kitabu/vendor/ruby1.9/uv/syntax/dylan.syntax +62 -0
  311. data/lib/kitabu/vendor/ruby1.9/uv/syntax/eiffel.syntax +78 -0
  312. data/lib/kitabu/vendor/ruby1.9/uv/syntax/erlang.syntax +922 -0
  313. data/lib/kitabu/vendor/ruby1.9/uv/syntax/f-script.syntax +80 -0
  314. data/lib/kitabu/vendor/ruby1.9/uv/syntax/fortran.syntax +141 -0
  315. data/lib/kitabu/vendor/ruby1.9/uv/syntax/fxscript.syntax +142 -0
  316. data/lib/kitabu/vendor/ruby1.9/uv/syntax/greasemonkey.syntax +34 -0
  317. data/lib/kitabu/vendor/ruby1.9/uv/syntax/gri.syntax +83 -0
  318. data/lib/kitabu/vendor/ruby1.9/uv/syntax/groovy.syntax +191 -0
  319. data/lib/kitabu/vendor/ruby1.9/uv/syntax/gtd.syntax +22 -0
  320. data/lib/kitabu/vendor/ruby1.9/uv/syntax/gtdalt.syntax +143 -0
  321. data/lib/kitabu/vendor/ruby1.9/uv/syntax/haml.syntax +88 -0
  322. data/lib/kitabu/vendor/ruby1.9/uv/syntax/haskell.syntax +88 -0
  323. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html-asp.syntax +27 -0
  324. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html.syntax +362 -0
  325. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html_django.syntax +36 -0
  326. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html_for_asp.net.syntax +424 -0
  327. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html_mason.syntax +119 -0
  328. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html_rails.syntax +40 -0
  329. data/lib/kitabu/vendor/ruby1.9/uv/syntax/html_tcl.syntax +26 -0
  330. data/lib/kitabu/vendor/ruby1.9/uv/syntax/icalendar.syntax +32 -0
  331. data/lib/kitabu/vendor/ruby1.9/uv/syntax/inform.syntax +48 -0
  332. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ini.syntax +55 -0
  333. data/lib/kitabu/vendor/ruby1.9/uv/syntax/installer_distribution_script.syntax +77 -0
  334. data/lib/kitabu/vendor/ruby1.9/uv/syntax/io.syntax +81 -0
  335. data/lib/kitabu/vendor/ruby1.9/uv/syntax/java.syntax +211 -0
  336. data/lib/kitabu/vendor/ruby1.9/uv/syntax/javaproperties.syntax +20 -0
  337. data/lib/kitabu/vendor/ruby1.9/uv/syntax/javascript.syntax +256 -0
  338. data/lib/kitabu/vendor/ruby1.9/uv/syntax/javascript_+_prototype.syntax +72 -0
  339. data/lib/kitabu/vendor/ruby1.9/uv/syntax/javascript_+_prototype_bracketed.syntax +140 -0
  340. data/lib/kitabu/vendor/ruby1.9/uv/syntax/jquery_javascript.syntax +114 -0
  341. data/lib/kitabu/vendor/ruby1.9/uv/syntax/json.syntax +136 -0
  342. data/lib/kitabu/vendor/ruby1.9/uv/syntax/languagedefinition.syntax +708 -0
  343. data/lib/kitabu/vendor/ruby1.9/uv/syntax/latex.syntax +566 -0
  344. data/lib/kitabu/vendor/ruby1.9/uv/syntax/latex_beamer.syntax +41 -0
  345. data/lib/kitabu/vendor/ruby1.9/uv/syntax/latex_log.syntax +50 -0
  346. data/lib/kitabu/vendor/ruby1.9/uv/syntax/latex_memoir.syntax +64 -0
  347. data/lib/kitabu/vendor/ruby1.9/uv/syntax/lexflex.syntax +219 -0
  348. data/lib/kitabu/vendor/ruby1.9/uv/syntax/lighttpd.syntax +54 -0
  349. data/lib/kitabu/vendor/ruby1.9/uv/syntax/lilypond.syntax +492 -0
  350. data/lib/kitabu/vendor/ruby1.9/uv/syntax/lisp.syntax +61 -0
  351. data/lib/kitabu/vendor/ruby1.9/uv/syntax/literate_haskell.syntax +24 -0
  352. data/lib/kitabu/vendor/ruby1.9/uv/syntax/logo.syntax +29 -0
  353. data/lib/kitabu/vendor/ruby1.9/uv/syntax/logtalk.syntax +152 -0
  354. data/lib/kitabu/vendor/ruby1.9/uv/syntax/lua.syntax +86 -0
  355. data/lib/kitabu/vendor/ruby1.9/uv/syntax/m.syntax +142 -0
  356. data/lib/kitabu/vendor/ruby1.9/uv/syntax/macports_portfile.syntax +163 -0
  357. data/lib/kitabu/vendor/ruby1.9/uv/syntax/makefile.syntax +36 -0
  358. data/lib/kitabu/vendor/ruby1.9/uv/syntax/man.syntax +17 -0
  359. data/lib/kitabu/vendor/ruby1.9/uv/syntax/mediawiki.syntax +567 -0
  360. data/lib/kitabu/vendor/ruby1.9/uv/syntax/mips.syntax +66 -0
  361. data/lib/kitabu/vendor/ruby1.9/uv/syntax/mod_perl.syntax +50 -0
  362. data/lib/kitabu/vendor/ruby1.9/uv/syntax/modula-3.syntax +47 -0
  363. data/lib/kitabu/vendor/ruby1.9/uv/syntax/moinmoin.syntax +189 -0
  364. data/lib/kitabu/vendor/ruby1.9/uv/syntax/mootools.syntax +572 -0
  365. data/lib/kitabu/vendor/ruby1.9/uv/syntax/movable_type.syntax +162 -0
  366. data/lib/kitabu/vendor/ruby1.9/uv/syntax/multimarkdown.syntax +39 -0
  367. data/lib/kitabu/vendor/ruby1.9/uv/syntax/objective-c++.syntax +18 -0
  368. data/lib/kitabu/vendor/ruby1.9/uv/syntax/objective-c.syntax +233 -0
  369. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ocaml.syntax +764 -0
  370. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ocamllex.syntax +167 -0
  371. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ocamlyacc.syntax +184 -0
  372. data/lib/kitabu/vendor/ruby1.9/uv/syntax/opengl.syntax +14 -0
  373. data/lib/kitabu/vendor/ruby1.9/uv/syntax/pascal.syntax +77 -0
  374. data/lib/kitabu/vendor/ruby1.9/uv/syntax/perl.syntax +1115 -0
  375. data/lib/kitabu/vendor/ruby1.9/uv/syntax/plain_text.syntax +32 -0
  376. data/lib/kitabu/vendor/ruby1.9/uv/syntax/postscript.syntax +114 -0
  377. data/lib/kitabu/vendor/ruby1.9/uv/syntax/processing.syntax +106 -0
  378. data/lib/kitabu/vendor/ruby1.9/uv/syntax/prolog.syntax +40 -0
  379. data/lib/kitabu/vendor/ruby1.9/uv/syntax/property_list.syntax +635 -0
  380. data/lib/kitabu/vendor/ruby1.9/uv/syntax/python.syntax +868 -0
  381. data/lib/kitabu/vendor/ruby1.9/uv/syntax/python_django.syntax +21 -0
  382. data/lib/kitabu/vendor/ruby1.9/uv/syntax/qmake_project.syntax +114 -0
  383. data/lib/kitabu/vendor/ruby1.9/uv/syntax/qt_c++.syntax +26 -0
  384. data/lib/kitabu/vendor/ruby1.9/uv/syntax/quake3_config.syntax +32 -0
  385. data/lib/kitabu/vendor/ruby1.9/uv/syntax/r.syntax +81 -0
  386. data/lib/kitabu/vendor/ruby1.9/uv/syntax/r_console.syntax +16 -0
  387. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ragel.syntax +201 -0
  388. data/lib/kitabu/vendor/ruby1.9/uv/syntax/rd_r_documentation.syntax +91 -0
  389. data/lib/kitabu/vendor/ruby1.9/uv/syntax/regexp.syntax +50 -0
  390. data/lib/kitabu/vendor/ruby1.9/uv/syntax/release_notes.syntax +46 -0
  391. data/lib/kitabu/vendor/ruby1.9/uv/syntax/remind.syntax +253 -0
  392. data/lib/kitabu/vendor/ruby1.9/uv/syntax/restructuredtext.syntax +250 -0
  393. data/lib/kitabu/vendor/ruby1.9/uv/syntax/rez.syntax +80 -0
  394. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ruby.syntax +1035 -0
  395. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ruby_experimental.syntax +145 -0
  396. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ruby_on_rails.syntax +88 -0
  397. data/lib/kitabu/vendor/ruby1.9/uv/syntax/s5.syntax +69 -0
  398. data/lib/kitabu/vendor/ruby1.9/uv/syntax/scheme.syntax +347 -0
  399. data/lib/kitabu/vendor/ruby1.9/uv/syntax/scilab.syntax +41 -0
  400. data/lib/kitabu/vendor/ruby1.9/uv/syntax/setext.syntax +147 -0
  401. data/lib/kitabu/vendor/ruby1.9/uv/syntax/shell-unix-generic.syntax +384 -0
  402. data/lib/kitabu/vendor/ruby1.9/uv/syntax/slate.syntax +149 -0
  403. data/lib/kitabu/vendor/ruby1.9/uv/syntax/sql.syntax +237 -0
  404. data/lib/kitabu/vendor/ruby1.9/uv/syntax/sql_rails.syntax +18 -0
  405. data/lib/kitabu/vendor/ruby1.9/uv/syntax/ssh-config.syntax +33 -0
  406. data/lib/kitabu/vendor/ruby1.9/uv/syntax/standard_ml.syntax +121 -0
  407. data/lib/kitabu/vendor/ruby1.9/uv/syntax/strings_file.syntax +39 -0
  408. data/lib/kitabu/vendor/ruby1.9/uv/syntax/subversion_commit_message.syntax +36 -0
  409. data/lib/kitabu/vendor/ruby1.9/uv/syntax/sweave.syntax +84 -0
  410. data/lib/kitabu/vendor/ruby1.9/uv/syntax/swig.syntax +57 -0
  411. data/lib/kitabu/vendor/ruby1.9/uv/syntax/tcl.syntax +152 -0
  412. data/lib/kitabu/vendor/ruby1.9/uv/syntax/template_toolkit.syntax +121 -0
  413. data/lib/kitabu/vendor/ruby1.9/uv/syntax/tex.syntax +86 -0
  414. data/lib/kitabu/vendor/ruby1.9/uv/syntax/tex_math.syntax +49 -0
  415. data/lib/kitabu/vendor/ruby1.9/uv/syntax/textile.syntax +215 -0
  416. data/lib/kitabu/vendor/ruby1.9/uv/syntax/tsv.syntax +50 -0
  417. data/lib/kitabu/vendor/ruby1.9/uv/syntax/twiki.syntax +241 -0
  418. data/lib/kitabu/vendor/ruby1.9/uv/syntax/txt2tags.syntax +79 -0
  419. data/lib/kitabu/vendor/ruby1.9/uv/syntax/vectorscript.syntax +57 -0
  420. data/lib/kitabu/vendor/ruby1.9/uv/syntax/xhtml_1.0.syntax +4027 -0
  421. data/lib/kitabu/vendor/ruby1.9/uv/syntax/xml.syntax +180 -0
  422. data/lib/kitabu/vendor/ruby1.9/uv/syntax/xml_strict.syntax +92 -0
  423. data/lib/kitabu/vendor/ruby1.9/uv/syntax/xsl.syntax +60 -0
  424. data/lib/kitabu/vendor/ruby1.9/uv/syntax/yaml.syntax +160 -0
  425. data/lib/kitabu/vendor/ruby1.9/uv/syntax/yui_javascript.syntax +176 -0
  426. data/lib/kitabu/vendor/ruby1.9/uv/uv.rb +89 -0
  427. data/lib/kitabu/vendor/ruby1.9/uv/uv/render_processor.rb +132 -0
  428. data/lib/kitabu/vendor/ruby1.9/uv/uv/utility.rb +68 -0
  429. data/spec/exit_matcher.rb +45 -0
  430. data/spec/fixtures/rails-guides/code/sample.rb +7 -0
  431. data/spec/kitabu/base_spec.rb +159 -0
  432. data/spec/kitabu/blackcloth_spec.rb +36 -0
  433. data/spec/kitabu/bug_fix_spec.rb +25 -0
  434. data/spec/kitabu/command_spec.rb +82 -0
  435. data/spec/kitabu/syntax_spec.rb +90 -0
  436. data/spec/kitabu/toc_spec.rb +79 -0
  437. data/spec/spec_helper.rb +30 -0
  438. data/templates/Rakefile +3 -0
  439. data/templates/config.yml +9 -0
  440. data/templates/layouts/boom/layout.css +469 -0
  441. data/templates/layouts/boom/layout.html +37 -0
  442. data/templates/syntax.css +1065 -0
  443. data/templates/themes/active4d.css +114 -0
  444. data/templates/themes/blackboard.css +88 -0
  445. data/templates/themes/dawn.css +121 -0
  446. data/templates/themes/eiffel.css +121 -0
  447. data/templates/themes/idle.css +62 -0
  448. data/templates/themes/iplastic.css +80 -0
  449. data/templates/themes/lazy.css +73 -0
  450. data/templates/themes/mac_classic.css +123 -0
  451. data/templates/themes/slush_poppies.css +85 -0
  452. data/templates/themes/sunburst.css +180 -0
  453. data/templates/user.css +1 -0
  454. metadata +518 -0
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+ KITABU_HELP = <<-TXT
3
+ The 'kitabu' command creates a new book with a default
4
+ directory structure at the path you specify.
5
+
6
+ == Usage
7
+ kitabu [options] path
8
+
9
+ For help use: kitabu -h
10
+
11
+ == Options
12
+ -h, --help Displays help message
13
+ -v, --version Display the version, then exit
14
+ -l, --layout Specify which layout to use
15
+
16
+ == Examples
17
+ Using defaults.
18
+ kitabu mybook
19
+
20
+ Specify layout.
21
+ kitabu -l boom mybook
22
+ kitabu --layout boom mybook
23
+
24
+ == Author
25
+ Nando Vieira
26
+ http://simplesideias.com.br
27
+
28
+ == Copyright
29
+ Copyright (c) 2008-2009 Nando Vieira.
30
+ Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
31
+ TXT
32
+
33
+ module Kitabu
34
+ module Command
35
+ extend self
36
+
37
+ def run!
38
+ options = {}
39
+
40
+ opts = OptionParser.new do |opts|
41
+ opts.banner = "The 'kitabu' command creates a new book with a default\ndirectory structure at the path you specify."
42
+
43
+ opts.separator ""
44
+ opts.separator "Options:"
45
+
46
+ opts.on("-l", "--layout LAYOUT", "Specify which layout to use.", "Available: #{Kitabu::Base.layouts.join(', ')}") do |layout|
47
+ if layout && !Kitabu::Base.layout?(layout)
48
+ output "Invalid layout"
49
+ exit 1
50
+ end
51
+
52
+ options[:layout] = layout
53
+ end
54
+
55
+ opts.on("-h", "--help", "Show help") do
56
+ output KITABU_HELP
57
+ exit 0
58
+ end
59
+
60
+ opts.on_tail("-v", "--version", "Show version") do
61
+ output Kitabu::VERSION
62
+ exit 0
63
+ end
64
+ end
65
+
66
+ args = ARGV.dup
67
+ other_args = opts.permute!
68
+
69
+ unless other_args.any?
70
+ output KITABU_HELP
71
+ exit 0
72
+ end
73
+
74
+ path = File.expand_path(other_args.first)
75
+
76
+ if File.exists?(path)
77
+ output "Output path already exists"
78
+ exit 1
79
+ end
80
+
81
+ opts.parse!(args)
82
+
83
+ Kitabu::Templates.process!({
84
+ :layout => options[:layout],
85
+ :theme => options[:theme],
86
+ :path => path
87
+ })
88
+ end
89
+
90
+ def output(*args)
91
+ puts *args
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,964 @@
1
+ # encoding: utf-8
2
+ class RedCloth < String
3
+
4
+ VERSION = '3.0.4'
5
+ DEFAULT_RULES = [:textile, :markdown]
6
+
7
+ #
8
+ # Two accessor for setting security restrictions.
9
+ #
10
+ # This is a nice thing if you're using RedCloth for
11
+ # formatting in public places (e.g. Wikis) where you
12
+ # don't want users to abuse HTML for bad things.
13
+ #
14
+ # If +:filter_html+ is set, HTML which wasn't
15
+ # created by the Textile processor will be escaped.
16
+ #
17
+ # If +:filter_styles+ is set, it will also disable
18
+ # the style markup specifier. ('{color: red}')
19
+ #
20
+ attr_accessor :filter_html, :filter_styles
21
+
22
+ #
23
+ # Accessor for toggling hard breaks.
24
+ #
25
+ # If +:hard_breaks+ is set, single newlines will
26
+ # be converted to HTML break tags. This is the
27
+ # default behavior for traditional RedCloth.
28
+ #
29
+ attr_accessor :hard_breaks
30
+
31
+ # Accessor for toggling lite mode.
32
+ #
33
+ # In lite mode, block-level rules are ignored. This means
34
+ # that tables, paragraphs, lists, and such aren't available.
35
+ # Only the inline markup for bold, italics, entities and so on.
36
+ #
37
+ # r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
38
+ # r.to_html
39
+ # #=> "And then? She <strong>fell</strong>!"
40
+ #
41
+ attr_accessor :lite_mode
42
+
43
+ #
44
+ # Accessor for toggling span caps.
45
+ #
46
+ # Textile places `span' tags around capitalized
47
+ # words by default, but this wreaks havoc on Wikis.
48
+ # If +:no_span_caps+ is set, this will be
49
+ # suppressed.
50
+ #
51
+ attr_accessor :no_span_caps
52
+
53
+ #
54
+ # Establishes the markup predence. Available rules include:
55
+ #
56
+ # == Textile Rules
57
+ #
58
+ # The following textile rules can be set individually. Or add the complete
59
+ # set of rules with the single :textile rule, which supplies the rule set in
60
+ # the following precedence:
61
+ #
62
+ # refs_textile:: Textile references (i.e. [hobix]http://hobix.com/)
63
+ # block_textile_table:: Textile table block structures
64
+ # block_textile_lists:: Textile list structures
65
+ # block_textile_prefix:: Textile blocks with prefixes (i.e. bq., h2., etc.)
66
+ # inline_textile_image:: Textile inline images
67
+ # inline_textile_link:: Textile inline links
68
+ # inline_textile_span:: Textile inline spans
69
+ # glyphs_textile:: Textile entities (such as em-dashes and smart quotes)
70
+ #
71
+ # == Markdown
72
+ #
73
+ # refs_markdown:: Markdown references (for example: [hobix]: http://hobix.com/)
74
+ # block_markdown_setext:: Markdown setext headers
75
+ # block_markdown_atx:: Markdown atx headers
76
+ # block_markdown_rule:: Markdown horizontal rules
77
+ # block_markdown_bq:: Markdown blockquotes
78
+ # block_markdown_lists:: Markdown lists
79
+ # inline_markdown_link:: Markdown links
80
+ attr_accessor :rules
81
+
82
+ # Returns a new RedCloth object, based on _string_ and
83
+ # enforcing all the included _restrictions_.
84
+ #
85
+ # r = RedCloth.new( "h1. A <b>bold</b> man", [:filter_html] )
86
+ # r.to_html
87
+ # #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>"
88
+ #
89
+ def initialize( string, restrictions = [] )
90
+ restrictions.each { |r| method( "#{ r }=" ).call( true ) }
91
+ super( string )
92
+ end
93
+
94
+ #
95
+ # Generates HTML from the Textile contents.
96
+ #
97
+ # r = RedCloth.new( "And then? She *fell*!" )
98
+ # r.to_html( true )
99
+ # #=>"And then? She <strong>fell</strong>!"
100
+ #
101
+ def to_html( *rules )
102
+ rules = DEFAULT_RULES if rules.empty?
103
+ # make our working copy
104
+ text = self.dup
105
+
106
+ @urlrefs = {}
107
+ @shelf = []
108
+ textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists,
109
+ :block_textile_prefix, :inline_textile_image, :inline_textile_link,
110
+ :inline_textile_code, :inline_textile_span, :glyphs_textile]
111
+ markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule,
112
+ :block_markdown_bq, :block_markdown_lists,
113
+ :inline_markdown_reflink, :inline_markdown_link]
114
+ @rules = rules.collect do |rule|
115
+ case rule
116
+ when :markdown
117
+ markdown_rules
118
+ when :textile
119
+ textile_rules
120
+ else
121
+ rule
122
+ end
123
+ end.flatten
124
+
125
+ # standard clean up
126
+ incoming_entities text
127
+ clean_white_space text
128
+
129
+ # start processor
130
+ @pre_list = []
131
+ rip_offtags text
132
+ no_textile text
133
+ hard_break text
134
+ unless @lite_mode
135
+ refs text
136
+ blocks text
137
+ end
138
+ inline text
139
+ smooth_offtags text
140
+
141
+ retrieve text
142
+
143
+ text.gsub!( /<\/?notextile>/, '' )
144
+ text.gsub!( /x%x%/, '&#38;' )
145
+ clean_html text if filter_html
146
+ text.strip!
147
+ text
148
+
149
+ end
150
+
151
+ #######
152
+ private
153
+ #######
154
+ #
155
+ # Mapping of 8-bit ASCII codes to HTML numerical entity equivalents.
156
+ # (from PyTextile)
157
+ #
158
+ TEXTILE_TAGS =
159
+
160
+ [[128, 8364], [129, 0], [130, 8218], [131, 402], [132, 8222], [133, 8230],
161
+ [134, 8224], [135, 8225], [136, 710], [137, 8240], [138, 352], [139, 8249],
162
+ [140, 338], [141, 0], [142, 0], [143, 0], [144, 0], [145, 8216], [146, 8217],
163
+ [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732],
164
+ [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]].
165
+
166
+ collect! do |a, b|
167
+ [a.chr, ( b.zero? and "" or "&#{ b };" )]
168
+ end
169
+
170
+ #
171
+ # Regular expressions to convert to HTML.
172
+ #
173
+ A_HLGN = /(?:(?:<>|<|>|\=|[()]+)+)/
174
+ A_VLGN = /[\-^~]/
175
+ C_CLAS = '(?:\([^)]+\))'
176
+ C_LNGE = '(?:\[[^\]]+\])'
177
+ C_STYL = '(?:\{[^}]+\})'
178
+ S_CSPN = '(?:\\\\\d+)'
179
+ S_RSPN = '(?:/\d+)'
180
+ A = "(?:#{A_HLGN}?#{A_VLGN}?|#{A_VLGN}?#{A_HLGN}?)"
181
+ S = "(?:#{S_CSPN}?#{S_RSPN}|#{S_RSPN}?#{S_CSPN}?)"
182
+ C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)"
183
+ # PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' )
184
+ PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' )
185
+ PUNCT_NOQ = Regexp::quote( '!"#$&\',./:;=?@\\`|' )
186
+ PUNCT_Q = Regexp::quote( '*-_+^~%' )
187
+ HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)'
188
+
189
+ # Text markup tags, don't conflict with block tags
190
+ SIMPLE_HTML_TAGS = [
191
+ 'tt', 'b', 'i', 'big', 'small', 'em', 'strong', 'dfn', 'code',
192
+ 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'a', 'img', 'br',
193
+ 'br', 'map', 'q', 'sub', 'sup', 'span', 'bdo'
194
+ ]
195
+
196
+ QTAGS = [
197
+ ['**', 'b'],
198
+ ['*', 'strong'],
199
+ ['??', 'cite', :limit],
200
+ ['-', 'del', :limit],
201
+ ['__', 'i'],
202
+ ['_', 'em', :limit],
203
+ ['%', 'span', :limit],
204
+ ['+', 'ins', :limit],
205
+ ['^', 'sup'],
206
+ ['~', 'sub']
207
+ ]
208
+ QTAGS.collect! do |rc, ht, rtype|
209
+ rcq = Regexp::quote rc
210
+ re =
211
+ case rtype
212
+ when :limit
213
+ /(\W)
214
+ (#{rcq})
215
+ (#{C})
216
+ (?::(\S+?))?
217
+ (\S.*?\S|\S)
218
+ #{rcq}
219
+ (?=\W)/x
220
+ else
221
+ /(#{rcq})
222
+ (#{C})
223
+ (?::(\S+))?
224
+ (\S.*?\S|\S)
225
+ #{rcq}/xm
226
+ end
227
+ [rc, ht, re, rtype]
228
+ end
229
+
230
+ # Elements to handle
231
+ GLYPHS = [
232
+ # [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
233
+ [ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)\'/, '\1&#8217;' ], # single closing
234
+ [ /\'(?=[#{PUNCT_Q}]*(s\b|[\s#{PUNCT_NOQ}]))/, '&#8217;' ], # single closing
235
+ [ /\'/, '&#8216;' ], # single opening
236
+ [ /</, '&lt;' ], # less-than
237
+ [ />/, '&gt;' ], # greater-than
238
+ # [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
239
+ [ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)"/, '\1&#8221;' ], # double closing
240
+ [ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '&#8221;' ], # double closing
241
+ [ /"/, '&#8220;' ], # double opening
242
+ [ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
243
+ [ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
244
+ [ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
245
+ [ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
246
+ [ /\s->\s/, ' &rarr; ' ], # right arrow
247
+ [ /\s-\s/, ' &#8211; ' ], # en dash
248
+ [ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
249
+ [ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
250
+ [ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
251
+ [ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
252
+ ]
253
+
254
+ H_ALGN_VALS = {
255
+ '<' => 'left',
256
+ '=' => 'center',
257
+ '>' => 'right',
258
+ '<>' => 'justify'
259
+ }
260
+
261
+ V_ALGN_VALS = {
262
+ '^' => 'top',
263
+ '-' => 'middle',
264
+ '~' => 'bottom'
265
+ }
266
+
267
+ #
268
+ # Flexible HTML escaping
269
+ #
270
+ def htmlesc( str, mode )
271
+ str.gsub!( '&', '&amp;' )
272
+ str.gsub!( '"', '&quot;' ) if mode != :NoQuotes
273
+ str.gsub!( "'", '&#039;' ) if mode == :Quotes
274
+ str.gsub!( '<', '&lt;')
275
+ str.gsub!( '>', '&gt;')
276
+ end
277
+
278
+ # Search and replace for Textile glyphs (quotes, dashes, other symbols)
279
+ def pgl( text )
280
+ GLYPHS.each do |re, resub, tog|
281
+ next if tog and method( tog ).call
282
+ text.gsub! re, resub
283
+ end
284
+ end
285
+
286
+ # Parses Textile attribute lists and builds an HTML attribute string
287
+ def pba( text_in, element = "" )
288
+
289
+ return '' unless text_in
290
+
291
+ style = []
292
+ text = text_in.dup
293
+ if element == 'td'
294
+ colspan = $1 if text =~ /\\(\d+)/
295
+ rowspan = $1 if text =~ /\/(\d+)/
296
+ style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN
297
+ end
298
+
299
+ style << "#{ $1 };" if not filter_styles and
300
+ text.sub!( /\{([^}]*)\}/, '' )
301
+
302
+ lang = $1 if
303
+ text.sub!( /\[([^)]+?)\]/, '' )
304
+
305
+ cls = $1 if
306
+ text.sub!( /\(([^()]+?)\)/, '' )
307
+
308
+ style << "padding-left:#{ $1.length }em;" if
309
+ text.sub!( /([(]+)/, '' )
310
+
311
+ style << "padding-right:#{ $1.length }em;" if text.sub!( /([)]+)/, '' )
312
+
313
+ style << "text-align:#{ h_align( $& ) };" if text =~ A_HLGN
314
+
315
+ cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/
316
+
317
+ atts = ''
318
+ atts << " style=\"#{ style.join }\"" unless style.empty?
319
+ atts << " class=\"#{ cls }\"" unless cls.to_s.empty?
320
+ atts << " lang=\"#{ lang }\"" if lang
321
+ atts << " id=\"#{ id }\"" if id
322
+ atts << " colspan=\"#{ colspan }\"" if colspan
323
+ atts << " rowspan=\"#{ rowspan }\"" if rowspan
324
+
325
+ atts
326
+ end
327
+
328
+ TABLE_RE = /^(?:table(_?#{S}#{A}#{C})\. ?\n)?^(#{A}#{C}\.? ?\|.*?\|)(\n\n|\Z)/m
329
+
330
+ # Parses a Textile table block, building HTML from the result.
331
+ def block_textile_table( text )
332
+ text.gsub!( TABLE_RE ) do |matches|
333
+
334
+ tatts, fullrow = $~[1..2]
335
+ tatts = pba( tatts, 'table' )
336
+ tatts = shelve( tatts ) if tatts
337
+ rows = []
338
+
339
+ fullrow.
340
+ split( /\|$/m ).
341
+ delete_if { |x| x.empty? }.
342
+ each do |row|
343
+
344
+ ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m
345
+
346
+ cells = []
347
+ row.split( '|' ).each do |cell|
348
+ ctyp = 'd'
349
+ ctyp = 'h' if cell =~ /^_/
350
+
351
+ catts = ''
352
+ catts, cell = pba( $1, 'td' ), $2 if cell =~ /^(_?#{S}#{A}#{C}\. ?)(.*)/
353
+
354
+ unless cell.strip.empty?
355
+ catts = shelve( catts ) if catts
356
+ cells << "\t\t\t<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>"
357
+ end
358
+ end
359
+ ratts = shelve( ratts ) if ratts
360
+ rows << "\t\t<tr#{ ratts }>\n#{ cells.join( "\n" ) }\n\t\t</tr>"
361
+ end
362
+ "\t<table#{ tatts }>\n#{ rows.join( "\n" ) }\n\t</table>\n\n"
363
+ end
364
+ end
365
+
366
+ LISTS_RE = /^([#*]+?#{C} .*?)$(?![^#*])/m
367
+ LISTS_CONTENT_RE = /^([#*]+)(#{A}#{C}) (.*)$/m
368
+
369
+ # Parses Textile lists and generates HTML
370
+ def block_textile_lists( text )
371
+ text.gsub!( LISTS_RE ) do |match|
372
+ lines = match.split( /\n/ )
373
+ last_line = -1
374
+ depth = []
375
+ lines.each_with_index do |line, line_id|
376
+ if line =~ LISTS_CONTENT_RE
377
+ tl,atts,content = $~[1..3]
378
+ if depth.last
379
+ if depth.last.length > tl.length
380
+ (depth.length - 1).downto(0) do |i|
381
+ break if depth[i].length == tl.length
382
+ lines[line_id - 1] << "</li>\n\t</#{ lT( depth[i] ) }l>\n\t"
383
+ depth.pop
384
+ end
385
+ end
386
+ if depth.last and depth.last.length == tl.length
387
+ lines[line_id - 1] << '</li>'
388
+ end
389
+ end
390
+ unless depth.last == tl
391
+ depth << tl
392
+ atts = pba( atts )
393
+ atts = shelve( atts ) if atts
394
+ lines[line_id] = "\t<#{ lT(tl) }l#{ atts }>\n\t<li>#{ content }"
395
+ else
396
+ lines[line_id] = "\t\t<li>#{ content }"
397
+ end
398
+ last_line = line_id
399
+
400
+ else
401
+ last_line = line_id
402
+ end
403
+ if line_id - last_line > 1 or line_id == lines.length - 1
404
+ depth.delete_if do |v|
405
+ lines[last_line] << "</li>\n\t</#{ lT( v ) }l>"
406
+ end
407
+ end
408
+ end
409
+ lines.join( "\n" )
410
+ end
411
+ end
412
+
413
+ CODE_RE = /(\W)
414
+ @
415
+ (?:\|(\w+?)\|)?
416
+ (.+?)
417
+ @
418
+ (?=\W)/x
419
+
420
+ def inline_textile_code( text )
421
+ text.gsub!( CODE_RE ) do |m|
422
+ before,lang,code,after = $~[1..4]
423
+ lang = " lang=\"#{ lang }\"" if lang
424
+ rip_offtags( "#{ before }<code#{ lang }>#{ code }</code>#{ after }" )
425
+ end
426
+ end
427
+
428
+ def lT( text )
429
+ text =~ /\#$/ ? 'o' : 'u'
430
+ end
431
+
432
+ def hard_break( text )
433
+ text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
434
+ end
435
+
436
+ BLOCKS_GROUP_RE = /\n{2,}(?! )/m
437
+
438
+ def blocks( text, deep_code = false )
439
+ text.replace( text.split( BLOCKS_GROUP_RE ).collect do |blk|
440
+ plain = blk !~ /\A[#*> ]/
441
+
442
+ # skip blocks that are complex HTML
443
+ if blk =~ /^<\/?(\w+).*>/ and not SIMPLE_HTML_TAGS.include? $1
444
+ blk
445
+ else
446
+ # search for indentation levels
447
+ blk.strip!
448
+ if blk.empty?
449
+ blk
450
+ else
451
+ code_blk = nil
452
+ blk.gsub!( /((?:\n(?:\n^ +[^\n]*)+)+)/m ) do |iblk|
453
+ flush_left iblk
454
+ blocks iblk, plain
455
+ iblk.gsub( /^(\S)/, "\t\\1" )
456
+ if plain
457
+ code_blk = iblk; ""
458
+ else
459
+ iblk
460
+ end
461
+ end
462
+
463
+ block_applied = 0
464
+ @rules.each do |rule_name|
465
+ block_applied += 1 if ( rule_name.to_s.match /^block_/ and method( rule_name ).call( blk ) )
466
+ end
467
+ if block_applied.zero?
468
+ if deep_code
469
+ blk = "\t<pre><code>#{ blk }</code></pre>"
470
+ else
471
+ blk = "\t<p>#{ blk }</p>"
472
+ end
473
+ end
474
+ # hard_break blk
475
+ blk + "\n#{ code_blk }"
476
+ end
477
+ end
478
+
479
+ end.join( "\n\n" ) )
480
+ end
481
+
482
+ def textile_bq( tag, atts, cite, content )
483
+ cite, cite_title = check_refs( cite )
484
+ cite = " cite=\"#{ cite }\"" if cite
485
+ atts = shelve( atts ) if atts
486
+ "\t<blockquote#{ cite }>\n\t\t<p#{ atts }>#{ content }</p>\n\t</blockquote>"
487
+ end
488
+
489
+ def textile_p( tag, atts, cite, content )
490
+ atts = shelve( atts ) if atts
491
+ "\t<#{ tag }#{ atts }>#{ content }</#{ tag }>"
492
+ end
493
+
494
+ alias textile_h1 textile_p
495
+ alias textile_h2 textile_p
496
+ alias textile_h3 textile_p
497
+ alias textile_h4 textile_p
498
+ alias textile_h5 textile_p
499
+ alias textile_h6 textile_p
500
+
501
+ def textile_fn_( tag, num, atts, cite, content )
502
+ atts << " id=\"fn#{ num }\""
503
+ content = "<sup>#{ num }</sup> #{ content }"
504
+ atts = shelve( atts ) if atts
505
+ "\t<p#{ atts }>#{ content }</p>"
506
+ end
507
+
508
+ BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m
509
+
510
+ def block_textile_prefix( text )
511
+ if text =~ BLOCK_RE
512
+ tag,tagpre,num,atts,cite,content = $~[1..6]
513
+ atts = pba( atts )
514
+
515
+ # pass to prefix handler
516
+ if respond_to? "textile_#{ tag }", true
517
+ text.gsub!( $&, method( "textile_#{ tag }" ).call( tag, atts, cite, content ) )
518
+ elsif respond_to? "textile_#{ tagpre }_", true
519
+ text.gsub!( $&, method( "textile_#{ tagpre }_" ).call( tagpre, num, atts, cite, content ) )
520
+ end
521
+ end
522
+ end
523
+
524
+ SETEXT_RE = /\A(.+?)\n([=-])[=-]* *$/m
525
+ def block_markdown_setext( text )
526
+ if text =~ SETEXT_RE
527
+ tag = if $2 == "="; "h1"; else; "h2"; end
528
+ blk, cont = "<#{ tag }>#{ $1 }</#{ tag }>", $'
529
+ blocks cont
530
+ text.replace( blk + cont )
531
+ end
532
+ end
533
+
534
+ ATX_RE = /\A(\#{1,6}) # $1 = string of #'s
535
+ [ ]*
536
+ (.+?) # $2 = Header text
537
+ [ ]*
538
+ \#* # optional closing #'s (not counted)
539
+ $/x
540
+ def block_markdown_atx( text )
541
+ if text =~ ATX_RE
542
+ tag = "h#{ $1.length }"
543
+ blk, cont = "<#{ tag }>#{ $2 }</#{ tag }>\n\n", $'
544
+ blocks cont
545
+ text.replace( blk + cont )
546
+ end
547
+ end
548
+
549
+ MARKDOWN_BQ_RE = /\A(^ *> ?.+$(.+\n)*\n*)+/m
550
+
551
+ def block_markdown_bq( text )
552
+ text.gsub!( MARKDOWN_BQ_RE ) do |blk|
553
+ blk.gsub!( /^ *> ?/, '' )
554
+ flush_left blk
555
+ blocks blk
556
+ blk.gsub!( /^(\S)/, "\t\\1" )
557
+ "<blockquote>\n#{ blk }\n</blockquote>\n\n"
558
+ end
559
+ end
560
+
561
+ MARKDOWN_RULE_RE = /^(#{
562
+ ['*', '-', '_'].collect { |ch| '( ?' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' )
563
+ })$/
564
+
565
+ def block_markdown_rule( text )
566
+ text.gsub!( MARKDOWN_RULE_RE ) do |blk|
567
+ "<hr />"
568
+ end
569
+ end
570
+
571
+ # XXX TODO XXX
572
+ def block_markdown_lists( text )
573
+ end
574
+
575
+ def inline_textile_span( text )
576
+ QTAGS.each do |qtag_rc, ht, qtag_re, rtype|
577
+ text.gsub!( qtag_re ) do |m|
578
+
579
+ case rtype
580
+ when :limit
581
+ sta,qtag,atts,cite,content = $~[1..5]
582
+ else
583
+ qtag,atts,cite,content = $~[1..4]
584
+ sta = ''
585
+ end
586
+ atts = pba( atts )
587
+ atts << " cite=\"#{ cite }\"" if cite
588
+ atts = shelve( atts ) if atts
589
+
590
+ "#{ sta }<#{ ht }#{ atts }>#{ content }</#{ ht }>"
591
+
592
+ end
593
+ end
594
+ end
595
+
596
+ LINK_RE = /
597
+ ([\s\[{(]|[#{PUNCT}])? # $pre
598
+ " # start
599
+ (#{C}) # $atts
600
+ ([^"]+?) # $text
601
+ \s?
602
+ (?:\(([^)]+?)\)(?="))? # $title
603
+ ":
604
+ (\S+?) # $url
605
+ (\/)? # $slash
606
+ ([^\w\/;]*?) # $post
607
+ (?=<|\s|$)
608
+ /x
609
+
610
+ def inline_textile_link( text )
611
+ text.gsub!( LINK_RE ) do |m|
612
+ pre,atts,text,title,url,slash,post = $~[1..7]
613
+
614
+ url, url_title = check_refs( url )
615
+ title ||= url_title
616
+
617
+ atts = pba( atts )
618
+ atts = " href=\"#{ url }#{ slash }\"#{ atts }"
619
+ atts << " title=\"#{ title }\"" if title
620
+ atts = shelve( atts ) if atts
621
+
622
+ "#{ pre }<a#{ atts }>#{ text }</a>#{ post }"
623
+ end
624
+ end
625
+
626
+ MARKDOWN_REFLINK_RE = /
627
+ \[([^\[\]]+)\] # $text
628
+ [ ]? # opt. space
629
+ (?:\n[ ]*)? # one optional newline followed by spaces
630
+ \[(.*?)\] # $id
631
+ /x
632
+
633
+ def inline_markdown_reflink( text )
634
+ text.gsub!( MARKDOWN_REFLINK_RE ) do |m|
635
+ text, id = $~[1..2]
636
+
637
+ if id.empty?
638
+ url, title = check_refs( text )
639
+ else
640
+ url, title = check_refs( id )
641
+ end
642
+
643
+ atts = " href=\"#{ url }\""
644
+ atts << " title=\"#{ title }\"" if title
645
+ atts = shelve( atts )
646
+
647
+ "<a#{ atts }>#{ text }</a>"
648
+ end
649
+ end
650
+
651
+ MARKDOWN_LINK_RE = /
652
+ \[([^\[\]]+)\] # $text
653
+ \( # open paren
654
+ [ \t]* # opt space
655
+ <?(.+?)>? # $href
656
+ [ \t]* # opt space
657
+ (?: # whole title
658
+ (['"]) # $quote
659
+ (.*?) # $title
660
+ \3 # matching quote
661
+ )? # title is optional
662
+ \)
663
+ /x
664
+
665
+ def inline_markdown_link( text )
666
+ text.gsub!( MARKDOWN_LINK_RE ) do |m|
667
+ text, url, quote, title = $~[1..4]
668
+
669
+ atts = " href=\"#{ url }\""
670
+ atts << " title=\"#{ title }\"" if title
671
+ atts = shelve( atts )
672
+
673
+ "<a#{ atts }>#{ text }</a>"
674
+ end
675
+ end
676
+
677
+ TEXTILE_REFS_RE = /(^ *)\[([^\n]+?)\](#{HYPERLINK})(?=\s|$)/
678
+ MARKDOWN_REFS_RE = /(^ *)\[([^\n]+?)\]:\s+<?(#{HYPERLINK})>?(?:\s+"((?:[^"]|\\")+)")?(?=\s|$)/m
679
+
680
+ def refs( text )
681
+ @rules.each do |rule_name|
682
+ method( rule_name ).call( text ) if rule_name.to_s.match /^refs_/
683
+ end
684
+ end
685
+
686
+ def refs_textile( text )
687
+ text.gsub!( TEXTILE_REFS_RE ) do |m|
688
+ flag, url = $~[2..3]
689
+ @urlrefs[flag.downcase] = [url, nil]
690
+ nil
691
+ end
692
+ end
693
+
694
+ def refs_markdown( text )
695
+ text.gsub!( MARKDOWN_REFS_RE ) do |m|
696
+ flag, url = $~[2..3]
697
+ title = $~[6]
698
+ @urlrefs[flag.downcase] = [url, title]
699
+ nil
700
+ end
701
+ end
702
+
703
+ def check_refs( text )
704
+ ret = @urlrefs[text.downcase] if text
705
+ ret || [text, nil]
706
+ end
707
+
708
+ IMAGE_RE = /
709
+ (<p>|.|^) # start of line?
710
+ \! # opening
711
+ (\<|\=|\>)? # optional alignment atts
712
+ (#{C}) # optional style,class atts
713
+ (?:\. )? # optional dot-space
714
+ ([^\s(!]+?) # presume this is the src
715
+ \s? # optional space
716
+ (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title
717
+ \! # closing
718
+ (?::#{ HYPERLINK })? # optional href
719
+ /x
720
+
721
+ def inline_textile_image( text )
722
+ text.gsub!( IMAGE_RE ) do |m|
723
+ stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8]
724
+ atts = pba( atts )
725
+ atts = " src=\"#{ url }\"#{ atts }"
726
+ atts << " title=\"#{ title }\"" if title
727
+ atts << " alt=\"#{ title }\""
728
+ # size = @getimagesize($url);
729
+ # if($size) $atts.= " $size[3]";
730
+
731
+ href, alt_title = check_refs( href ) if href
732
+ url, url_title = check_refs( url )
733
+
734
+ out = ''
735
+ out << "<a#{ shelve( " href=\"#{ href }\"" ) }>" if href
736
+ out << "<img#{ shelve( atts ) } />"
737
+ out << "</a>#{ href_a1 }#{ href_a2 }" if href
738
+
739
+ if algn
740
+ algn = h_align( algn )
741
+ if stln == "<p>"
742
+ out = "<p style=\"float:#{ algn }\">#{ out }"
743
+ else
744
+ out = "#{ stln }<div style=\"float:#{ algn }\">#{ out }</div>"
745
+ end
746
+ else
747
+ out = stln + out
748
+ end
749
+
750
+ out
751
+ end
752
+ end
753
+
754
+ def shelve( val )
755
+ @shelf << val
756
+ " :redsh##{ @shelf.length }:"
757
+ end
758
+
759
+ def retrieve( text )
760
+ @shelf.each_with_index do |r, i|
761
+ text.gsub!( " :redsh##{ i + 1 }:", r )
762
+ end
763
+ end
764
+
765
+ def incoming_entities( text )
766
+ ## turn any incoming ampersands into a dummy character for now.
767
+ ## This uses a negative lookahead for alphanumerics followed by a semicolon,
768
+ ## implying an incoming html entity, to be skipped
769
+
770
+ text.gsub!( /&(?![#a-z0-9]+;)/i, "x%x%" )
771
+ end
772
+
773
+ def no_textile( text )
774
+ text.gsub!( /(^|\s)==([^=]+.*?)==(\s|$)?/,
775
+ '\1<notextile>\2</notextile>\3' )
776
+ text.gsub!( /^ *==([^=]+.*?)==/m,
777
+ '\1<notextile>\2</notextile>\3' )
778
+ end
779
+
780
+ def clean_white_space( text )
781
+ # normalize line breaks
782
+ text.gsub!( /\r\n/, "\n" )
783
+ text.gsub!( /\r/, "\n" )
784
+ text.gsub!( /\t/, ' ' )
785
+ text.gsub!( /^ +$/, '' )
786
+ text.gsub!( /\n{3,}/, "\n\n" )
787
+ text.gsub!( /"$/, "\" " )
788
+
789
+ # if entire document is indented, flush
790
+ # to the left side
791
+ flush_left text
792
+ end
793
+
794
+ def flush_left( text )
795
+ indt = 0
796
+ if text =~ /^ /
797
+ while text !~ /^ {#{indt}}\S/
798
+ indt += 1
799
+ end unless text.empty?
800
+ if indt.nonzero?
801
+ text.gsub!( /^ {#{indt}}/, '' )
802
+ end
803
+ end
804
+ end
805
+
806
+ def footnote_ref( text )
807
+ text.gsub!( /\b\[([0-9]+?)\](\s)?/,
808
+ '<sup><a href="#fn\1">\1</a></sup>\2' )
809
+ end
810
+
811
+ OFFTAGS = /(code|pre|kbd|notextile)/
812
+ OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }|\Z)/mi
813
+ OFFTAG_OPEN = /<#{ OFFTAGS }/
814
+ OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/
815
+ HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
816
+ ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
817
+
818
+ def glyphs_textile( text, level = 0 )
819
+ if text !~ HASTAG_MATCH
820
+ pgl text
821
+ footnote_ref text
822
+ else
823
+ codepre = 0
824
+ text.gsub!( ALLTAG_MATCH ) do |line|
825
+ ## matches are off if we're between <code>, <pre> etc.
826
+ if $1
827
+ if line =~ OFFTAG_OPEN
828
+ codepre += 1
829
+ elsif line =~ OFFTAG_CLOSE
830
+ codepre -= 1
831
+ codepre = 0 if codepre < 0
832
+ end
833
+ elsif codepre.zero?
834
+ glyphs_textile( line, level + 1 )
835
+ else
836
+ htmlesc( line, :NoQuotes )
837
+ end
838
+ # p [level, codepre, line]
839
+
840
+ line
841
+ end
842
+ end
843
+ end
844
+
845
+ def rip_offtags( text )
846
+ if text =~ /<.*>/
847
+ ## strip and encode <pre> content
848
+ codepre, used_offtags = 0, {}
849
+ text.gsub!( OFFTAG_MATCH ) do |line|
850
+ if $3
851
+ offtag, aftertag = $4, $5
852
+ codepre += 1
853
+ used_offtags[offtag] = true
854
+ if codepre - used_offtags.length > 0
855
+ htmlesc( line, :NoQuotes ) unless used_offtags['notextile']
856
+ @pre_list.last << line
857
+ line = ""
858
+ else
859
+ htmlesc( aftertag, :NoQuotes ) if aftertag and not used_offtags['notextile']
860
+ line = "<redpre##{ @pre_list.length }>"
861
+ @pre_list << "#{ $3 }#{ aftertag }"
862
+ end
863
+ elsif $1 and codepre > 0
864
+ if codepre - used_offtags.length > 0
865
+ htmlesc( line, :NoQuotes ) unless used_offtags['notextile']
866
+ @pre_list.last << line
867
+ line = ""
868
+ end
869
+ codepre -= 1 unless codepre.zero?
870
+ used_offtags = {} if codepre.zero?
871
+ end
872
+ line
873
+ end
874
+ end
875
+ text
876
+ end
877
+
878
+ def smooth_offtags( text )
879
+ unless @pre_list.empty?
880
+ ## replace <pre> content
881
+ text.gsub!( /<redpre#(\d+)>/ ) { @pre_list[$1.to_i] }
882
+ end
883
+ end
884
+
885
+ def inline( text )
886
+ [/^inline_/, /^glyphs_/].each do |meth_re|
887
+ @rules.each do |rule_name|
888
+ method( rule_name ).call( text ) if rule_name.to_s.match( meth_re )
889
+ end
890
+ end
891
+ end
892
+
893
+ def h_align( text )
894
+ H_ALGN_VALS[text]
895
+ end
896
+
897
+ def v_align( text )
898
+ V_ALGN_VALS[text]
899
+ end
900
+
901
+ def textile_popup_help( name, windowW, windowH )
902
+ ' <a target="_blank" href="http://hobix.com/textile/#' + helpvar + '" onclick="window.open(this.href, \'popupwindow\', \'width=' + windowW + ',height=' + windowH + ',scrollbars,resizable\'); return false;">' + name + '</a><br />'
903
+ end
904
+
905
+ # HTML cleansing stuff
906
+ BASIC_TAGS = {
907
+ 'a' => ['href', 'title'],
908
+ 'img' => ['src', 'alt', 'title'],
909
+ 'br' => [],
910
+ 'i' => nil,
911
+ 'u' => nil,
912
+ 'b' => nil,
913
+ 'pre' => nil,
914
+ 'kbd' => nil,
915
+ 'code' => ['lang'],
916
+ 'cite' => nil,
917
+ 'strong' => nil,
918
+ 'em' => nil,
919
+ 'ins' => nil,
920
+ 'sup' => nil,
921
+ 'sub' => nil,
922
+ 'del' => nil,
923
+ 'table' => nil,
924
+ 'tr' => nil,
925
+ 'td' => ['colspan', 'rowspan'],
926
+ 'th' => nil,
927
+ 'ol' => nil,
928
+ 'ul' => nil,
929
+ 'li' => nil,
930
+ 'p' => nil,
931
+ 'h1' => nil,
932
+ 'h2' => nil,
933
+ 'h3' => nil,
934
+ 'h4' => nil,
935
+ 'h5' => nil,
936
+ 'h6' => nil,
937
+ 'blockquote' => ['cite']
938
+ }
939
+
940
+ def clean_html( text, tags = BASIC_TAGS )
941
+ text.gsub!( /<!\[CDATA\[/, '' )
942
+ text.gsub!( /<(\/*)(\w+)([^>]*)>/ ) do
943
+ raw = $~
944
+ tag = raw[2].downcase
945
+ if tags.has_key? tag
946
+ pcs = [tag]
947
+ tags[tag].each do |prop|
948
+ ['"', "'", ''].each do |q|
949
+ q2 = ( q != '' ? q : '\s' )
950
+ if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
951
+ attrv = $1
952
+ next if prop == 'src' and attrv =~ %r{^(?!http)\w+:}
953
+ pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
954
+ break
955
+ end
956
+ end
957
+ end if tags[tag]
958
+ "<#{raw[1]}#{pcs.join " "}>"
959
+ else
960
+ " "
961
+ end
962
+ end
963
+ end
964
+ end