sisu 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/sisu +367 -0
- data/bin/sisugem +367 -0
- data/data/sisu/image/arrow_next_red.png +0 -0
- data/data/sisu/image/arrow_prev_red.png +0 -0
- data/data/sisu/image/arrow_up_red.png +0 -0
- data/data/sisu/image/b_bluebell.png +0 -0
- data/data/sisu/image/b_doc.png +0 -0
- data/data/sisu/image/b_epub.png +0 -0
- data/data/sisu/image/b_home.png +0 -0
- data/data/sisu/image/b_info.png +0 -0
- data/data/sisu/image/b_odf.png +0 -0
- data/data/sisu/image/b_pdf.png +0 -0
- data/data/sisu/image/b_search.png +0 -0
- data/data/sisu/image/b_toc.png +0 -0
- data/data/sisu/image/bullet_08.png +0 -0
- data/data/sisu/image/bullet_09.png +0 -0
- data/data/sisu/image/bullet_10.png +0 -0
- data/data/sisu/image/bullet_11.png +0 -0
- data/data/sisu/image/bullet_12.png +0 -0
- data/data/sisu/image/bullet_doc.png +0 -0
- data/data/sisu/image/bullet_red.png +0 -0
- data/data/sisu/image/dot_clear.png +0 -0
- data/data/sisu/image/dot_white.png +0 -0
- data/data/sisu/image/gplv3.png +0 -0
- data/data/sisu/image/gplv3_free_software.png +0 -0
- data/data/sisu/image/next.png +0 -0
- data/data/sisu/image/previous.png +0 -0
- data/data/sisu/image/rb7.ico +0 -0
- data/data/sisu/image/sisu.png +0 -0
- data/data/sisu/image/toctoc.png +0 -0
- data/data/sisu/version.yml +5 -0
- data/lib/sisu.rb +94 -0
- data/lib/sisu/air.rb +80 -0
- data/lib/sisu/ao.rb +590 -0
- data/lib/sisu/ao_character_check.rb +102 -0
- data/lib/sisu/ao_composite.rb +286 -0
- data/lib/sisu/ao_doc_objects.rb +565 -0
- data/lib/sisu/ao_doc_str.rb +2269 -0
- data/lib/sisu/ao_endnotes.rb +136 -0
- data/lib/sisu/ao_expand_insertions.rb +514 -0
- data/lib/sisu/ao_hash_digest.rb +174 -0
- data/lib/sisu/ao_idx.rb +422 -0
- data/lib/sisu/ao_images.rb +187 -0
- data/lib/sisu/ao_metadata.rb +86 -0
- data/lib/sisu/ao_misc_arrange.rb +207 -0
- data/lib/sisu/ao_numbering.rb +720 -0
- data/lib/sisu/ao_persist.rb +194 -0
- data/lib/sisu/ao_references.rb +502 -0
- data/lib/sisu/ao_syntax.rb +640 -0
- data/lib/sisu/cgi.rb +84 -0
- data/lib/sisu/cgi_pgsql.rb +270 -0
- data/lib/sisu/cgi_sql_common.rb +986 -0
- data/lib/sisu/cgi_sqlite.rb +244 -0
- data/lib/sisu/conf.rb +287 -0
- data/lib/sisu/constants.rb +388 -0
- data/lib/sisu/css.rb +3484 -0
- data/lib/sisu/db_columns.rb +1997 -0
- data/lib/sisu/db_create.rb +689 -0
- data/lib/sisu/db_dbi.rb +90 -0
- data/lib/sisu/db_drop.rb +207 -0
- data/lib/sisu/db_import.rb +877 -0
- data/lib/sisu/db_indexes.rb +146 -0
- data/lib/sisu/db_load_tuple.rb +323 -0
- data/lib/sisu/db_remove.rb +182 -0
- data/lib/sisu/db_select.rb +230 -0
- data/lib/sisu/db_sqltxt.rb +173 -0
- data/lib/sisu/db_tests.rb +114 -0
- data/lib/sisu/dbi.rb +166 -0
- data/lib/sisu/dbi_discrete.rb +206 -0
- data/lib/sisu/digests.rb +306 -0
- data/lib/sisu/dp.rb +1606 -0
- data/lib/sisu/dp_identify_markup.rb +161 -0
- data/lib/sisu/dp_make.rb +668 -0
- data/lib/sisu/embedded.rb +149 -0
- data/lib/sisu/errors.rb +84 -0
- data/lib/sisu/generic_parts.rb +131 -0
- data/lib/sisu/git.rb +277 -0
- data/lib/sisu/html.rb +775 -0
- data/lib/sisu/html_concordance.rb +391 -0
- data/lib/sisu/html_format.rb +1348 -0
- data/lib/sisu/html_harvest.rb +109 -0
- data/lib/sisu/html_harvest_author_format.rb +111 -0
- data/lib/sisu/html_harvest_authors.rb +466 -0
- data/lib/sisu/html_harvest_topics.rb +893 -0
- data/lib/sisu/html_lite_shared.rb +324 -0
- data/lib/sisu/html_manifest.rb +1032 -0
- data/lib/sisu/html_minitoc.rb +230 -0
- data/lib/sisu/html_parts.rb +437 -0
- data/lib/sisu/html_persist.rb +237 -0
- data/lib/sisu/html_promo.rb +440 -0
- data/lib/sisu/html_scroll.rb +235 -0
- data/lib/sisu/html_segments.rb +716 -0
- data/lib/sisu/html_shared.rb +62 -0
- data/lib/sisu/html_table.rb +64 -0
- data/lib/sisu/html_tune.rb +301 -0
- data/lib/sisu/hub.rb +277 -0
- data/lib/sisu/hub_actions.rb +1122 -0
- data/lib/sisu/hub_loop_markup_files.rb +170 -0
- data/lib/sisu/hub_options.rb +1695 -0
- data/lib/sisu/i18n.rb +702 -0
- data/lib/sisu/manpage.rb +377 -0
- data/lib/sisu/manpage_format.rb +85 -0
- data/lib/sisu/object_munge.rb +307 -0
- data/lib/sisu/prog_text_translation.rb +1702 -0
- data/lib/sisu/qrcode.rb +754 -0
- data/lib/sisu/relaxng.rb +1153 -0
- data/lib/sisu/remote.rb +246 -0
- data/lib/sisu/rexml.rb +148 -0
- data/lib/sisu/se.rb +158 -0
- data/lib/sisu/se_cleanoutput.rb +145 -0
- data/lib/sisu/se_clear.rb +105 -0
- data/lib/sisu/se_createsite.rb +273 -0
- data/lib/sisu/se_css.rb +221 -0
- data/lib/sisu/se_date.rb +92 -0
- data/lib/sisu/se_db.rb +214 -0
- data/lib/sisu/se_envcall.rb +326 -0
- data/lib/sisu/se_file_op.rb +2758 -0
- data/lib/sisu/se_filemap.rb +247 -0
- data/lib/sisu/se_get_init.rb +238 -0
- data/lib/sisu/se_hub_particulars.rb +234 -0
- data/lib/sisu/se_info_env.rb +2179 -0
- data/lib/sisu/se_info_port.rb +70 -0
- data/lib/sisu/se_info_system.rb +202 -0
- data/lib/sisu/se_load.rb +108 -0
- data/lib/sisu/se_processing.rb +659 -0
- data/lib/sisu/se_programs.rb +394 -0
- data/lib/sisu/se_remotes.rb +553 -0
- data/lib/sisu/se_standardise_lang.rb +176 -0
- data/lib/sisu/se_version.rb +174 -0
- data/lib/sisu/shared_images.rb +137 -0
- data/lib/sisu/shared_markup_alt.rb +336 -0
- data/lib/sisu/shared_metadata.rb +1361 -0
- data/lib/sisu/shared_sem.rb +156 -0
- data/lib/sisu/sisu_thor_lib.rb +407 -0
- data/lib/sisu/sitemaps.rb +224 -0
- data/lib/sisu/src_kdissert_share.rb +102 -0
- data/lib/sisu/src_po4a_share.rb +309 -0
- data/lib/sisu/src_po4a_shelf.rb +1217 -0
- data/lib/sisu/src_po4a_shelf_set.rb +297 -0
- data/lib/sisu/src_po4a_sst_ao_sst.rb +893 -0
- data/lib/sisu/src_po4a_sst_ao_sst_set.rb +284 -0
- data/lib/sisu/src_po4a_sstm.rb +135 -0
- data/lib/sisu/src_shared.rb +347 -0
- data/lib/sisu/src_sisupod_make.rb +171 -0
- data/lib/sisu/src_sisupod_sstm.rb +109 -0
- data/lib/sisu/sst_convert_markup.rb +323 -0
- data/lib/sisu/sst_do_inline_footnotes.rb +440 -0
- data/lib/sisu/sst_from_xml.rb +178 -0
- data/lib/sisu/sst_identify_markup.rb +482 -0
- data/lib/sisu/sst_to_s_xml_sax.rb +471 -0
- data/lib/sisu/termsheet.rb +163 -0
- data/lib/sisu/texinfo.rb +430 -0
- data/lib/sisu/texinfo_format.rb +541 -0
- data/lib/sisu/texpdf.rb +1162 -0
- data/lib/sisu/texpdf_format.rb +1689 -0
- data/lib/sisu/texpdf_parts.rb +235 -0
- data/lib/sisu/txt_asciidoc.rb +354 -0
- data/lib/sisu/txt_asciidoc_decorate.rb +207 -0
- data/lib/sisu/txt_markdown.rb +389 -0
- data/lib/sisu/txt_markdown_decorate.rb +207 -0
- data/lib/sisu/txt_orgmode.rb +376 -0
- data/lib/sisu/txt_orgmode_decorate.rb +186 -0
- data/lib/sisu/txt_output.rb +86 -0
- data/lib/sisu/txt_plain.rb +410 -0
- data/lib/sisu/txt_plain_decorate.rb +189 -0
- data/lib/sisu/txt_read.rb +109 -0
- data/lib/sisu/txt_rst.rb +371 -0
- data/lib/sisu/txt_rst_decorate.rb +186 -0
- data/lib/sisu/txt_shared.rb +241 -0
- data/lib/sisu/txt_textile.rb +367 -0
- data/lib/sisu/txt_textile_decorate.rb +186 -0
- data/lib/sisu/update.rb +141 -0
- data/lib/sisu/urls.rb +696 -0
- data/lib/sisu/utils.rb +232 -0
- data/lib/sisu/utils_composite.rb +115 -0
- data/lib/sisu/utils_response.rb +114 -0
- data/lib/sisu/utils_screen_text_color.rb +472 -0
- data/lib/sisu/utils_spell.rb +99 -0
- data/lib/sisu/webrick.rb +191 -0
- data/lib/sisu/wikispeak.rb +375 -0
- data/lib/sisu/xhtml.rb +472 -0
- data/lib/sisu/xhtml_epub2.rb +890 -0
- data/lib/sisu/xhtml_epub2_concordance.rb +322 -0
- data/lib/sisu/xhtml_epub2_format.rb +2272 -0
- data/lib/sisu/xhtml_epub2_persist.rb +278 -0
- data/lib/sisu/xhtml_epub2_segments.rb +599 -0
- data/lib/sisu/xhtml_epub2_tune.rb +330 -0
- data/lib/sisu/xhtml_parts.rb +183 -0
- data/lib/sisu/xhtml_shared.rb +62 -0
- data/lib/sisu/xhtml_table.rb +97 -0
- data/lib/sisu/xml_docbook5.rb +376 -0
- data/lib/sisu/xml_dom.rb +624 -0
- data/lib/sisu/xml_fictionbook2.rb +389 -0
- data/lib/sisu/xml_format.rb +865 -0
- data/lib/sisu/xml_md_oai_pmh_dc.rb +229 -0
- data/lib/sisu/xml_odf_odt.rb +887 -0
- data/lib/sisu/xml_odf_odt_format.rb +674 -0
- data/lib/sisu/xml_parts.rb +191 -0
- data/lib/sisu/xml_persist.rb +126 -0
- data/lib/sisu/xml_sax.rb +521 -0
- data/lib/sisu/xml_scaffold_structure_collapsed.rb +198 -0
- data/lib/sisu/xml_scaffold_structure_sisu.rb +201 -0
- data/lib/sisu/xml_shared.rb +665 -0
- data/lib/sisu/xml_tables.rb +261 -0
- data/lib/sisu/zap.rb +90 -0
- metadata +251 -0
@@ -0,0 +1,440 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
* Name: SiSU
|
5
|
+
|
6
|
+
** Description: documents, structuring, processing, publishing, search
|
7
|
+
*** preprocessing, convert bi-footnotemarker-footnote to inline
|
8
|
+
footnotes, invoked using: sisu --to-footnotes filename.sst
|
9
|
+
|
10
|
+
** Author: Ralph Amissah
|
11
|
+
<ralph@amissah.com>
|
12
|
+
<ralph.amissah@gmail.com>
|
13
|
+
|
14
|
+
** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
15
|
+
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
|
16
|
+
All Rights Reserved.
|
17
|
+
|
18
|
+
** License: GPL 3 or later:
|
19
|
+
|
20
|
+
SiSU, a framework for document structuring, publishing and search
|
21
|
+
|
22
|
+
Copyright (C) Ralph Amissah
|
23
|
+
|
24
|
+
This program is free software: you can redistribute it and/or modify it
|
25
|
+
under the terms of the GNU General Public License as published by the Free
|
26
|
+
Software Foundation, either version 3 of the License, or (at your option)
|
27
|
+
any later version.
|
28
|
+
|
29
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
30
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
32
|
+
more details.
|
33
|
+
|
34
|
+
You should have received a copy of the GNU General Public License along with
|
35
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
36
|
+
|
37
|
+
If you have Internet connection, the latest version of the GPL should be
|
38
|
+
available at these locations:
|
39
|
+
<http://www.fsf.org/licensing/licenses/gpl.html>
|
40
|
+
<http://www.gnu.org/licenses/gpl.html>
|
41
|
+
|
42
|
+
<http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
|
43
|
+
|
44
|
+
** SiSU uses:
|
45
|
+
* Standard SiSU markup syntax,
|
46
|
+
* Standard SiSU meta-markup syntax, and the
|
47
|
+
* Standard SiSU object citation numbering and system
|
48
|
+
|
49
|
+
** Hompages:
|
50
|
+
<http://www.jus.uio.no/sisu>
|
51
|
+
<http://www.sisudoc.org>
|
52
|
+
|
53
|
+
** Git
|
54
|
+
<http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
|
55
|
+
<http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/set_do_inline_footnotes.rb;hb=HEAD>
|
56
|
+
|
57
|
+
=end
|
58
|
+
module SiSU_ConvertFootnotes
|
59
|
+
require_relative 'se' # se.rb
|
60
|
+
include SiSU_Env
|
61
|
+
require_relative 'dp' # dp.rb
|
62
|
+
include SiSU_Param
|
63
|
+
require_relative 'ao_syntax' # ao_syntax.rb
|
64
|
+
include SiSU_AO_Syntax
|
65
|
+
require_relative 'i18n' # i18n.rb
|
66
|
+
class Instantiate < SiSU_Param::Parameters::Instructions
|
67
|
+
@@flag={} #Beware!!
|
68
|
+
def initialize
|
69
|
+
@@flag['table_to']=false
|
70
|
+
@@counter=@@column=@@columns=@@flag_vocab=0
|
71
|
+
@@endnote={}
|
72
|
+
@@endnote_array=@@word_mode=[]
|
73
|
+
@@endnote_call_counter=1
|
74
|
+
@@line_mode=''
|
75
|
+
end
|
76
|
+
end
|
77
|
+
class Source <Instantiate
|
78
|
+
@@ao_array=[]
|
79
|
+
@@fns=nil
|
80
|
+
def initialize(opt)
|
81
|
+
@opt=opt
|
82
|
+
@@fns||@opt.fns
|
83
|
+
@my_make=SiSU_Env::CreateFile.new(@opt.fns)
|
84
|
+
@fnm=SiSU_Env::InfoFile.new(@opt.fns).marshal.ao_content
|
85
|
+
end
|
86
|
+
def read #creates ao
|
87
|
+
begin
|
88
|
+
@@ao_array=[]
|
89
|
+
@@fns=@opt.fns
|
90
|
+
create_ao
|
91
|
+
rescue
|
92
|
+
SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do
|
93
|
+
__LINE__.to_s + ':' + __FILE__
|
94
|
+
end
|
95
|
+
ensure
|
96
|
+
Instantiate.new
|
97
|
+
end
|
98
|
+
end
|
99
|
+
def get #reads ao, unless does not exist then creates first
|
100
|
+
begin
|
101
|
+
ao=[]
|
102
|
+
unless @@fns==@opt.fns
|
103
|
+
@@fns=@opt.fns
|
104
|
+
@@ao_array=[]
|
105
|
+
end
|
106
|
+
ao=(@@ao_array.empty?) \
|
107
|
+
? read_fnm
|
108
|
+
: @@ao_array.dup #check
|
109
|
+
rescue
|
110
|
+
SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do
|
111
|
+
__LINE__.to_s + ':' + __FILE__
|
112
|
+
end
|
113
|
+
ensure
|
114
|
+
Instantiate.new
|
115
|
+
end
|
116
|
+
end
|
117
|
+
protected
|
118
|
+
def create_ao
|
119
|
+
ao_array=[]
|
120
|
+
SiSU_Screen::Ansi.new(
|
121
|
+
@opt.act[:color_state][:set],
|
122
|
+
'convert footnotes'
|
123
|
+
).green_title_hi unless @opt.act[:quiet][:set]==:on
|
124
|
+
file_array=IO.readlines(@opt.fns,'')
|
125
|
+
file_array.each do |l|
|
126
|
+
if l =~/\r\n/ then l.gsub!(/\r\n/,"\n")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
meta=file_array.dup
|
130
|
+
meta=meta.join.split("\n\n") #check whether can be eliminated, some of these are large objects to have twice
|
131
|
+
@md=SiSU_Param::Parameters::Instructions.new(meta,@opt).extract
|
132
|
+
if @md.en[:mismatch]==0 \
|
133
|
+
or @md.opt.selections.str =~/=footnotes-force/
|
134
|
+
meta=nil
|
135
|
+
ao=SiSU_ConvertFootnotes::Make.new(@md,file_array).song
|
136
|
+
SiSU_Screen::Ansi.new(
|
137
|
+
@opt.act[:color_state][:set],
|
138
|
+
@opt.fns,
|
139
|
+
"#{@md.fns}.fn"
|
140
|
+
).output if @md.opt.act[:verbose][:set]==:on
|
141
|
+
SiSU_Screen::Ansi.new(
|
142
|
+
@opt.act[:color_state][:set],
|
143
|
+
"#{@md.fns}.fn -> #{@md.fns}.fn"
|
144
|
+
).txt_red unless @md.opt.act[:quiet][:set]==:on
|
145
|
+
ao.each {|s| ao_array << "#{s.strip}\n\n" unless s.strip.empty?}
|
146
|
+
ao_array
|
147
|
+
else
|
148
|
+
SiSU_Screen::Ansi.new(
|
149
|
+
@md.opt.act[:color_state][:set],
|
150
|
+
'*WARN* no footnote conversion done, problem with source file',
|
151
|
+
'to override use --convert=footnote-force (this is not advised)'
|
152
|
+
).warn unless @md.opt.act[:quiet][:set]==:on
|
153
|
+
''
|
154
|
+
end
|
155
|
+
end
|
156
|
+
def read_fnm
|
157
|
+
ao=[]
|
158
|
+
ao=(FileTest.file?(@fnm)) \
|
159
|
+
? (File.open(@fnm){ |f| ao=Marshal.load(f)})
|
160
|
+
: (SiSU_ConvertFootnotes::Source.new(@opt).create_ao) #watch
|
161
|
+
end
|
162
|
+
end
|
163
|
+
class Output
|
164
|
+
def initialize(md,data)
|
165
|
+
@md,@data=md,data
|
166
|
+
@my_make=SiSU_Env::CreateFile.new(@md.fns)
|
167
|
+
SiSU_Env::InfoEnv.new(@md.fns)
|
168
|
+
@hard="#{Dir.pwd}/#{@md.fns}.fn"
|
169
|
+
end
|
170
|
+
def hard_output
|
171
|
+
filename_note=@my_make.file_note
|
172
|
+
@data.each {|s| filename_note.puts s.strip + "\n\n" unless s.strip.empty?}
|
173
|
+
end
|
174
|
+
end
|
175
|
+
class Make
|
176
|
+
@@endnote={}
|
177
|
+
@@endnote_array=@@word_mode=[]
|
178
|
+
@@endnote_call_counter=1
|
179
|
+
@@comment='%'
|
180
|
+
@@flag={ ['table_to']=>false }
|
181
|
+
def initialize(md,data)
|
182
|
+
@md,@data=md,data
|
183
|
+
@@word_mode=[]
|
184
|
+
@env=SiSU_Env::InfoEnv.new(@md.fns)
|
185
|
+
l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language
|
186
|
+
@language=l[:n]
|
187
|
+
@translate=SiSU_Translate::Source.new(@md,@language)
|
188
|
+
end
|
189
|
+
def reset
|
190
|
+
@@counter=@@column=@@columns=@@flag_vocab=0
|
191
|
+
@@endnote={}
|
192
|
+
@@endnote_array=@@word_mode=[]
|
193
|
+
@@endnote_call_counter=1
|
194
|
+
@@line_mode=''
|
195
|
+
end
|
196
|
+
def song
|
197
|
+
reset
|
198
|
+
data=@data
|
199
|
+
@metafile="#{@env.processing_path.ao}/#{@md.fns}.meta"
|
200
|
+
SiSU_Env::CreateFile.new(@md.fns)
|
201
|
+
data=data.join.split("\n\n")
|
202
|
+
data_new=[]
|
203
|
+
data.each do |x|
|
204
|
+
data_new << (x =~ /\n\n/m) \
|
205
|
+
? (x.split(/\n\n+/))
|
206
|
+
: x
|
207
|
+
end
|
208
|
+
data=data_new.flatten
|
209
|
+
data=SiSU_ConvertFootnotes::Make.new(@md,data).character_check
|
210
|
+
data=SiSU_ConvertFootnotes::Make.new(@md,data).endnotes
|
211
|
+
SiSU_ConvertFootnotes::Output.new(@md,data).hard_output
|
212
|
+
reset
|
213
|
+
data
|
214
|
+
end
|
215
|
+
protected
|
216
|
+
def vocabulary
|
217
|
+
data=@data
|
218
|
+
tuned_file,vocab_insert=[],[]
|
219
|
+
data.each do |para|
|
220
|
+
if para =~/^1~/ \
|
221
|
+
and @@flag_vocab==0
|
222
|
+
vocab_insert << '@vocabulary: lex' << "\n\n" << para
|
223
|
+
tuned_file << vocab_insert unless para.nil?
|
224
|
+
@@flag_vocab=1
|
225
|
+
else tuned_file << para unless para.nil?
|
226
|
+
end
|
227
|
+
end
|
228
|
+
tuned_file
|
229
|
+
end
|
230
|
+
def character_check
|
231
|
+
reset
|
232
|
+
data=@data
|
233
|
+
@tuned_file=[]
|
234
|
+
endnote_no=1
|
235
|
+
data.each do |para|
|
236
|
+
para.strip!
|
237
|
+
para.gsub!(/^[{~}]\s*$/,'')
|
238
|
+
para.gsub!(/^#{@@comment}.*/,'') #remove comment and divider #%
|
239
|
+
para.gsub!(/<~#>|~#\s*/,'~#')
|
240
|
+
para.gsub!(/-#\s*/,'-#')
|
241
|
+
para.gsub!(/(~\{ )\s+/,'\1')
|
242
|
+
para.gsub!(/ \/\//,'<br />') #added 2004w29
|
243
|
+
para.gsub!(/<br>/,'<br />') #needed by xml, xhtml etc.
|
244
|
+
para.gsub!(/`/,"'")
|
245
|
+
para.gsub!(/\342\200\231/,"'") #if para =~/’/ #Avoid #‘ ’ #“ ”
|
246
|
+
para.gsub!(/\t/,' ')
|
247
|
+
para.gsub!(/�/,' ') #watch, replace with char code
|
248
|
+
para.gsub!(/[“”]/,'""')
|
249
|
+
para.gsub!(/[–—]/,'-') #— – chk
|
250
|
+
para.gsub!(/·/,'*')
|
251
|
+
para.gsub!(/\\copy(?:right)?\b/,'©')
|
252
|
+
para.gsub!(/\\trademark\b|\\tm\b/,'®')
|
253
|
+
para.gsub!(/\44/,'$') #$ watch
|
254
|
+
para=para + "\n"
|
255
|
+
case para
|
256
|
+
when /\^~/ # endnotes
|
257
|
+
#% Note must do this first (earlier loop) and then enter gathered data into ~^\d+
|
258
|
+
sub_para=para.dup
|
259
|
+
@@endnote_array << sub_para.gsub!(/\n/,'').gsub!(/\^~\s+(.+)\s*/,'~{ \1 }~').strip
|
260
|
+
endnote_no+=1
|
261
|
+
para=nil if para =~/\^~ .+/ #removes 'binary' endnote now in endnote array for later insertion
|
262
|
+
end
|
263
|
+
@tuned_file << para unless para.nil?
|
264
|
+
end
|
265
|
+
@tuned_file
|
266
|
+
end
|
267
|
+
def name_endnote_seg
|
268
|
+
data=@data
|
269
|
+
@tuned_file=[]
|
270
|
+
data.each do |para|
|
271
|
+
para.gsub!(/<:3>\s*<:ee>/,
|
272
|
+
"#{@@endnote['special_align']} <p /><br />\r " +
|
273
|
+
"#{@@endnote['seg_name_3']} <p /> " +
|
274
|
+
"#{@@endnote['special_align_close']}")
|
275
|
+
para.gsub!(/<:2>\s*<:ee>/,
|
276
|
+
"#{@@endnote['special_align']} <p /><br />\r " +
|
277
|
+
"#{@@endnote['seg_name_2']} <p />" +
|
278
|
+
"#{@@endnote['special_align_close']}")
|
279
|
+
para.gsub!(/<:1>\s*<:ee>/,
|
280
|
+
"#{@@endnote['special_align']} <p /><br />\r " +
|
281
|
+
"#{@@endnote['seg_name_1']} <p /> " +
|
282
|
+
"#{@@endnote['special_align_close']}")
|
283
|
+
@tuned_file << para
|
284
|
+
end
|
285
|
+
if @md.flag_auto_endnotes \
|
286
|
+
and @md.flag_separate_endnotes_make
|
287
|
+
@tuned_file << "\n1~endnotes Endnotes" #prob numbering, revisit
|
288
|
+
end
|
289
|
+
@tuned_file << "\n<ENDNOTES>"
|
290
|
+
@tuned_file
|
291
|
+
end
|
292
|
+
def owner_details_seg
|
293
|
+
data << '1~owner.details Owner Details'
|
294
|
+
end
|
295
|
+
def number_sub_heading(para,num,title_no)
|
296
|
+
case para
|
297
|
+
when /#{num}~- / then para.gsub!(/#{num}~- /,"#{title_no} ")
|
298
|
+
when /^#{num}~#\s*/ then para.gsub!(/^#{num}~#\s*/,"#{title_no} ")
|
299
|
+
when /^#{num}~[a-z_\.]+ /
|
300
|
+
para.gsub!(/^#{num}~([a-z_\.]+)\s+(.+)/i,%{#{num}~\\1 #{title_no} \\2 <:name##{title_no}>})
|
301
|
+
else para.gsub!(/^#{num}~ /,"#{num}~#{title_no} #{title_no} ") #main
|
302
|
+
end
|
303
|
+
if @md.toc_lev_limit \
|
304
|
+
and @md.toc_lev_limit < num
|
305
|
+
para.gsub!(/^[2-6]~(?:~\S+)?\s*/,'!_ ')
|
306
|
+
end
|
307
|
+
para
|
308
|
+
end
|
309
|
+
def set_heading_top #% make sure no false positives
|
310
|
+
unless @md.set_heading_top
|
311
|
+
if (@md.opt.act[:verbose_plus][:set]==:on \
|
312
|
+
|| @md.opt.act[:maintenance][:set]==:on)
|
313
|
+
puts "\tdocument contains no top level heading, (will have to manufacture one)"
|
314
|
+
end
|
315
|
+
data=@data
|
316
|
+
@tuned_file=[]
|
317
|
+
data.each do |para|
|
318
|
+
unless @md.set_heading_top
|
319
|
+
if para !~/^(?:@\S+:|0~\S+)\s/m \
|
320
|
+
and para !~/\A\s*\Z/m
|
321
|
+
@md.set_heading_top=true
|
322
|
+
head=(@md.title.full) \
|
323
|
+
? (":A~ #{@md.title.full}")
|
324
|
+
: (':A~ [no title provided]')
|
325
|
+
@tuned_file << head
|
326
|
+
end
|
327
|
+
end
|
328
|
+
@tuned_file << para
|
329
|
+
end
|
330
|
+
@tuned_file
|
331
|
+
end
|
332
|
+
end
|
333
|
+
def set_heading_seg #% make sure no false positives
|
334
|
+
unless @md.set_heading_seg
|
335
|
+
if (@md.opt.act[:verbose_plus][:set]==:on \
|
336
|
+
|| @md.opt.act[:maintenance][:set]==:on)
|
337
|
+
puts "\tdocument contains no segment level, (will have to manufacture one)"
|
338
|
+
end
|
339
|
+
data=@data
|
340
|
+
@tuned_file=[]
|
341
|
+
data.each do |para|
|
342
|
+
unless @md.set_heading_seg
|
343
|
+
if para !~/^(?:@\S+:|0~\S+|:[ABC]~)/m \
|
344
|
+
and para !~/\A\s*\Z/m \
|
345
|
+
and para !~/<:p[bn]>/
|
346
|
+
@md.set_heading_seg=true
|
347
|
+
head=(@md.title.full) \
|
348
|
+
? ("1~seg [#{@md.title.full}]")
|
349
|
+
: ('1~seg [segment]')
|
350
|
+
@tuned_file << head
|
351
|
+
end
|
352
|
+
end
|
353
|
+
@tuned_file << para
|
354
|
+
end
|
355
|
+
@tuned_file
|
356
|
+
end
|
357
|
+
end
|
358
|
+
def set_header_title #% make sure no false positives
|
359
|
+
unless @md.set_header_title
|
360
|
+
if (@md.opt.act[:verbose_plus][:set]==:on \
|
361
|
+
|| @md.opt.act[:maintenance][:set]==:on)
|
362
|
+
puts "\t no document title provided, (will have to manufacture one)"
|
363
|
+
end
|
364
|
+
data=@data
|
365
|
+
@tuned_file=[]
|
366
|
+
data.each do |para|
|
367
|
+
unless @md.set_header_title
|
368
|
+
if para !~/^%{1,2}\s/m \
|
369
|
+
and para !~/\A\s*\Z/m
|
370
|
+
@tuned_file << "0~title #{@md.heading_seg_first}"
|
371
|
+
@md.title.full=@md.heading_seg_first
|
372
|
+
@md.set_header_title=true
|
373
|
+
end
|
374
|
+
end
|
375
|
+
@tuned_file << para
|
376
|
+
end
|
377
|
+
@tuned_file
|
378
|
+
end
|
379
|
+
end
|
380
|
+
def endnotes #% endnote work zone
|
381
|
+
data=@data
|
382
|
+
@tuned_file=[]
|
383
|
+
endnote_ref=1
|
384
|
+
data.each do |para|
|
385
|
+
case para # manually numbered endnotes <!e(\d)!> <!e_(\d)!> -->
|
386
|
+
when /~\{\s+.+?\}~/ # auto-numbered endnotes <!e!> <!e_!> -->
|
387
|
+
para.gsub!(/\s*\}~/,' }~') # required 2003w31
|
388
|
+
@word_mode=para.scan(/\S+/)
|
389
|
+
word_mode=SiSU_ConvertFootnotes::Make.new(@md,@word_mode).endnote_call_number
|
390
|
+
para=word_mode.join(' ')
|
391
|
+
endnote_ref+=1
|
392
|
+
when /~\^(?:\s|$)|<:e>/ #%Note inserts endnotes previously gathered from /^(<!e[:_]!>|[-~]\{{3})/ (in earlier loop)
|
393
|
+
word_mode=para.scan(/\S+/)
|
394
|
+
word_mode=SiSU_ConvertFootnotes::Make.new(@md,word_mode).endnote_call_number
|
395
|
+
para=word_mode.join(' ')
|
396
|
+
endnote_ref+=1
|
397
|
+
end
|
398
|
+
@tuned_file << para
|
399
|
+
end
|
400
|
+
@tuned_file
|
401
|
+
end
|
402
|
+
def endnote_call_number
|
403
|
+
data=@data
|
404
|
+
data.each do |word|
|
405
|
+
case word
|
406
|
+
when /~\{/
|
407
|
+
unless word =~/~\{\*+/
|
408
|
+
@@endnote_call_counter+=1
|
409
|
+
end
|
410
|
+
when /~\^|<:e>/
|
411
|
+
word.gsub!(/~\^|<:e>/,"#{@@endnote_array[@@endnote_call_counter-1]}")
|
412
|
+
@@endnote_call_counter+=1
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
def strip_clean_extra_spaces(s) # ao output tuned
|
417
|
+
s=s.dup
|
418
|
+
s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1')
|
419
|
+
s=s.gsub(/ [ ]+/,' ')
|
420
|
+
s=s.gsub(/^ [ ]+/,'')
|
421
|
+
s=s.gsub(/ [ ]+$/,'')
|
422
|
+
s=s.gsub(/(<\/[bi]>')[ ]+(s )/,'\1\2')
|
423
|
+
end
|
424
|
+
def strip_clean_of_markup(s) # used for digest, define rules, make same as in db clean
|
425
|
+
s=s.dup
|
426
|
+
s=s.gsub(/(?:<\/?[ib]>|^:[A-C]~\S+|^[1-6]~\S+|~\{\d+\s.+?\}~)/,'') # markup and endnotes removed
|
427
|
+
#% same as db clean -->
|
428
|
+
s=s.gsub(/<del>(.+?)<\/del>/,'DELETED(\1)') # deletions
|
429
|
+
s=s.gsub(/<sup>(\d+)<\/sup>/,'[\1]')
|
430
|
+
s=s.gsub(/(?: \\;|#{Mx[:nbsp]})+/,' ') #checking source Mx not necessary
|
431
|
+
s=s.gsub(/\{.+?\.(?:png|jpg|gif).+?\}(?:https?|file|ftp)\\\:\S+ /,' [image] ') # else image names found in search
|
432
|
+
s=s.gsub(/#{Mx[:lnk_o]}.+?\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [image] ') # else image names found in search, re-check
|
433
|
+
s=s.gsub(/\s\s+/,' ')
|
434
|
+
s=s.strip
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
__END__
|
439
|
+
@particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
|
440
|
+
ao_array=@particulars.ao_array # ao file drawn here
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
* Name: SiSU
|
5
|
+
|
6
|
+
** Description: documents, structuring, processing, publishing, search
|
7
|
+
*** Conversion script from kdissert .kdi to sisu markup .ssm (master document)
|
8
|
+
|
9
|
+
** Author: Ralph Amissah
|
10
|
+
<ralph@amissah.com>
|
11
|
+
<ralph.amissah@gmail.com>
|
12
|
+
|
13
|
+
** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
14
|
+
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
|
15
|
+
All Rights Reserved.
|
16
|
+
|
17
|
+
** License: GPL 3 or later:
|
18
|
+
|
19
|
+
SiSU, a framework for document structuring, publishing and search
|
20
|
+
|
21
|
+
Copyright (C) Ralph Amissah
|
22
|
+
|
23
|
+
This program is free software: you can redistribute it and/or modify it
|
24
|
+
under the terms of the GNU General Public License as published by the Free
|
25
|
+
Software Foundation, either version 3 of the License, or (at your option)
|
26
|
+
any later version.
|
27
|
+
|
28
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
29
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
31
|
+
more details.
|
32
|
+
|
33
|
+
You should have received a copy of the GNU General Public License along with
|
34
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
35
|
+
|
36
|
+
If you have Internet connection, the latest version of the GPL should be
|
37
|
+
available at these locations:
|
38
|
+
<http://www.fsf.org/licensing/licenses/gpl.html>
|
39
|
+
<http://www.gnu.org/licenses/gpl.html>
|
40
|
+
|
41
|
+
<http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
|
42
|
+
|
43
|
+
** SiSU uses:
|
44
|
+
* Standard SiSU markup syntax,
|
45
|
+
* Standard SiSU meta-markup syntax, and the
|
46
|
+
* Standard SiSU object citation numbering and system
|
47
|
+
|
48
|
+
** Hompages:
|
49
|
+
<http://www.jus.uio.no/sisu>
|
50
|
+
<http://www.sisudoc.org>
|
51
|
+
|
52
|
+
** Git
|
53
|
+
<http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
|
54
|
+
<http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/sst_from_xml.rb;hb=HEAD>
|
55
|
+
|
56
|
+
=end
|
57
|
+
module SiSU_sstFromXML
|
58
|
+
require_relative 'se' # se.rb
|
59
|
+
class Convert
|
60
|
+
begin
|
61
|
+
require 'rexml/document'
|
62
|
+
include REXML
|
63
|
+
rescue LoadError
|
64
|
+
SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
|
65
|
+
error('rexml/document NOT FOUND (LoadError)')
|
66
|
+
end
|
67
|
+
def initialize(opt)
|
68
|
+
@opt=opt
|
69
|
+
@sisu,@sisu_base=[],[]
|
70
|
+
@ver=SiSU_Env::InfoVersion.instance.get_version
|
71
|
+
end
|
72
|
+
def tell(filename,type)
|
73
|
+
SiSU_Screen::Ansi.new(
|
74
|
+
@opt.act[:color_state][:set],
|
75
|
+
"XML #{type} to SiSU sst",
|
76
|
+
"#{filename} --> #{filename}.sst"
|
77
|
+
).green_hi_blue
|
78
|
+
end
|
79
|
+
def read
|
80
|
+
xml_to_sisu
|
81
|
+
end
|
82
|
+
def markup_head(text)
|
83
|
+
text.strip!
|
84
|
+
text.gsub!(/(?:\s*\n|\s\s+)/,' ')
|
85
|
+
text.gsub!(/<header class=['"]\S+?['"]>(.+?)<\/header>/,'\1')
|
86
|
+
text.gsub!(/<(\w+)>(.+?)<\/\w+>/,'@\1: \2')
|
87
|
+
text.gsub!(/<header class=['"]\S+?['"]><(\w+)>(.+?)<\/\w+><\/header>/,'@\1: \2')
|
88
|
+
text.gsub!(/\s +/,' ')
|
89
|
+
text.strip!
|
90
|
+
text + "\n\n"
|
91
|
+
end
|
92
|
+
def markup(text)
|
93
|
+
text.strip!
|
94
|
+
text.gsub!(/(?:\s*\n|\s\s+)/,' ')
|
95
|
+
text.gsub!(/<text class='h1'>(.+?)<\/text>/,':A~ \1')
|
96
|
+
text.gsub!(/<text class='h2'>(.+?)<\/text>/,':B~ \1')
|
97
|
+
text.gsub!(/<text class='h3'>(.+?)<\/text>/,':C~ \1')
|
98
|
+
text.gsub!(/<text class='h4'>(.+?)<\/text>/,'1~ \1')
|
99
|
+
text.gsub!(/<text class='h5'>(.+?)<\/text>/,'2~ \1')
|
100
|
+
text.gsub!(/<text class='h6'>(.+?)<\/text>/,'3~ \1')
|
101
|
+
text.gsub!(/<text class='norm'>(.+?)<\/text>/,'\1')
|
102
|
+
text.gsub!(/<endnote symbol='norm'>(.+?)<\/endnote>/,'~{ \1 }~')
|
103
|
+
text.gsub!(/<br ?\/>/,'<br>')
|
104
|
+
text.gsub!(/<i>(.+?)<\/i>/,'/{\1}/')
|
105
|
+
text.gsub!(/<b>(.+?)<\/b>/,'*{\1}*')
|
106
|
+
text.gsub!(/<u>(.+?)<\/u>/,'_{\1}_')
|
107
|
+
text.gsub!(/<sem:([a-z_]+)\s+depth=['"]zero['"]>(\s*.+?\s*)<\/sem:\1>/,';{ \2 };\1')
|
108
|
+
text.gsub!(/<sem:([a-z_]+)\s+depth=['"]one['"]>(\s*.+?\s*)<\/sem:\1>/,':{ \2 }:\1')
|
109
|
+
text.gsub!(/<sem:([a-z_]+)\s+depth=['"]many['"]>(\s*.+?\s*)<\/sem:\1>/,'\1:{ \2 }:\1')
|
110
|
+
text.gsub!(/<sem:([a-z_]+)>(\s*.+?\s*)<\/sem:\1>/,'\1:{ \2 }:\1')
|
111
|
+
text.gsub!(/\s +/,' ')
|
112
|
+
text.strip!
|
113
|
+
text + "\n\n"
|
114
|
+
end
|
115
|
+
def sax
|
116
|
+
out_file=File.new(@output_file_name,'w')
|
117
|
+
head=@doc.root.get_elements('//head/header')
|
118
|
+
body=@doc.root.get_elements('//object/text')
|
119
|
+
out_file.puts "% SiSU text #{@ver.version} (generated from a SiSU XML markup representation)\n\n"
|
120
|
+
head.each do |x|
|
121
|
+
if x.name=='header'
|
122
|
+
head=markup_head(x.to_s)
|
123
|
+
out_file.puts head
|
124
|
+
end
|
125
|
+
end
|
126
|
+
body.each do |x|
|
127
|
+
if x.name=='text'
|
128
|
+
body=markup(x.to_s)
|
129
|
+
out_file.puts body
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
def node
|
134
|
+
sax
|
135
|
+
end
|
136
|
+
def dom
|
137
|
+
raise "#{__FILE__}::#{__LINE__} xml dom representation to sst not yet implemented (experimental simple xml representations sax and node to sst are in place)."
|
138
|
+
end
|
139
|
+
def xml_to_sisu
|
140
|
+
unless @opt.files.empty?
|
141
|
+
@opt.files.each do |xml|
|
142
|
+
@sisu_base=[]
|
143
|
+
if xml =~/\.sx[sdn]\.xml$/
|
144
|
+
begin
|
145
|
+
@doc_str=IO.readlines(xml,'').join("\n")
|
146
|
+
@output=File.new("#{xml}.sst",'w')
|
147
|
+
@doc=REXML::Document.new(@doc_str)
|
148
|
+
@output_file_name="#{Dir.pwd}/#{xml}.sst"
|
149
|
+
@el=[]
|
150
|
+
rescue REXML::ParseException
|
151
|
+
end
|
152
|
+
end
|
153
|
+
if xml =~/\.sxs\.xml$/
|
154
|
+
unless @opt.act[:quiet][:set]==:on
|
155
|
+
tell(xml,'sax')
|
156
|
+
end
|
157
|
+
sax
|
158
|
+
elsif xml =~/\.sxd\.xml$/
|
159
|
+
unless @opt.act[:quiet][:set]==:on
|
160
|
+
tell(xml,'dom')
|
161
|
+
end
|
162
|
+
dom
|
163
|
+
elsif xml =~/\.sxn\.xml$/
|
164
|
+
unless @opt.act[:quiet][:set]==:on
|
165
|
+
tell(xml,'node')
|
166
|
+
end
|
167
|
+
node
|
168
|
+
else puts "filename not recognised: << #{xml} >>"
|
169
|
+
end
|
170
|
+
@output << @sisu_base
|
171
|
+
end
|
172
|
+
else puts '.xml file for conversion to sisu expected'
|
173
|
+
end
|
174
|
+
puts @opt.files.inspect
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
__END__
|