-
Notifications
You must be signed in to change notification settings - Fork 2
/
COMPARE.js
504 lines (441 loc) · 10.9 KB
/
COMPARE.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
const fs = require("fs");
const path = require("path");
const dom = require("htmldom2").DOMParser;
const xpath = require("xpath");
const ghDiffHTML = require('gh-diff-html')
const staticPath = (filename) => {
return path.join(__dirname, "static", filename);
}
const scriptsPath = (filename) => {
return path.join(__dirname, "scripts", filename);
}
const mapsPath = (filename) => {
return path.join(__dirname, "..", "JM", "jurism", "juris-abbrevs", filename);
}
const immediatePath = (filename) => {
return path.join(__dirname, filename);
}
const oldXml = fs.readFileSync(immediatePath("indigobook-old.html")).toString();
const newXml = fs.readFileSync(staticPath("indigobook.html")).toString();
const fixup = (txt) => {
var txt = node.innerHTML;
txt = txt.replace(/^<span[^>]+>/, "").replace(/<\/span>$/, "");
txt = txt.trim();
txt = txt.replace(/<var>/g, "[var]").replace(/<\/var>/g, "[/var]");
txt = txt.replace(/<[^>]+>/g, "");
txt = txt.replace(/\[var\]/g, "<").replace(/\[\/var\]/g, ">");
txt = txt.replace(/&/g, "&");
txt = txt.replace(/&/g, "&");
txt = txt.replace(/&/g, "&");
txt = txt.replace(/\.$/, "");
return txt;
}
var oldStuff = {};
var doc = new dom().parseFromString(oldXml, "text/html");
var nodes = xpath.select("//span[contains(@class, 'cite')]", doc);
for (var node of nodes) {
var html_id = node.getAttribute("id");
if (!html_id) console.log("OUCH1");
oldStuff[html_id] = fixup(node.innerHTML);
}
var newStuff = {};
doc = new dom().parseFromString(newXml, "text/html");
var nodes = xpath.select("//span[contains(@class, 'cite')]", doc);
for (var node of nodes) {
var html_id = node.getAttribute("id");
newStuff[html_id] = fixup(node.innerHTML);
}
var ret = [];
for (var key in newStuff) {
var oldThing = oldStuff[key];
var newThing = newStuff[key];
if (oldThing !== newThing) {
ret.push(ghDiffHTML(oldThing+"\n", newThing+"\n", {
outputFormat: 'line-by-line',
fileName: key
}));
}
}
var html = ret.join("\n");
var HTML = `
<head>
<title>IndigoBook diffs</title>
<style>
.d2h-wrapper {
text-align: left;
}
.d2h-file-header {
padding: 5px 10px;
border-bottom: 1px solid #d8d8d8;
background-color: #f7f7f7;
}
.d2h-file-stats {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-left: auto;
font-size: 14px;
}
.d2h-lines-added {
text-align: right;
border: 1px solid #b4e2b4;
border-radius: 5px 0 0 5px;
color: #399839;
padding: 2px;
vertical-align: middle;
}
.d2h-lines-deleted {
text-align: left;
border: 1px solid #e9aeae;
border-radius: 0 5px 5px 0;
color: #c33;
padding: 2px;
vertical-align: middle;
margin-left: 1px;
}
.d2h-file-name-wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 15px;
}
.d2h-file-name {
white-space: nowrap;
text-overflow: ellipsis;
overflow-x: hidden;
line-height: 21px;
}
.d2h-file-wrapper {
border: 1px solid #ddd;
border-radius: 3px;
margin-bottom: 1em;
}
.d2h-diff-table {
width: 100%;
border-collapse: collapse;
font-family: "Menlo", "Consolas", monospace;
font-size: 13px;
}
.d2h-diff-tbody > tr > td {
height: 20px;
line-height: 20px;
}
.d2h-files-diff {
display: block;
width: 100%;
height: 100%;
}
.d2h-file-diff {
overflow-x: scroll;
overflow-y: hidden;
}
.d2h-file-side-diff {
display: inline-block;
overflow-x: scroll;
overflow-y: hidden;
width: 50%;
margin-right: -4px;
margin-bottom: -8px;
}
.d2h-code-line {
display: inline-block;
white-space: nowrap;
padding: 0 10px;
margin-left: 80px;
}
.d2h-code-side-line {
display: inline-block;
white-space: nowrap;
padding: 0 10px;
margin-left: 50px;
}
.d2h-code-line del,
.d2h-code-side-line del {
display: inline-block;
margin-top: -1px;
text-decoration: none;
background-color: #ffb6ba;
border-radius: 0.2em;
}
.d2h-code-line ins,
.d2h-code-side-line ins {
display: inline-block;
margin-top: -1px;
text-decoration: none;
background-color: #97f295;
border-radius: 0.2em;
text-align: left;
}
.d2h-code-line-prefix {
display: inline;
background: none;
padding: 0;
word-wrap: normal;
white-space: pre;
}
.d2h-code-line-ctn {
display: inline;
background: none;
padding: 0;
word-wrap: normal;
white-space: pre;
}
.line-num1 {
box-sizing: border-box;
float: left;
width: 40px;
overflow: hidden;
text-overflow: ellipsis;
padding-left: 3px;
}
.line-num2 {
box-sizing: border-box;
float: right;
width: 40px;
overflow: hidden;
text-overflow: ellipsis;
padding-left: 3px;
}
.d2h-code-linenumber {
box-sizing: border-box;
position: absolute;
width: 86px;
padding-left: 2px;
padding-right: 2px;
background-color: #fff;
color: rgba(0, 0, 0, 0.3);
text-align: right;
border: solid #eeeeee;
border-width: 0 1px 0 1px;
cursor: pointer;
}
.d2h-code-side-linenumber {
box-sizing: border-box;
position: absolute;
width: 56px;
padding-left: 5px;
padding-right: 5px;
background-color: #fff;
color: rgba(0, 0, 0, 0.3);
text-align: right;
border: solid #eeeeee;
border-width: 0 1px 0 1px;
cursor: pointer;
overflow: hidden;
text-overflow: ellipsis;
}
/*
* Changes Highlight
*/
.d2h-del {
background-color: #fee8e9;
border-color: #e9aeae;
}
.d2h-ins {
background-color: #dfd;
border-color: #b4e2b4;
}
.d2h-info {
background-color: #f8fafd;
color: rgba(0, 0, 0, 0.3);
border-color: #d5e4f2;
}
.d2h-file-diff .d2h-del.d2h-change {
background-color: #fdf2d0;
}
.d2h-file-diff .d2h-ins.d2h-change {
background-color: #ded;
}
/*
* File Summary List
*/
.d2h-file-list-wrapper {
margin-bottom: 10px;
}
.d2h-file-list-wrapper a {
text-decoration: none;
color: #3572b0;
}
.d2h-file-list-wrapper a:visited {
color: #3572b0;
}
.d2h-file-list-header {
text-align: left;
}
.d2h-file-list-title {
font-weight: bold;
}
.d2h-file-list-line {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
text-align: left;
}
.d2h-file-list {
display: block;
list-style: none;
padding: 0;
margin: 0;
}
.d2h-file-list > li {
border-bottom: #ddd solid 1px;
padding: 5px 10px;
margin: 0;
}
.d2h-file-list > li:last-child {
border-bottom: none;
}
.d2h-file-switch {
display: none;
font-size: 10px;
cursor: pointer;
}
.d2h-icon-wrapper {
line-height: 31px;
}
.d2h-icon {
vertical-align: middle;
margin-right: 10px;
fill: currentColor;
}
.d2h-deleted {
color: #c33;
}
.d2h-added {
color: #399839;
}
.d2h-changed {
color: #d0b44c;
}
.d2h-moved {
color: #3572b0;
}
.d2h-tag {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
font-size: 10px;
margin-left: 5px;
padding: 0 2px;
background-color: #fff;
}
.d2h-deleted-tag {
border: #c33 1px solid;
}
.d2h-added-tag {
border: #399839 1px solid;
}
.d2h-changed-tag {
border: #d0b44c 1px solid;
}
.d2h-moved-tag {
border: #3572b0 1px solid;
}
/*
* Selection util.
*/
.selecting-left .d2h-code-line,
.selecting-left .d2h-code-line *,
.selecting-right td.d2h-code-linenumber,
.selecting-right td.d2h-code-linenumber *,
.selecting-left .d2h-code-side-line,
.selecting-left .d2h-code-side-line *,
.selecting-right td.d2h-code-side-linenumber,
.selecting-right td.d2h-code-side-linenumber * {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.selecting-left .d2h-code-line::-moz-selection,
.selecting-left .d2h-code-line *::-moz-selection,
.selecting-right td.d2h-code-linenumber::-moz-selection,
.selecting-left .d2h-code-side-line::-moz-selection,
.selecting-left .d2h-code-side-line *::-moz-selection,
.selecting-right td.d2h-code-side-linenumber::-moz-selection,
.selecting-right td.d2h-code-side-linenumber *::-moz-selection {
background: transparent;
}
.selecting-left .d2h-code-line::selection,
.selecting-left .d2h-code-line *::selection,
.selecting-right td.d2h-code-linenumber::selection,
.selecting-left .d2h-code-side-line::selection,
.selecting-left .d2h-code-side-line *::selection,
.selecting-right td.d2h-code-side-linenumber::selection,
.selecting-right td.d2h-code-side-linenumber *::selection {
background: transparent;
}
</style>
<style>
.d2h-files-diff {
display: flex;
height: initial;
}
.d2h-diff-tbody tr:first-of-type {
display: none;
}
.d2h-diff-tbody>tr>td {
height: 22px;
}
.d2h-file-side-diff {
margin-bottom: 0;
}
li {
margin-top: 0.5em;
}
</style>
</head>
<body>
<h1>IndigoBook diffs</h1>
<div>
<span style="border-radius:1em;border: solid black 2px;padding:1em;">
Return to <a href="index.html">IndigoBook+Jurism project page</a>
</span>
</div>
<p>
This page shows changes made to the text of citation examples in the IndigoBook
in connection with the IndigoBook+Jurism integration. The revised forms in
green reflect the output Jurism citation processor against appropriate metadata.
A few notes on the content:
</p>
<ul>
<li>Many of the changes are small adjustments to typography, such as
changing straight-quotes to curly-quotes, or setting en-dash rather
than hyphen as the delimiter for ranged numbers.</li>
<li>Some touch on editorial choices. Some of these are arbitrary, such as the use of “No.”
versus no-label against docket numbers. Others reflect inconsistency in formatting
embodied in the original examples, where there is no explicit governing rule. An example
of this latter case is the use or non-use of “at“ to set off a pinpoint page number.
In both cases, editorial preferences should govern. If changes need to be made to
any of these citations, just let me know.
</li>
<li>Examples of multiple
citations (parallel citations and procedural histories) are due to
changes in the scope of the <span
style="font-family:ariel"><span></span></span> citation
wrapper to include additional portions of the citation. In these cases
there may be no actual difference in the cites themselves.</li>
<li>The examples that include placeholders bracketed in “<span
style="font-family:ariel"><</span>” and “<span
style="font-family:ariel">></span>” characters are a bit
special. For these, the bracketed elements are converted to actual
values for testing purposes. To produce meaningful test data, cryptic
placeholders such as <span style="font-family:ariel"><xx></span>
have been replaced with placeholders that make their semantics more
clear. The changes in that regard were done on the fly while building
the citation stylesheet, and have not yet been normalized across
IndigoBook. Editors should feel free to make changes to these: just
send a note that changes have been made (no need for a detailed list)
so that I can make any necessary adjustments at this end.</li>
</ul>
<hr/>
${html}
</body>
`
fs.writeFileSync(path.join(__dirname, "static", "indigobook-diffs.html"), HTML);