wiki style document editor
リビジョン | 6e270617e182abbcca805698d54c6e135989c5f0 (tree) |
---|---|
日時 | 2014-09-01 01:41:09 |
作者 | Hiromichi Matsushima <hylom@Hiro...> |
コミッター | Hiromichi Matsushima |
export: fix for table markup
@@ -45,6 +45,7 @@ function copyFiles(filelist, from, dest) { | ||
45 | 45 | |
46 | 46 | function exportSingle(target, output) { |
47 | 47 | fs.readFile(target, 'utf8', function (err, data) { |
48 | + console.log(target); | |
48 | 49 | if (err) { |
49 | 50 | console.log('Cannot read file: ' + target); |
50 | 51 | return; |
@@ -60,21 +61,25 @@ function exportSingle(target, output) { | ||
60 | 61 | // output honmon, caption |
61 | 62 | fs.writeFileSync(path.join(output, 'honmon.txt'), |
62 | 63 | result.bodies.join('\n')); |
63 | - fs.writeFileSync(path.join(output, 'caption.txt'), | |
64 | - result.captions.join('\n')); | |
64 | + | |
65 | + if (result.captions.length != 0) { | |
66 | + fs.writeFileSync(path.join(output, 'caption.txt'), | |
67 | + result.captions.join('\n')); | |
68 | + // output html | |
69 | + var out = fs.createWriteStream(path.join(output, 'figures.html'), {flags: 'w', encoding: 'utf8', mode: 0666}); | |
70 | + out.write(HTML_HEAD); | |
71 | + out.write('\n'); | |
72 | + out.write(result.htmls.join('\n')); | |
73 | + out.write('\n'); | |
74 | + out.write(HTML_FOOT); | |
75 | + out.end(); | |
76 | + } | |
65 | 77 | |
66 | 78 | // file copy |
67 | 79 | var copyFrom = path.join(path.dirname(target), 'figure'); |
68 | - copyFiles(result.figures, copyFrom, path.join(output, 'figures')); | |
69 | - | |
70 | - // output html | |
71 | - var out = fs.createWriteStream(path.join(output, 'figures.html'), {flags: 'w', encoding: 'utf8', mode: 0666}); | |
72 | - out.write(HTML_HEAD); | |
73 | - out.write('\n'); | |
74 | - out.write(result.htmls.join('\n')); | |
75 | - out.write('\n'); | |
76 | - out.write(HTML_FOOT); | |
77 | - out.end(); | |
80 | + if (result.figures.length != 0) { | |
81 | + copyFiles(result.figures, copyFrom, path.join(output, 'figures')); | |
82 | + } | |
78 | 83 | |
79 | 84 | }); |
80 | 85 | } |
@@ -89,6 +94,9 @@ function findFigureFile(caption, imageDir) { | ||
89 | 94 | } |
90 | 95 | |
91 | 96 | function findImageFile(name, targetDir) { |
97 | + if (fs.existsSync(path.join(targetDir, name))) { | |
98 | + return name; | |
99 | + } | |
92 | 100 | var files = fs.readdirSync(targetDir); |
93 | 101 | var exts = config.figureFormat; |
94 | 102 | for (var i = 0; i < files.length; i++) { |
@@ -136,6 +144,9 @@ function splitBody(lines) { | ||
136 | 144 | && bodies[bodies.length-1] === '' ) { |
137 | 145 | // do nothing |
138 | 146 | } else { |
147 | + // *図、*表を置換 | |
148 | + lines[i] = lines[i].replace(/\*図/g, '★図'); | |
149 | + lines[i] = lines[i].replace(/\*表/g, '★表'); | |
139 | 150 | bodies.push(lines[i]); |
140 | 151 | } |
141 | 152 | } |
@@ -241,7 +252,8 @@ function makeHtmls(lines, imageDir) { | ||
241 | 252 | var html = []; |
242 | 253 | var figMode = false; |
243 | 254 | var figTextMode = false; |
244 | - var figName; | |
255 | + var assumedFigName; | |
256 | + var figName | |
245 | 257 | var figId; |
246 | 258 | for (var i = 0; i < lines.length; i++) { |
247 | 259 |
@@ -253,14 +265,15 @@ function makeHtmls(lines, imageDir) { | ||
253 | 265 | // figure |
254 | 266 | if (lines[i].match(/^☆図/)) { |
255 | 267 | figId = lines[i].match(/^☆図([0-9]+-[0-9]+)/); |
256 | - figName = 'fig' + figId[1] + '.fw.png'; | |
268 | + console.log(lines[i]); | |
269 | + assumedFigName = 'fig' + figId[1] + '.fw.png'; | |
257 | 270 | figMode = true; |
258 | - if (isExistsFigure(figName, imageDir)) { | |
271 | + if (isExistsFigure(assumedFigName, imageDir)) { | |
259 | 272 | html.push('<span class="caption">' + lines[i] + '</span>'); |
260 | - html.push('<img src="figures/' + figName + '">'); | |
261 | - html.push('<span class="filename">' + figName + '</span>'); | |
273 | + html.push('<img src="figures/' + assumedFigName + '">'); | |
274 | + html.push('<span class="filename">' + assumedFigName + '</span>'); | |
262 | 275 | i++; |
263 | - while(!lines[i].match(/^>>>>/)) { | |
276 | + while((i < lines.length) && (!lines[i].match(/^>>>>/))) { | |
264 | 277 | if (lines[i].match(/^\s*$/)) { |
265 | 278 | i++; |
266 | 279 | continue; |
@@ -270,7 +283,7 @@ function makeHtmls(lines, imageDir) { | ||
270 | 283 | } |
271 | 284 | if (figMode) { |
272 | 285 | figName = findImageFile(lines[i], imageDir); |
273 | - if (figName != '') { | |
286 | + if ((figName != '') && (figName != assumedFigName)) { | |
274 | 287 | html.push('<span class="filename">' + figName + '</span>'); |
275 | 288 | } |
276 | 289 | } |
@@ -309,7 +322,10 @@ function makeHtmls(lines, imageDir) { | ||
309 | 322 | html.push('<span class="caption">' + lines[i] + '</span>'); |
310 | 323 | html.push('<table>'); |
311 | 324 | i++; |
312 | - while(!lines[i].match(/^\s+$/)) { | |
325 | + while((i < lines.length) && (!lines[i].match(/^\s*$/))) { | |
326 | + if (lines[i].match(/^>>>>/)) { | |
327 | + break; | |
328 | + } | |
313 | 329 | html.push(lines[i].replace(/^/, '<tr><td>') |
314 | 330 | .replace(/$/, '</td></tr>') |
315 | 331 | .replace(/\t/, '</td><td>')); |
@@ -22,12 +22,12 @@ function exportPages(taget, output) { | ||
22 | 22 | } |
23 | 23 | var contents = toc.directories[target].contents; |
24 | 24 | var page = toc.directories[target].pageStart; |
25 | - console.log(toc.directories[target]); | |
25 | + //console.log(toc.directories[target]); | |
26 | 26 | contents.forEach(function (content) { |
27 | 27 | var outputDirPath = calcOutputDirPath(content, page); |
28 | 28 | page += content.pages; |
29 | 29 | var targetPathname = path.join(config.rootDir, target, content.title + '.txt'); |
30 | - console.log(targetPathname, outputDirPath); | |
30 | + //console.log(targetPathname, outputDirPath); | |
31 | 31 | exportSinge(targetPathname, outputDirPath); |
32 | 32 | }); |
33 | 33 | } |