• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

wiki style document editor


Commit MetaInfo

Revision8e1928cccc1d0e77866cd89a1394e57a5f976fed (tree)
Time2014-08-26 19:52:39
Authorhylom <hylom@hylo...>
Commiterhylom

Log Message

refactor export.js

Change Summary

Incremental Difference

--- a/tools/export/export.js
+++ b/tools/export/export.js
@@ -10,6 +10,7 @@ var fs = require('fs');
1010
1111 var HTML_HEADER = 'header.txt';
1212 var HTML_FOOTER = 'footer.txt';
13+var IMAGE_DIR = 'figure';
1314
1415 var headerFullPath = path.join(path.dirname(module.filename), HTML_HEADER);
1516 var footerFullPath = path.join(path.dirname(module.filename), HTML_FOOTER);
@@ -20,29 +21,21 @@ var HTML_FOOT = fs.readFileSync(footerFullPath, {encoding: 'utf8'});
2021 var usage = 'node export.js <target directory> <output directory>';
2122
2223
23-
24-
2524 function exportSingle(target, output) {
2625 fs.readFile(target, 'utf8', function (err, data) {
2726 if (err) {
2827 console.log('Cannot read file: ' + target);
2928 return;
3029 }
31- var result = stripText(data);
32-/*
33- console.log(result.text.join('\n'));
34- console.log('-------------------------');
35- console.log(result.caption.join('\n'));
36- console.log('-------------------------');
37- console.log(result.html.join('\n'));
38-*/
39- result.caption = parseCaption(result.caption, target);
30+
31+ var result = parseText(data);
4032 result.html = makeCaptionHtml(result.figure);
4133
4234 fs.writeFileSync(path.join(output, 'honmon.txt'),
4335 result.text.join('\n'));
4436 fs.writeFileSync(path.join(output, 'caption.txt'),
4537 result.caption.join('\n'));
38+
4639 var out = fs.createWriteStream(path.join(output, 'figures.html'), {flags: 'w', encoding: 'utf8', mode: 0666});
4740 out.write(HTML_HEAD);
4841 out.write('\n');
@@ -50,6 +43,7 @@ function exportSingle(target, output) {
5043 out.write('\n');
5144 out.write(HTML_FOOT);
5245 out.end();
46+
5347 });
5448 }
5549
@@ -92,7 +86,8 @@ function makeCaptionHtml(text) {
9286 return results;
9387 }
9488
95-function parseCaption(text, targetPath) {
89+// replace image file name to full pathname
90+function replaceImageToPathname(text, targetPath) {
9691 var results = [];
9792 for (var i = 0; i < text.length; i++) {
9893
@@ -110,7 +105,8 @@ function parseCaption(text, targetPath) {
110105 return results;
111106 }
112107
113-function stripText(data) {
108+// parse main text to separate body text and captions/tables
109+function parseText(data) {
114110 var lines = data.split('\n');
115111 var counter = 0;
116112 var texts = [];
@@ -155,12 +151,13 @@ function stripText(data) {
155151 }
156152 var result = {};
157153 result.text = texts;
158- result.caption = captions;
154+ result.caption = replaceImageToPathname(captions, target);
159155 result.figure = figures;
160156 return result;
161157 }
162158
163159
160+// main action
164161 if (require.main == module) {
165162 if (process.argv.length < 4) {
166163 process.stdout.write(usage + '\n');