~ubuntu-branches/ubuntu/quantal/texworks/quantal

« back to all changes in this revision

Viewing changes to res/resfiles/scripts/Hooks/latexErrors.js

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA
  • Date: 2011-04-04 13:42:12 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110404134212-vifjuxlyai7y7gyu
Tags: 0.4.0-2
* Added english manual.
* Updated Build-Depends; removed sharutils and replaced python2.6-dev with
  python-dev
* Removed obsolete debian/patch-print and debian/document-print.png.enc
* Added texworks-help-en package which included manual for texworks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Title: LaTeX errors
3
3
// Description: Looks for errors in the LaTeX terminal output
4
4
// Author: Jonathan Kew & Stefan Löffler
5
 
// Version: 0.3
6
 
// Date: 2010-01-09
 
5
// Version: 0.4
 
6
// Date: 2010-11-02
7
7
// Script-Type: hook
8
8
// Hook: AfterTypeset
9
9
 
11
11
// Switching the engines to use the FILE:LINE-style error messages could help a lot.
12
12
 
13
13
parenRE = new RegExp("[()]");
14
 
newFileRE = new RegExp("^\\(([\\./][^ )]+)");
 
14
// Should catch filenames of the following forms:
 
15
// * ./abc, "./abc"
 
16
// * /abc, "/abc"
 
17
// * .\abc, ".\abc"
 
18
// * C:\abc, "C:\abc"
 
19
// * \\server\abc, "\\server\abc"
 
20
// Caveats: filenames with escaped " or space in the filename don't work (correctly)
 
21
newFileRE = new RegExp("^\\(\"?((?:\\./|/|.\\\\|[a-zA-Z]:\\\\|\\\\\\\\[^\\\" )]+\\\\)[^\" )]+)");
15
22
lineNumRE = new RegExp("^l\\.(\\d+)");
16
23
badLineRE = new RegExp("^(?:Over|Under)full \\\\hbox.*at lines (\\d+)");
17
24
warnLineRE = new RegExp("^(?:LaTeX|Package (?:.*)) Warning: .*");
18
25
warnLineNumRE = new RegExp("on input line (\\d+).");
19
 
result = [];
 
26
errors = [];
 
27
warnings = [];
 
28
infos = [];
 
29
 
 
30
function trim (zeichenkette) {
 
31
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
 
32
}
20
33
 
21
34
// get the text from the standard console output
22
35
txt = TW.target.consoleOutput;
40
53
                error[1] = 0;
41
54
                while (++i < lines.length) {
42
55
                        line = lines[i];
 
56
                        if(trim(line) == '') break;
43
57
                        matched = lineNumRE.exec(line);
44
 
                        if (matched) {
 
58
                        if (matched)
45
59
                                error[1] = matched[1];
46
 
                                break;
47
 
                        }
 
60
                        error[2] += "\n" + line;
48
61
                }
49
 
                result.push(error);
 
62
                errors.push(error);
50
63
                continue;
51
64
        }
52
65
        
57
70
                error[0] = curFile;
58
71
                error[1] = matched[1];
59
72
                error[2] = line;
60
 
                result.push(error);
 
73
                infos.push(error);
61
74
                continue;
62
75
        }
63
76
 
67
80
                var error = [];
68
81
                error[0] = curFile;
69
82
                error[1] = "?";
70
 
                matched = warnLineNumRE.exec(line);
 
83
                error[2] = line;
 
84
 
 
85
                while (++i < lines.length) {
 
86
                        line = lines[i];
 
87
                        if(line == '') break;
 
88
                        error[2] += "\n" + line;
 
89
                }
 
90
                matched = warnLineNumRE.exec(error[2].replace(/\n/, ""));
71
91
                if (matched)
72
92
                        error[1] = matched[1];
73
 
                error[2] = "";
74
 
                while (line != "" && i < lines.length) {
75
 
                        error[2] += line;
76
 
                        i++;
77
 
                        line = lines[i];
78
 
                }
79
 
                result.push(error);
 
93
                warnings.push(error);
80
94
                continue;
81
95
        }
82
96
 
113
127
        }
114
128
}
115
129
 
 
130
function htmlize(str) {
 
131
        var html = str;
 
132
        html = html.replace(/&/g, "&amp;");
 
133
        html = html.replace(/</g, "&lt;");
 
134
        html = html.replace(/>/g, "&gt;");
 
135
        html = html.replace(/\n /g, "\n&nbsp;");
 
136
        html = html.replace(/  /g, "&nbsp;&nbsp;");
 
137
        html = html.replace(/&nbsp; /g, "&nbsp;&nbsp;");
 
138
        return html.replace(/\n/g, "<br />\n");
 
139
        
 
140
}
 
141
 
 
142
function makeResultRow(data, color) {
 
143
        var html = '';
 
144
        var url = 'texworks:' + data[0] + (data[1] != '?' && data[1] != 0 ? '#' + data[1] : '');
 
145
        html += '<tr>';
 
146
        html += '<td width="10" style="background-color: ' + color + '"></td>';
 
147
        html += '<td valign="top"><a href="' + url + '">' + data[0] + '</a></td>';
 
148
        html += '<td valign="top">' + data[1] + '</td>';
 
149
        html += '<td valign="top" style="font-family: monospace;">' + htmlize(data[2]) + '</td>';
 
150
        html += '</tr>';
 
151
        return html;
 
152
}
 
153
 
116
154
// finally, return our result (if any)
117
 
if (result.length > 0) {
118
 
        TW.result = result;
 
155
if (errors.length > 0 || warnings.length > 0 || infos.length > 0) {
 
156
        html  = '<html><body>';
 
157
        html += '<table border="1" cellspacing="0" cellpadding="4">';
 
158
 
 
159
        for(i = 0; i < errors.length; ++i)
 
160
                html += makeResultRow(errors[i], 'red');
 
161
        for(i = 0; i < warnings.length; ++i)
 
162
                html += makeResultRow(warnings[i], 'yellow');
 
163
        for(i = 0; i < infos.length; ++i)
 
164
                html += makeResultRow(infos[i], '#8080ff');
 
165
 
 
166
        html += "</table>";
 
167
        html += "</body></html>";
 
168
        TW.result = html;
119
169
}
 
170
undefined;