Skip to content

Commit 0af837c

Browse files
committed
[pdf output] Normalize quotes inside code blocks
Since newunicodechar makes a mess of them otherwise.
1 parent 99bb2a6 commit 0af837c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

bin/clean_latex.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
// Check that no unicode characters that we aren't explicitly handling
2-
// with \newunicodechar snuck into the output.
3-
function checkUnicode(str) {
41
var allowedUnicode = /[π½¼×βϕé]/;
5-
var unicode = /[\x7f-\uffff]/g;
6-
var match;
7-
while (match = unicode.exec(str)) {
8-
if (!allowedUnicode.test(match[0])) {
9-
console.error("Found unhandled unicode: " + match[0]);
10-
process.exit(1);
2+
function replaceUnicode(input) {
3+
var inCode = false;
4+
return input.replace(/\\(end|begin)\{lstlisting\}|([\x80-\uffff])/g, function(full, beginEnd, ch) {
5+
if (beginEnd) {
6+
inCode = beginEnd == "begin";
7+
return full;
8+
} else {
9+
if (!allowedUnicode.test(ch)) {
10+
console.error("Found unhandled unicode: " + ch);
11+
process.exit(1);
12+
}
13+
if (inCode && /[]/.test(ch)) return '"';
14+
if (inCode && /[]/.test(ch)) return "'";
15+
return ch;
1116
}
12-
}
17+
});
1318
}
1419

1520
var escaped = {"\\{{}": "{",
@@ -65,7 +70,7 @@ process.stdin.on("end", function() {
6570
});
6671
input = cleanLstInline(input);
6772
input = input.replace(/({\\hspace\*\{.+?\}\\itshape``)\s*([^]+?)\s*('')/g, "$1$2$3");
68-
checkUnicode(input);
73+
input = replaceUnicode(input);
6974

7075
process.stdout.write(input);
7176
});

0 commit comments

Comments
 (0)