Skip to content

Commit ad0f45b

Browse files
committed
Bundle KaTeX together and fix a bug of whitespacing
1 parent 34e87f2 commit ad0f45b

File tree

90 files changed

+36
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+36
-23
lines changed

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,40 @@ build: lint build/pseudocode.min.js build/pseudocode.min.css
55
setup:
66
npm install
77
mkdir -p build
8+
ln -s ../static/fonts build/fonts
89

910
# Watch the changes to js source code and update the target js code
1011
watch-js: pseudocode.js $(wildcard src/*.js)
11-
./node_modules/.bin/watchify $< --exclude katex --standalone pseudocode -o build/pseudocode.js
12+
./node_modules/.bin/watchify $< --standalone pseudocode -o build/pseudocode.js
1213

1314
clean:
1415
rm -rf build/*
16+
ln -s ../static/fonts build/fonts
1517

1618
zip: build/pseudocode-js.tar.gz build/pseudocode-js.zip
1719

1820
lint: pseudocode.js $(wildcard src/*.js)
1921
./node_modules/.bin/jshint $^
2022

21-
# although pseudocode.js depends on katex, pseudocode.js will not be
22-
# bundled with katex, as users are likely to have katex.js loade in a separate
23-
# file by browser
2423
build/pseudocode.js: pseudocode.js $(wildcard src/*.js)
25-
./node_modules/.bin/browserify $< --exclude katex --standalone pseudocode -o $@
24+
./node_modules/.bin/browserify $< --standalone pseudocode -o $@
2625

2726
build/pseudocode.min.js: build/pseudocode.js
2827
./node_modules/.bin/uglifyjs --mangle --beautify beautify=false < $< > $@
2928

30-
build/pseudocode.min.css: static/pseudocode.css
29+
build/pseudocode.min.css: build/pseudocode.css
3130
./node_modules/.bin/cleancss -o $@ $<
3231

32+
build/pseudocode.css: static/pseudocode.css static/katex.min.css
33+
cp static/katex.min.css build/pseudocode.css
34+
cat static/pseudocode.css >> build/pseudocode.css
35+
3336
build/pseudocode: build/pseudocode.min.js build/pseudocode.min.css README.md
3437
mkdir -p build/pseudocode
3538
cp -r $^ build/pseudocode
3639

3740
build/pseudocode-js.tar.gz: build/pseudocode
38-
cd build && tar czf pseudocode-js.tar.gz pseudocode/
41+
cd build && cp -r fonts pseudocode/ && tar czf pseudocode-js.tar.gz pseudocode/
3942

4043
build/pseudocode-js.zip: build/pseudocode
41-
cd build && zip -rq pseudocode-js.zip pseudocode/
44+
cd build && cp -r fonts pseudocode && zip -rq pseudocode-js.zip pseudocode/

README.md

Lines changed: 2 additions & 6 deletions

src/Parser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,26 @@ Parser.prototype._parseOpenText = function() {
387387

388388
Parser.prototype._parseText = function(openOrClose) {
389389
var textNode = new ParseNode(openOrClose + '-text');
390-
390+
// any whitespace between Atom and CloseText
391+
var anyWhitespace = false;
391392
var atomNode;
392393
while (true) {
393394
atomNode = this._parseAtom();
394395
if (atomNode) {
396+
if (anyWhitespace) atomNode.whitespace |= anyWhitespace;
395397
textNode.addChild(atomNode);
396398
continue;
397399
}
398400

399401
if (this._lexer.accept('open')) {
400402
var subTextNode = this._parseCloseText();
403+
404+
anyWhitespace = this._lexer.get().whitespace;
405+
subTextNode.whitespace = anyWhitespace;
406+
401407
textNode.addChild(subTextNode);
402408
this._lexer.expect('close');
409+
anyWhitespace = this._lexer.get().whitespace;
403410
continue;
404411
}
405412

src/Renderer.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/*
22
* TODO: rename commentSymbol to commentDelimiters
33
* */
4-
/* katex package may either be defined in a separate js file loaded by browser
5-
* or imported by node.js.
6-
* */
4+
var katex = require('katex');
75
var utils = require('./utils');
86

97
/*
@@ -157,7 +155,6 @@ TextEnvironment.prototype.renderToHTML = function() {
157155
this._html.putText(text);
158156
break;
159157
case 'math':
160-
if (!katex) katex = require('katex');
161158
var mathHTML = katex.renderToString(text);
162159
this._html.putSpan(mathHTML);
163160
break;
@@ -194,6 +191,7 @@ TextEnvironment.prototype.renderToHTML = function() {
194191
var newTextStyle = new TextStyle(this._textStyle.fontSize());
195192
var closeTextEnv = new TextEnvironment(
196193
node.children, newTextStyle);
194+
if (node.whitespace) this._html.putText(' ');
197195
this._html.putSpan(closeTextEnv.renderToHTML());
198196
break;
199197
// There are two kinds of typestyle commands:

static/fonts/KaTeX_AMS-Regular.eot

59.3 KB
Binary file not shown.

static/fonts/KaTeX_AMS-Regular.ttf

59.1 KB
Binary file not shown.
34.1 KB
Binary file not shown.
27.9 KB
Binary file not shown.
12.4 KB
Binary file not shown.
12.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)