docgenerator 1.1.1 → 1.2.1
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/examples/docgenerator_example.rb +34 -17
- data/examples/docgenerator_example_footnote.rb +82 -61
- data/examples/docgenerator_example_list.rb +24 -18
- data/examples/docgenerator_example_restrictions.rb +17 -27
- data/examples/docgenerator_example_tabular.rb +20 -20
- data/examples/docgenerator_example_tripfalls.rb +28 -20
- data/examples/results/readme +1 -0
- data/examples/results_expected/docgenerator_example.html +39 -0
- data/examples/results_expected/docgenerator_example.pdf +0 -0
- data/examples/results_expected/docgenerator_example.tex +56 -0
- data/examples/results_expected/docgenerator_example_footnote.html +40 -0
- data/examples/results_expected/docgenerator_example_footnote.pdf +0 -0
- data/examples/results_expected/docgenerator_example_footnote.tex +50 -0
- data/examples/results_expected/docgenerator_example_list.html +18 -0
- data/examples/results_expected/docgenerator_example_list.pdf +0 -0
- data/examples/results_expected/docgenerator_example_list.tex +46 -0
- data/examples/results_expected/docgenerator_example_restrictions.html +22 -0
- data/examples/results_expected/docgenerator_example_restrictions.pdf +0 -0
- data/examples/results_expected/docgenerator_example_restrictions.tex +31 -0
- data/examples/results_expected/docgenerator_example_tabular.html +37 -0
- data/examples/results_expected/docgenerator_example_tabular.pdf +0 -0
- data/examples/results_expected/docgenerator_example_tabular.tex +41 -0
- data/examples/results_expected/docgenerator_example_tripfalls.html +27 -0
- data/examples/results_expected/docgenerator_example_tripfalls.pdf +0 -0
- data/examples/results_expected/docgenerator_example_tripfalls.tex +31 -0
- data/lib/creole/creole2doc.rb +291 -140
- data/lib/creole/creole_inclusion_and_plugins.rb +142 -39
- data/lib/creole/creole_placeholder.rb +92 -30
- data/lib/creole/creole_tabular.rb +119 -20
- data/lib/docgenerator.rb +209 -118
- data/lib/{docgenerator_attribute.rb → docgenerator/attribute.rb} +2 -1
- data/lib/{docgenerator_characters.rb → docgenerator/characters.rb} +75 -6
- data/lib/{docgenerator_css.rb → docgenerator/css.rb} +0 -0
- data/lib/docgenerator/document.rb +588 -0
- data/lib/{docgenerator_element.rb → docgenerator/element.rb} +52 -80
- data/lib/{docgenerator_elements.rb → docgenerator/elements.rb} +43 -17
- data/lib/{docgenerator_environments.rb → docgenerator/environments.rb} +20 -6
- data/lib/{docgenerator_footnote.rb → docgenerator/footnote.rb} +22 -18
- data/lib/{docgenerator_lists.rb → docgenerator/lists.rb} +17 -1
- data/lib/{docgenerator_sections.rb → docgenerator/sections.rb} +9 -1
- data/lib/docgenerator/standard.rb +81 -0
- data/lib/{docgenerator_tabular.rb → docgenerator/tabular.rb} +9 -5
- data/lib/packages/docgenerator_listings.rb +9 -5
- data/lib/packages/docgenerator_pdfpages.rb +17 -11
- data/lib/packages/docgenerator_url.rb +0 -2
- data/lib/templates/docgenerator_template.rb +66 -29
- data/lib/templates/docgenerator_template.yaml +18 -0
- data/lib/wiki2doc/wiki2docgenerator.rb +6 -2
- data/readme.rd +132 -0
- data/unittest/expected/test_document_usepackage_undefined.log +2 -0
- data/unittest/expected/test_enumerate.context +4 -0
- data/unittest/expected/test_footnote.html +4 -4
- data/unittest/expected/test_footnote.latex +4 -4
- data/unittest/expected/test_footnote_group.html +6 -6
- data/unittest/expected/test_footnote_group.latex +6 -6
- data/unittest/expected/test_href.html +2 -2
- data/unittest/expected/test_href.latex +2 -2
- data/unittest/expected/test_href.text +2 -2
- data/unittest/expected/test_itemize.context +4 -0
- data/unittest/expected/test_runtex.stdout +3 -0
- data/unittest/expected/test_runtex_2.stdout +3 -0
- data/unittest/expected/test_section.context +20 -0
- data/unittest/expected/test_tabular.html +2 -2
- data/unittest/expected/test_verbatim.html +3 -0
- data/unittest/expected/test_verbatim.latex +4 -0
- data/unittest/expected/test_verbatim_array.html +1 -0
- data/unittest/expected/test_verbatim_array.latex +2 -0
- data/unittest/expected_creole/test_creole_characters_all.html +12 -5
- data/unittest/expected_creole/test_creole_characters_all.latex +20 -6
- data/unittest/expected_creole/test_creole_comment.context +11 -0
- data/unittest/expected_creole/test_creole_comment.creole +12 -0
- data/unittest/expected_creole/test_creole_comment.html +9 -0
- data/unittest/expected_creole/test_creole_comment.latex +11 -0
- data/unittest/expected_creole/test_creole_creole1.0test.html +3 -3
- data/unittest/expected_creole/test_creole_creole1.0test.latex +3 -3
- data/unittest/expected_creole/test_creole_creole1.0test.text +4 -4
- data/unittest/expected_creole/test_creole_ignore.html +3 -0
- data/unittest/expected_creole/test_creole_ignore.latex +4 -0
- data/unittest/expected_creole/test_creole_ignore.text +2 -0
- data/unittest/expected_creole/test_creole_input.normsource +12 -12
- data/unittest/expected_creole/test_creole_input_file_simple.html +15 -0
- data/unittest/expected_creole/test_creole_input_file_simple_readlines.html +15 -0
- data/unittest/expected_creole/test_creole_links_external_implicit.html +2 -2
- data/unittest/expected_creole/test_creole_links_external_implicit.latex +2 -2
- data/unittest/expected_creole/test_creole_links_external_implicit.text +2 -2
- data/unittest/expected_creole/test_creole_links_implicit_end.creole +4 -0
- data/unittest/expected_creole/test_creole_links_implicit_end.html +3 -0
- data/unittest/expected_creole/test_creole_links_implicit_end.latex +4 -0
- data/unittest/expected_creole/test_creole_list_ul.normsource +42 -42
- data/unittest/expected_creole/test_creole_mix_titles_list.html +10 -0
- data/unittest/expected_creole/test_creole_mix_titles_list.latex +18 -0
- data/unittest/expected_creole/test_creole_mix_titles_list.text +12 -0
- data/unittest/expected_creole/test_creole_paragraphs.normsource +15 -15
- data/unittest/expected_creole/test_creole_pictures_css.html +4 -1
- data/unittest/expected_creole/test_creole_pictures_css.latex +5 -1
- data/unittest/expected_creole/test_creole_pictures_longdesc.html +3 -0
- data/unittest/expected_creole/test_creole_pictures_width.html +3 -0
- data/unittest/expected_creole/test_creole_pictures_width.latex +4 -0
- data/unittest/expected_creole/test_creole_short_html.html +3 -0
- data/unittest/expected_creole/test_creole_short_html.latex +4 -0
- data/unittest/expected_creole/test_creole_short_html.text +2 -0
- data/unittest/expected_creole/test_creole_shy.creole +6 -0
- data/unittest/expected_creole/test_creole_shy.html +6 -0
- data/unittest/expected_creole/test_creole_shy.latex +8 -0
- data/unittest/expected_creole/test_creole_shy.text +4 -0
- data/unittest/expected_creole/test_creole_tabular_with_cell_option.html +20 -0
- data/unittest/expected_creole/test_creole_toc.html +3 -1
- data/unittest/expected_creole/test_creole_toc.latex +1 -1
- data/unittest/expected_creole/test_creole_toc.text +1 -1
- data/unittest/expected_creole/test_creole_toc_level.html +7 -0
- data/unittest/expected_creole/test_creole_toc_level.latex +10 -0
- data/unittest/expected_creole/test_creole_toc_level.text +3 -0
- data/unittest/expected_creole/test_creole_toc_level_text.html +8 -0
- data/unittest/expected_creole/test_creole_toc_level_text.latex +9 -0
- data/unittest/expected_creole/test_creole_verbatim.html +1 -1
- data/unittest/expected_creole/test_creole_verbatim.latex +1 -1
- data/unittest/expected_creole/test_creole_verbatim.text +1 -1
- data/unittest/expected_creole/test_creole_verbatim_inline.html +1 -1
- data/unittest/expected_creole/test_creole_verbatim_inline.latex +1 -1
- data/unittest/expected_wiki/test_wiki_description.html +5 -5
- data/unittest/expected_wiki/test_wiki_description.latex +5 -5
- data/unittest/expected_wiki/test_wiki_description.text +5 -5
- data/unittest/expected_wiki/test_wiki_description.wiki +5 -5
- data/unittest/test_rakefile_docgenerator.rb +43 -0
- data/unittest/unittest_creole2doc.rb +415 -27
- data/unittest/unittest_docgenerator.rb +256 -23
- data/unittest/unittest_docgenerator_runtex.rb +83 -0
- data/unittest/unittest_versions.rb +44 -0
- data/unittest/unittest_wiki2doc.rb +28 -27
- metadata +473 -106
- data/lib/docgenerator_document.rb +0 -525
- data/lib/packages/docgenerator_beamer.rb +0 -253
- data/lib/yaml2presentation/yaml2presentation.rb +0 -1091
- data/unittest/expected/beamer_01_article.tex +0 -13
- data/unittest/expected/beamer_01_attachment.tex +0 -15
- data/unittest/expected/beamer_01_doc.html +0 -13
- data/unittest/expected/beamer_01_doc.tex +0 -18
- data/unittest/expected/beamer_01_notes_only.tex +0 -13
- data/unittest/expected/beamer_01_notes_onlyslideswithnotes.tex +0 -13
- data/unittest/expected/beamer_01_notes_show.tex +0 -13
- data/unittest/expected/beamer_01_presentation.tex +0 -13
- data/unittest/expected/beamer_02_doc.html +0 -29
- data/unittest/expected/beamer_02_doc.tex +0 -34
- data/unittest/expected/beamer_block.html +0 -1
- data/unittest/expected/beamer_block.latex +0 -1
- data/unittest/expected/beamer_doc_fragile_doc.tex +0 -33
- data/unittest/expected/beamer_doc_html_overview_with_detailpic_and_text_doc.html +0 -34
- data/unittest/expected/beamer_doc_html_overview_with_detailpic_doc.html +0 -34
- data/unittest/expected/beamer_doc_key_doc.html +0 -20
- data/unittest/expected/beamer_doc_key_doc.tex +0 -29
- data/unittest/expected/beamer_doc_note_doc.html +0 -30
- data/unittest/expected/beamer_doc_note_doc.tex +0 -37
- data/unittest/expected/beamer_doc_pic_bottom_doc.html +0 -24
- data/unittest/expected/beamer_doc_pic_doc.html +0 -24
- data/unittest/expected/beamer_doc_pic_doc.tex +0 -28
- data/unittest/expected/beamer_doc_pic_left_doc.html +0 -24
- data/unittest/expected/beamer_doc_pic_left_doc.tex +0 -28
- data/unittest/expected/beamer_doc_pic_ratio_doc.tex +0 -29
- data/unittest/expected/beamer_doc_pic_right_doc.html +0 -24
- data/unittest/expected/beamer_doc_pic_right_doc.tex +0 -28
- data/unittest/expected/beamer_doc_pic_top_doc.html +0 -24
- data/unittest/expected/beamer_frame.html +0 -5
- data/unittest/expected/beamer_frame.tex +0 -11
- data/unittest/expected/beamer_frame_fragile.tex +0 -7
- data/unittest/expected/beamer_frame_id.html +0 -1
- data/unittest/expected/beamer_frame_id.tex +0 -4
- data/unittest/expected/beamer_framepic.html +0 -5
- data/unittest/expected/beamer_framepic.latex +0 -1
- data/unittest/expected/beamer_framepic_link.html +0 -5
- data/unittest/expected/beamer_framepic_link.latex +0 -1
- data/unittest/expected/beamer_frametitle.html +0 -1
- data/unittest/expected/beamer_frametitle.latex +0 -1
- data/unittest/expected/beamer_note.html +0 -1
- data/unittest/expected/beamer_note.latex +0 -1
- data/unittest/expected_privat/test_creole_test_document.html +0 -6
- data/unittest/expected_wiki/test_wiki_amazon.html +0 -10
- data/unittest/expected_wiki/test_wiki_link.log +0 -3
- data/unittest/test_docgenerator.rb +0 -107
- data/unittest/unittest_yaml2pres.rb +0 -336
Binary file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
%
|
2
|
+
% Build by C:/appl/Ruby192/lib/ruby/gems/1.9.1/gems/docgenerator-1.2.1/lib/docgenerator/document.rb
|
3
|
+
% Dir: C:/usr/script/documentgenerator/examples/results
|
4
|
+
% Creator: docgenerator_example_tabular.rb
|
5
|
+
% Target: docgenerator_example_tabular.tex
|
6
|
+
% 2011/02/18 10:44:08
|
7
|
+
%
|
8
|
+
% Generation-Info-End
|
9
|
+
\documentclass[ngerman]{scrartcl}
|
10
|
+
\usepackage{babel}
|
11
|
+
\usepackage[ansinew]{inputenc}
|
12
|
+
\usepackage{hyperref}
|
13
|
+
% ----------------------------------------------------------------
|
14
|
+
|
15
|
+
\title{Testdocument with tabulars}
|
16
|
+
\hypersetup{pdftitle={Testdocument with tabulars}}
|
17
|
+
|
18
|
+
% ----------------------------------------------------------------
|
19
|
+
\begin{document}
|
20
|
+
\maketitle \section{Tabulars}
|
21
|
+
|
22
|
+
\begin{tabular}{cccc}
|
23
|
+
\multicolumn{4}{c}{Title}\\[1ex]\hline
|
24
|
+
1A & 1B & 1C & 1D\\
|
25
|
+
2A & 2B & 2C & 2D\\
|
26
|
+
3A & 3B & 3C & 3D\\
|
27
|
+
4A & 4B & 4C & 4D\\
|
28
|
+
5A & 5B & 5C & 5D\\
|
29
|
+
\end{tabular}
|
30
|
+
|
31
|
+
\begin{tabular}{cccccc}
|
32
|
+
\multicolumn{6}{c}{Title}\\[1ex]\hline
|
33
|
+
1A & 1B & 1C & 1D & 1E & 1F\\
|
34
|
+
2A & 2B & 2C & 2D & 2E & 2F\\
|
35
|
+
3A & 3B & 3C & 3D & 3E & 3F\\
|
36
|
+
4A & 4B & 4C & 4D & 4E & 4F\\
|
37
|
+
5A & 5B & 5C & 5D & 5E & 5F\\
|
38
|
+
\end{tabular}
|
39
|
+
|
40
|
+
\end{document}
|
41
|
+
% ----------------------------------------------------------------
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<!--
|
2
|
+
|
3
|
+
Build by C:/usr/script/documentgenerator/lib/docgenerator/document.rb
|
4
|
+
Dir: C:/usr/script/documentgenerator/examples/results
|
5
|
+
Creator: docgenerator_example_tripfalls.rb
|
6
|
+
Target: docgenerator_example_tripfalls.html
|
7
|
+
2011/02/18 11:23:23
|
8
|
+
|
9
|
+
Generation-Info-End
|
10
|
+
-->
|
11
|
+
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
|
12
|
+
<html>
|
13
|
+
<head >
|
14
|
+
<title>Testdocument with tripfalls</title>
|
15
|
+
</head>
|
16
|
+
<body lang = "de" ><!-- maketitle -->
|
17
|
+
<h1 >Generell Tripfalls</h1>
|
18
|
+
Some Text<br />
|
19
|
+
Some Text<h1 >Tripfalls with HTML</h1>
|
20
|
+
<h2 >Paragraph forgotten?</h2>
|
21
|
+
You may add text to the body direct.
|
22
|
+
But there is no p-tag in HTML if you don't define it.
|
23
|
+
Your HTML will be malformed and when you use CSS, you may loose your layout for paragraphs.
|
24
|
+
<h1 >Tripfalls with LaTeX</h1>
|
25
|
+
<h2 >Tabulars</h2>
|
26
|
+
</body>
|
27
|
+
</html>
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
%
|
2
|
+
% Build by C:/usr/script/documentgenerator/lib/docgenerator/document.rb
|
3
|
+
% Dir: C:/usr/script/documentgenerator/examples/results
|
4
|
+
% Creator: docgenerator_example_tripfalls.rb
|
5
|
+
% Target: docgenerator_example_tripfalls.tex
|
6
|
+
% 2011/02/18 11:23:23
|
7
|
+
%
|
8
|
+
% Generation-Info-End
|
9
|
+
\documentclass[ngerman]{scrartcl}
|
10
|
+
\usepackage{babel}
|
11
|
+
\usepackage[ansinew]{inputenc}
|
12
|
+
\usepackage{hyperref}
|
13
|
+
% ----------------------------------------------------------------
|
14
|
+
|
15
|
+
\title{Testdocument with tripfalls}
|
16
|
+
\hypersetup{pdftitle={Testdocument with tripfalls}}
|
17
|
+
|
18
|
+
% ----------------------------------------------------------------
|
19
|
+
\begin{document}
|
20
|
+
\maketitle \section{Generell Tripfalls}
|
21
|
+
Some Text\newline
|
22
|
+
Some Text\section{Tripfalls with HTML}
|
23
|
+
\subsection{Paragraph forgotten?}
|
24
|
+
You may add text to the body direct.
|
25
|
+
But there is no p-tag in HTML if you don't define it.
|
26
|
+
Your HTML will be malformed and when you use CSS, you may loose your layout for paragraphs.
|
27
|
+
\section{Tripfalls with LaTeX}
|
28
|
+
\subsection{Tabulars}
|
29
|
+
|
30
|
+
\end{document}
|
31
|
+
% ----------------------------------------------------------------
|
data/lib/creole/creole2doc.rb
CHANGED
@@ -1,24 +1,35 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
This is a Creole-to-Docgenerator converter.
|
4
|
+
The Docgenerator-data can be exported as
|
5
|
+
- HTML
|
6
|
+
- LaTeX
|
7
|
+
- Creole
|
8
|
+
- Wikimedia-like wiki
|
9
|
+
- Plain text
|
10
|
+
|
11
|
+
For another Creole-to-XHTML converter see
|
12
|
+
https://rubyforge.org/projects/wikicreole/
|
13
|
+
|
14
|
+
More about creole at http://www.wikicreole.org/
|
15
|
+
=end
|
15
16
|
|
17
|
+
class Creole
|
18
|
+
VERSION = '1.2.1'
|
19
|
+
end
|
20
|
+
#~ $:.unshift("../") #for test purposes.
|
21
|
+
#Load the same version of docgenerator
|
16
22
|
require 'docgenerator'
|
23
|
+
if Creole::VERSION != Docgenerator::VERSION
|
24
|
+
raise LoadError, "Creole V#{Creole::VERSION} needs Docgenerator #{Creole::VERSION}, but gets #{Docgenerator::VERSION}"
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
27
|
+
|
28
|
+
=begin rdoc
|
29
|
+
Some class definitions for the Creole-class.
|
30
|
+
=end
|
21
31
|
class Creole
|
32
|
+
|
22
33
|
#Little structure to store the parsing result.
|
23
34
|
Creole_line = Struct.new('Creole_line', :type, :content, :add_info)
|
24
35
|
#Define Placeholders
|
@@ -44,10 +55,18 @@ class Creole
|
|
44
55
|
'<-' => element(:leftarrow),
|
45
56
|
'<=' => element(:Leftarrow),
|
46
57
|
'_' => element(:underscore),
|
47
|
-
|
58
|
+
'…' => element(:ldots),
|
59
|
+
'‚' => element(:sbquo), # einfaches low-9-Zeichen, U+201A , ‚
|
60
|
+
'’' => element(:rsquo), #'zu ’
|
61
|
+
'„' => element(:bdquo), #"auf „
|
62
|
+
'“' => element(:ldquo), #"zu “
|
63
|
+
'–' => element(:ndash), # –
|
64
|
+
'—' => element(:mdash), # –
|
48
65
|
}
|
49
66
|
|
50
|
-
|
67
|
+
=begin rdoc
|
68
|
+
Add a quick online-help.
|
69
|
+
=end
|
51
70
|
def self.help( option = :syntax)
|
52
71
|
hlp = []
|
53
72
|
hlp << "==Creole help #{option}"
|
@@ -141,43 +160,43 @@ tabular
|
|
141
160
|
end #Creole
|
142
161
|
|
143
162
|
#Load sub-classes.
|
144
|
-
Dir.chdir(File.dirname(__FILE__)){
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
}
|
151
|
-
|
152
|
-
Dir.chdir('..'){
|
153
|
-
require 'docgenerator'
|
154
|
-
}
|
163
|
+
#~ Dir.chdir(File.dirname(__FILE__)){
|
164
|
+
require_relative 'creole_placeholder.rb'
|
165
|
+
require_relative 'creole_tabular.rb'
|
166
|
+
require_relative 'creole_inclusion_and_plugins.rb'
|
167
|
+
begin require 'privat/creole_affiliate.rb'; rescue LoadError; end #Just some privat extension
|
168
|
+
|
155
169
|
require 'log4r'
|
156
170
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
171
|
+
=begin rdoc
|
172
|
+
Build a document.
|
173
|
+
This is just a little combination of the classes Document and Creole.
|
174
|
+
|
175
|
+
For the future: This class could allow features t build one TeX-file and
|
176
|
+
multiple HTML (corresponding to pages).
|
177
|
+
|
178
|
+
HTML-pagebreak could be forced with ======== or something similar.
|
179
|
+
=end
|
165
180
|
class Creole_document
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
181
|
+
include Docgenerator #get VERSION
|
182
|
+
|
183
|
+
=begin rdoc
|
184
|
+
Define a creole document. The settings are forwarded to Document#new()
|
185
|
+
|
186
|
+
Some settings are used only directly in Creole_document.
|
187
|
+
- :with_toc: Add a table of contents at the beginning of the document.
|
188
|
+
- :content: Wiki-text. Same as Creole_document#<<
|
189
|
+
=end
|
171
190
|
def initialize( settings = {} )
|
172
191
|
@with_toc = settings[:with_toc ]
|
173
192
|
settings.delete(:with_toc) #Avoid error message in Document.new
|
174
|
-
|
193
|
+
|
175
194
|
@creole = Creole.new(
|
176
195
|
#Get content if available and delete setting to avoid error message in Document.new
|
177
196
|
:content => settings.delete(:content),
|
197
|
+
:ignore => settings.delete(:ignore),
|
178
198
|
:targetdir => settings.delete(:targetdir)
|
179
199
|
)
|
180
|
-
|
181
200
|
#fixme/ideen parameter
|
182
201
|
#preamble -> vor wiki-texten
|
183
202
|
#post -> nach wiki-texten
|
@@ -185,6 +204,9 @@ class Creole_document
|
|
185
204
|
#replacements (schon teil von document?)
|
186
205
|
|
187
206
|
@doc = Document.new(settings)
|
207
|
+
|
208
|
+
@doc.runtex = settings[:runtex] if settings[:runtex]
|
209
|
+
|
188
210
|
@log = @doc.log
|
189
211
|
|
190
212
|
@doc.body << creole
|
@@ -198,12 +220,22 @@ class Creole_document
|
|
198
220
|
def << (content)
|
199
221
|
@creole << content
|
200
222
|
end
|
201
|
-
|
223
|
+
=begin rdoc
|
224
|
+
Save the creole document.
|
225
|
+
|
226
|
+
If requested, the tableofcontents is added.
|
227
|
+
The first Creole_document#save decides, which variant is added (html/tex)
|
228
|
+
=end
|
202
229
|
def save( filename, options = {} )
|
203
|
-
if @with_toc
|
204
|
-
|
205
|
-
|
206
|
-
|
230
|
+
if @with_toc
|
231
|
+
@doc.body.insertbefore(creole, element(:htmlonly,{}, creole.toc(:level => @with_toc )))
|
232
|
+
@doc.body.insertbefore(creole, element(:latexonly,{},element(:tableofcontents).cr))
|
233
|
+
case @with_toc
|
234
|
+
when Numeric
|
235
|
+
@doc.head << element(:latexonly,{},"\\setcounter{tocdepth}{#{@with_toc}}\n")
|
236
|
+
end
|
237
|
+
@with_toc = false #Add it only once
|
238
|
+
end #@with_toc
|
207
239
|
|
208
240
|
@doc.save(filename, options )
|
209
241
|
end
|
@@ -212,31 +244,47 @@ class Creole_document
|
|
212
244
|
@doc.runtex = option
|
213
245
|
end
|
214
246
|
end
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
#
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
247
|
+
=begin rdoc
|
248
|
+
Creole is a standard wiki-syntax for wikitexts.
|
249
|
+
Definition see http://www.wikicreole.org
|
250
|
+
|
251
|
+
I liked this definition.
|
252
|
+
When you look at the website, you get a definition and
|
253
|
+
you get an explanation, why it is like this. - great!
|
254
|
+
|
255
|
+
This class gets a creole-text and translate it to elements of the docgenerator,
|
256
|
+
they can be used by Document or directly like Element#to_doc.
|
257
|
+
|
258
|
+
Example:
|
259
|
+
wiki = Creole.new()
|
260
|
+
wiki << <<txt
|
261
|
+
=Test document
|
262
|
+
This is a little test text with **bold** and //italic// text.
|
263
|
+
txt
|
264
|
+
puts wiki.to_latex()
|
265
|
+
Often I use it in combination with "Here"-Documents with __END__:
|
266
|
+
|
267
|
+
require 'creole/creole2doc'
|
268
|
+
|
269
|
+
doc = Creole_document.new()
|
270
|
+
doc << DATA
|
271
|
+
doc.save('test.html')
|
272
|
+
__END__
|
273
|
+
Content
|
274
|
+
=end
|
232
275
|
class Creole
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
276
|
+
=begin rdoc
|
277
|
+
Define the Creole-object.
|
278
|
+
|
279
|
+
Options:
|
280
|
+
- :log => Logger to catch information.
|
281
|
+
Alternativ you have access to the default logger via Creole#log
|
282
|
+
- :targetdir => directory, where you want to save the result.
|
283
|
+
This directory is important for checks for internal links.
|
284
|
+
- :ignore: A regex describing parts to be ignored during text parsing. e.g. /^#~.*$/ for usage with scite.
|
285
|
+
- :encoding: The encoding used for creole.
|
286
|
+
Default is UTF-8
|
287
|
+
=end
|
240
288
|
def initialize( options = {} )
|
241
289
|
@options = {
|
242
290
|
:name => 'Creole', #Just a name for easier debugging/logging
|
@@ -254,6 +302,8 @@ class Creole
|
|
254
302
|
5 => :h5,
|
255
303
|
6 => :h6,
|
256
304
|
},
|
305
|
+
:ignore => nil, #Define a "local" comment, e.g /^#~.*$/
|
306
|
+
:encoding => __ENCODING__,
|
257
307
|
}.update(options)
|
258
308
|
@placeholders = Placeholders.dup
|
259
309
|
@inclusions = Inclusions.dup
|
@@ -267,11 +317,11 @@ class Creole
|
|
267
317
|
@footnotegroups = {} #Collection of footnote groups
|
268
318
|
|
269
319
|
|
270
|
-
@targetdir = @options[:targetdir]
|
320
|
+
@targetdir = @options[:targetdir] if @options[:targetdir]
|
271
321
|
@log = @options[:log]
|
272
322
|
@log = Log4r::Logger.new(@options[:name], Log4r::INFO) unless @log
|
273
323
|
@log.outputters = Log4r::StdoutOutputter.new('log_stdout') if @log.outputters.empty?
|
274
|
-
|
324
|
+
|
275
325
|
self << @options[:content] if @options[:content]
|
276
326
|
end
|
277
327
|
|
@@ -294,18 +344,28 @@ class Creole
|
|
294
344
|
#All footnotegroups of the wiki
|
295
345
|
attr_reader :footnotegroups
|
296
346
|
|
297
|
-
#
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
347
|
+
#Error Class
|
348
|
+
class InputError < ArgumentError; end
|
349
|
+
=begin rdoc
|
350
|
+
Get some content.
|
351
|
+
Strings are taken like strings.
|
352
|
+
Array items are handled like lines.
|
353
|
+
|
354
|
+
It is possible to add the content of a file. Just add the open file handle.
|
355
|
+
In case of ruby scripts, the part after __END__ is used as input.
|
356
|
+
|
357
|
+
Content added with << starts always with a new paragraph, but it may contain
|
358
|
+
multiple paragraphs, lists...
|
359
|
+
=end
|
305
360
|
def << ( input )
|
306
|
-
|
361
|
+
case input
|
362
|
+
when String
|
307
363
|
source = input
|
308
|
-
|
364
|
+
when Array
|
365
|
+
#Items of the array are handled like single lines.
|
366
|
+
#The chomp avoid double \n (the array items may already have their own newlines).
|
367
|
+
source = input.map{|item| item.chomp}.join("\n") #ohne doppelte xx
|
368
|
+
when File
|
309
369
|
#If file is a ruby script, then use the wiki-code after __END__
|
310
370
|
#
|
311
371
|
#Often scripts contains there own text content after __END__.
|
@@ -319,24 +379,40 @@ class Creole
|
|
319
379
|
end
|
320
380
|
end
|
321
381
|
#Read the code
|
322
|
-
source = input.readlines.
|
382
|
+
source = input.readlines.join
|
383
|
+
else
|
384
|
+
raise InputError, "Don't know, how to handle #{input.class} in Creole#<<"
|
323
385
|
end
|
324
386
|
|
325
|
-
|
387
|
+
source_enc = source.encode(@options[:encoding])
|
388
|
+
@source << source_enc
|
326
389
|
#Parse the given source.
|
327
390
|
#This is done immediate, so you have a chance to localize the line, where an error occurs.
|
328
391
|
#(Some errors are reported later during to_doc).
|
329
|
-
#fixme:
|
392
|
+
#fixme: option to parse immediate at << or later
|
330
393
|
#immediate_parse => true...
|
331
|
-
@normsource.push( *parse(
|
394
|
+
@normsource.push( *parse( source_enc ) )
|
332
395
|
end #<< ( input )
|
333
|
-
|
334
|
-
|
396
|
+
=begin rdoc
|
397
|
+
Parse the given creole code and build a "normalized source"
|
398
|
+
=end
|
335
399
|
def parse( source = @source )
|
336
400
|
|
337
|
-
normsource = []
|
401
|
+
normsource = []
|
338
402
|
statusflag = nil #Variable to store the actual status. nil = nothing special.
|
339
403
|
normsource << Creole_line.new(:dummy)
|
404
|
+
|
405
|
+
if ! source.respond_to?(:each_with_index)
|
406
|
+
#Ruby 1.9 removed each from String
|
407
|
+
if source.respond_to? :each_line
|
408
|
+
source = source.each_line
|
409
|
+
else
|
410
|
+
@log.fatal("Unable to parse #{source.class}: #{source.inspect}" ) if @log.fatal?
|
411
|
+
return normsource
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
|
340
416
|
#
|
341
417
|
#Check code line by line
|
342
418
|
#
|
@@ -362,6 +438,14 @@ class Creole
|
|
362
438
|
#
|
363
439
|
#Parse the wiki text on line level (main structure)
|
364
440
|
case line
|
441
|
+
#Skip this line, if it correspond to a special comment-pattern.
|
442
|
+
#Can be used for application-specific comments.
|
443
|
+
#
|
444
|
+
#Example:
|
445
|
+
# :ignore => /^#~.*$/
|
446
|
+
#This comment is created by scite using Ctrl-Q (for ruby-scripts).
|
447
|
+
when @options[:ignore]
|
448
|
+
@log.info("Found comment #{$1} : #{line.inspect}" ) if @log.info?
|
365
449
|
#Headings
|
366
450
|
#http://www.wikicreole.org/wiki/Headings
|
367
451
|
#
|
@@ -376,6 +460,9 @@ class Creole
|
|
376
460
|
if $~.post_match !~ /\s*/
|
377
461
|
@log.warn("Ignore text #{$~.post_match.inspect} after title <#{line.inspect}>" ) if @log.warn?
|
378
462
|
end
|
463
|
+
#And close the actual level
|
464
|
+
#See unit test test_creole_mix_titles_list
|
465
|
+
normsource << Creole_line.new(:dummy )
|
379
466
|
#Empty line
|
380
467
|
when /^\s*$/
|
381
468
|
normsource << Creole_line.new(:dummy )
|
@@ -395,14 +482,15 @@ class Creole
|
|
395
482
|
) unless normsource.last.content.is_a?(Creole_creoletab)
|
396
483
|
normsource.last.content << line
|
397
484
|
#http://www.wikicreole.org/wiki/PreformattedAndNowiki
|
398
|
-
when /^\{\{\{\s*$/
|
485
|
+
when /^\{\{\{\s*$/ #Kind of verbatim
|
399
486
|
normsource << Creole_line.new(:pre, [], :start => lineno )
|
400
487
|
statusflag = :pre
|
401
|
-
#~ when /^<<<(.*)\|?(.*?)/ #fixme
|
488
|
+
#~ when /^<<<(.*)\|?(.*?)/ #fixme options for placeholders?
|
402
489
|
when /^<<<(.*)/
|
403
|
-
|
490
|
+
ph, par = $1.split(/\|/,2)
|
491
|
+
placeholder = @placeholders[ph].new(self, par)
|
404
492
|
if placeholder.is_a?(Creole_dummy_placeholder)
|
405
|
-
@log.warn("Unknown placeholder #{
|
493
|
+
@log.warn("Unknown placeholder #{ph.inspect} used in line #{lineno}" ) if @log.warn?
|
406
494
|
end
|
407
495
|
normsource << Creole_line.new(:placeholder, placeholder, :start => lineno )
|
408
496
|
statusflag = :placeholder
|
@@ -440,15 +528,22 @@ class Creole
|
|
440
528
|
#See http://forum.ruby-portal.de/viewtopic.php?t=3844
|
441
529
|
#
|
442
530
|
|
443
|
-
|
444
|
-
|
445
|
-
|
531
|
+
=begin rdoc
|
532
|
+
Return a table of contents as a list
|
533
|
+
=end
|
446
534
|
def toc( i_options = {})
|
447
535
|
options = {
|
448
536
|
:listtype => :ul,
|
449
537
|
:level => 4,
|
450
538
|
#~ :startlevel => 1,
|
451
539
|
}.update(i_options)
|
540
|
+
|
541
|
+
if ! options[:level].is_a?(Fixnum)
|
542
|
+
@log.error("Toc: toclevel is no number but '#{options[:level].inspect}'. Set 4") if @log.error?
|
543
|
+
options[:level] = 4
|
544
|
+
end
|
545
|
+
|
546
|
+
|
452
547
|
toclist = []
|
453
548
|
toclabel = [0] #help variable to construct labels
|
454
549
|
listtype = '*'
|
@@ -463,7 +558,13 @@ class Creole
|
|
463
558
|
|
464
559
|
@toc.each{|tocentry|
|
465
560
|
level = tocentry.add_info[:level]
|
466
|
-
|
561
|
+
|
562
|
+
#
|
563
|
+
#fixme:
|
564
|
+
#Ebenenfehler (fehlende ebene resultiert in:
|
565
|
+
# ERROR Creole: List ** with missing sublist
|
566
|
+
# --> bessere meldung
|
567
|
+
|
467
568
|
#Build the label
|
468
569
|
if level > toclabel.size
|
469
570
|
toclabel << 0
|
@@ -490,16 +591,30 @@ class Creole
|
|
490
591
|
|
491
592
|
toclist << "#{listtype * level}[[##{label}|#{tocentry.content}]]"
|
492
593
|
}
|
493
|
-
|
594
|
+
toclist = <<toc
|
595
|
+
<<<html
|
596
|
+
<div class = 'toc'>
|
597
|
+
>>>
|
598
|
+
#{toclist.join("\n")}
|
599
|
+
<<<html
|
600
|
+
</div>
|
601
|
+
>>>
|
602
|
+
toc
|
603
|
+
|
604
|
+
return Creole.new( :content => toclist, :log => @log )
|
494
605
|
end #toc
|
495
|
-
|
496
|
-
|
606
|
+
=begin rdoc
|
607
|
+
Wrapping mechanism for texts.
|
608
|
+
|
609
|
+
Don't do anything, if line_width is 0.
|
610
|
+
=end
|
497
611
|
def word_wrap(text, line_width = @options[:wrap_at] )
|
498
612
|
return text if line_width <= 0
|
499
613
|
text.gsub(/\n/, ' ').gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
|
500
614
|
end
|
501
|
-
|
502
|
-
|
615
|
+
=begin rdoc
|
616
|
+
Prepare document.
|
617
|
+
=end
|
503
618
|
def to_doc( target, options = {} )
|
504
619
|
options[:log] = @log unless options[:log]
|
505
620
|
#
|
@@ -508,10 +623,12 @@ class Creole
|
|
508
623
|
@footnotegroups = {} #Collection of footnote groups
|
509
624
|
return normsource2elements( @normsource, options ).to_doc(target, options)
|
510
625
|
end #to_doc
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
626
|
+
=begin rdoc
|
627
|
+
Take the given normsource and build a list of elements.
|
628
|
+
Used by
|
629
|
+
- Creole#to_doc
|
630
|
+
- Creole_ruby#to_doc
|
631
|
+
=end
|
515
632
|
def normsource2elements( normsource, options )
|
516
633
|
doc = []
|
517
634
|
elements = {} #little collector for lists
|
@@ -560,7 +677,7 @@ class Creole
|
|
560
677
|
end
|
561
678
|
}
|
562
679
|
when :pre
|
563
|
-
doc << element(:
|
680
|
+
doc << element(:verbatim, {}, line.content ).cR
|
564
681
|
when :hr
|
565
682
|
doc << element(:hr).cr
|
566
683
|
when :placeholder
|
@@ -574,25 +691,34 @@ class Creole
|
|
574
691
|
|
575
692
|
return doc
|
576
693
|
end #to_doc_internal
|
577
|
-
|
578
|
-
|
579
|
-
def inline( text, options )
|
694
|
+
=begin rdoc
|
695
|
+
Parse the inline text.
|
580
696
|
|
697
|
+
Options is a Hash and may contain:
|
698
|
+
* :log (default: @log)
|
699
|
+
=end
|
700
|
+
def inline( text, options )
|
701
|
+
|
702
|
+
raise ArgumentError, "Creole#inline: Options no Hash" unless options.is_a?(Hash)
|
703
|
+
options[:log] = @log unless options[:log]
|
704
|
+
options[:plugins] = @plugins unless options[:plugins]
|
705
|
+
options[:inclusions] = @inclusions unless options[:inclusions]
|
706
|
+
|
581
707
|
res = [] #result
|
582
708
|
stack = [] #
|
583
|
-
|
709
|
+
|
584
710
|
#~ http_regex =
|
585
711
|
#fixme: Only once to reduce runtime
|
586
712
|
splitregex = Regexp.new(
|
587
713
|
'(' + [
|
588
714
|
'\[\[.+?\]\]', # [[...links]]
|
589
|
-
'http
|
715
|
+
'http:\/\/.+?(\s|\Z)', #including the next space!!
|
590
716
|
'\*\*', #bold
|
591
717
|
'\/\/', #emph
|
592
718
|
'\\\\\\\\', #newline
|
593
|
-
'\{\{\{
|
594
|
-
'\{\{
|
595
|
-
'
|
719
|
+
'\{\{\{.*?\}\}\}', #inline verbatim
|
720
|
+
'\{\{.*?\}\}', #images/inclusion
|
721
|
+
'<<.*?>>', #Plugins
|
596
722
|
CHARACTERS.keys.join('|')
|
597
723
|
].join('|') + ')'
|
598
724
|
)
|
@@ -632,7 +758,11 @@ class Creole
|
|
632
758
|
case link
|
633
759
|
when /^(https?|ftp):\/\/.+?/
|
634
760
|
link = link
|
635
|
-
|
761
|
+
#local file via file://...
|
762
|
+
when /^(file):\/\/(.+)/
|
763
|
+
link = link
|
764
|
+
check_link_existence( $2, options[:log] )
|
765
|
+
when /^\./, /\S:[\\\/]/ #lokal file
|
636
766
|
link = link
|
637
767
|
check_link_existence( link, options[:log] )
|
638
768
|
when /^#/ #internal link
|
@@ -657,14 +787,17 @@ class Creole
|
|
657
787
|
#All links should be catched before
|
658
788
|
when %r{\[\[(.*)\]\]}
|
659
789
|
options[:log].error("Lost link <#{el}>") if options[:log].error?
|
790
|
+
#fixme: there are obsolete 2 additional spaces in the result.
|
660
791
|
when /^http/ #implicit link
|
661
792
|
href = element(:a, {:href=>el.strip}, el.strip )
|
793
|
+
el =~ /(\s|\Z)$/ #get the end-space/newline if available
|
794
|
+
endspace = ( ! $1.empty? ? $1 : nil )
|
662
795
|
if stack.last
|
663
796
|
stack.last << href
|
664
|
-
stack.last <<
|
797
|
+
#~ stack.last << last_char #add again the
|
665
798
|
else
|
666
799
|
res << href
|
667
|
-
res <<
|
800
|
+
#~ res << last_char #add again the end-space/newline
|
668
801
|
end
|
669
802
|
#No-wiki inline: {{{text}}}
|
670
803
|
when /\{\{\{(.*)\}\}\}/
|
@@ -681,9 +814,9 @@ class Creole
|
|
681
814
|
#Available inclusions are defined in Creole::Inclusions resp. Creole#inclusions,
|
682
815
|
when /\{\{(.+?)(?:\|(.*))?\}\}/
|
683
816
|
if stack.last
|
684
|
-
stack.last << inclusion_or_plugin($1, $2,
|
817
|
+
stack.last << inclusion_or_plugin($1, $2, options[:inclusions])
|
685
818
|
else
|
686
|
-
res << inclusion_or_plugin($1, $2,
|
819
|
+
res << inclusion_or_plugin($1, $2, options[:inclusions])
|
687
820
|
end
|
688
821
|
#Plugin
|
689
822
|
#Used like Inclusions.
|
@@ -691,9 +824,9 @@ class Creole
|
|
691
824
|
#available plugins are defined in Creole::Plugins resp. Creole#plugins
|
692
825
|
when /<<(.+?)(?:\|(.*))?>>/
|
693
826
|
if stack.last
|
694
|
-
stack.last << inclusion_or_plugin($1, $2,
|
827
|
+
stack.last << inclusion_or_plugin($1, $2, options[:plugins])
|
695
828
|
else
|
696
|
-
res << inclusion_or_plugin($1, $2,
|
829
|
+
res << inclusion_or_plugin($1, $2, options[:plugins])
|
697
830
|
end
|
698
831
|
#No special wiki command. The text is "normal" text.
|
699
832
|
else #text to add
|
@@ -720,13 +853,14 @@ class Creole
|
|
720
853
|
}
|
721
854
|
res
|
722
855
|
end #inline
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
856
|
+
=begin rdoc
|
857
|
+
Inclusion or Plugin.
|
858
|
+
creole2doc implements a general inclusion.
|
859
|
+
Main usage are pictures/images ({{picname|alt}}),
|
860
|
+
but it can be more...
|
861
|
+
|
862
|
+
The last paramter contains a hash with the supported inclusions/plugins.
|
863
|
+
=end
|
730
864
|
def inclusion_or_plugin( link, p_additions, inclusions )
|
731
865
|
|
732
866
|
addition, additions = nil
|
@@ -744,20 +878,30 @@ class Creole
|
|
744
878
|
ip = inclusion.new( link, addition, additions, self )
|
745
879
|
return ip
|
746
880
|
end #inclusion
|
747
|
-
|
748
|
-
|
881
|
+
=begin rdoc
|
882
|
+
Check for links and pictures if the target exist.
|
883
|
+
|
884
|
+
Absolute DOS-Pathes are detected (C:\...).
|
885
|
+
Relative pathes are searched from @options[:targetdir] (default '.').
|
886
|
+
=end
|
749
887
|
def check_link_existence( filename, log )
|
750
|
-
|
888
|
+
case filename
|
889
|
+
when /^.:/#absolute DOS-path
|
890
|
+
path = filename.dup
|
891
|
+
else #relative path
|
892
|
+
path = "#{@options[:targetdir]}/#{filename}".sub(/^\//, '')
|
893
|
+
end
|
894
|
+
path.sub!(/(\.html?)#.*$/, '\1') #Don't check anchor inside html
|
751
895
|
if ! File.exist?(path)
|
752
|
-
log.warn("Reference not found: <#{filename}> (looking at
|
753
|
-
log.debug("Reference not found: <#{path}>") if log.debug?
|
896
|
+
log.warn("Reference not found: <#{filename}> (looking at <#{path}>)") if log.warn?
|
897
|
+
#~ log.debug("Reference not found: <#{path}>") if log.debug?
|
754
898
|
fpath = File.expand_path("#{Dir.pwd}/#{path}")
|
755
899
|
log.debug("Reference not found: <#{fpath}>") if log.debug?
|
756
900
|
end
|
757
901
|
end #check_link_existence
|
758
902
|
end #Creole
|
759
903
|
|
760
|
-
if [__FILE__
|
904
|
+
if [__FILE__ ].include?($0)
|
761
905
|
|
762
906
|
#~ [
|
763
907
|
#~ :syntax,
|
@@ -773,5 +917,12 @@ if [__FILE__, 'creole_tabular.rb'].include?($0)
|
|
773
917
|
#~ }
|
774
918
|
|
775
919
|
#~ puts `call "../../unittest/unittest_creole2doc.rb"`
|
776
|
-
require 'quicktest'
|
920
|
+
#~ require 'quicktest'
|
921
|
+
|
922
|
+
creole = Creole.new
|
923
|
+
creole << 'x{{-}}y{{-}}z'
|
924
|
+
creole << 'x{{shy}}y{{shy}}z'
|
925
|
+
creole << ''
|
926
|
+
creole << '{{../index.html#aa}}'
|
927
|
+
puts creole.to_html
|
777
928
|
end
|