Skip to content

Commit 46138b9

Browse files
committed
Update dependencies; remove fonts; test with KaTeX 0.8
1 parent bfa77e6 commit 46138b9

Some content is hidden

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

50 files changed

+523
-402
lines changed

.eslintrc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"rules": {
3+
"arrow-spacing": 2,
4+
"brace-style": [2, "stroustrup", { "allowSingleLine": true }],
5+
// We'd possibly like to remove the 'properties': 'never' one day.
6+
"camelcase": [2, { "properties": "never" }],
7+
"comma-dangle": [2, "always-multiline"],
8+
"comma-spacing": [2, { "before": false, "after": true }],
9+
"constructor-super": 2,
10+
"curly": 0,
11+
"eol-last": 2,
12+
"eqeqeq": [2, "allow-null"],
13+
"guard-for-in": 0,
14+
"indent": [1, 4, {"SwitchCase": 1}],
15+
"keyword-spacing": 2,
16+
"linebreak-style": [2, "unix"],
17+
"max-len": [2, 84, 4, { "ignoreUrls": true, "ignorePattern": "\\brequire\\([\"']|eslint-disable", "ignoreComments": true, }],
18+
"no-alert": 2,
19+
"no-array-constructor": 2,
20+
"no-console": 2,
21+
"no-const-assign": 2,
22+
"no-constant-condition": 0,
23+
"no-debugger": 2,
24+
"no-dupe-class-members": 2,
25+
"no-dupe-keys": 2,
26+
"no-extra-bind": 2,
27+
"no-new": 2,
28+
"no-new-func": 2,
29+
"no-new-object": 2,
30+
"no-spaced-func": 2,
31+
"no-this-before-super": 2,
32+
"no-throw-literal": 0,
33+
"no-trailing-spaces": 2,
34+
"no-undef": 0,
35+
"no-unexpected-multiline": 2,
36+
"no-unreachable": 2,
37+
"no-unused-vars": [2, {"args": "none", "varsIgnorePattern": "^_*$"}],
38+
"no-useless-call": 2,
39+
"no-with": 2,
40+
"one-var": [2, "never"],
41+
"prefer-const": 2,
42+
"prefer-spread": 0, // re-enable once we use es6
43+
"semi": [2, "always"],
44+
"space-before-blocks": 2,
45+
"space-before-function-paren": [2, "never"],
46+
"space-infix-ops": 2,
47+
"space-unary-ops": 2,
48+
// ---------------------------------------
49+
// Stuff we explicitly disable.
50+
// We turned this off because it complains when you have a
51+
// multi-line string, which I think is going too far.
52+
"prefer-template": 0,
53+
// We've decided explicitly not to care about this.
54+
"arrow-parens": 0,
55+
// ---------------------------------------
56+
// TODO(csilvers): enable these if/when community agrees on it.
57+
"prefer-arrow-callback": 0,
58+
"object-curly-spacing": [0, "always"],
59+
// Might be nice to turn this on one day, but since we don't
60+
// use jsdoc anywhere it seems silly to require it yet.
61+
"valid-jsdoc": 0,
62+
"require-jsdoc": 0
63+
},
64+
"ecmaFeatures": {
65+
"arrowFunctions": true,
66+
"blockBindings": true,
67+
"classes": true,
68+
"destructuring": true,
69+
"experimentalObjectRestSpread": true,
70+
"forOf": true,
71+
"jsx": true,
72+
"restParams": true,
73+
"spread": true,
74+
"templateStrings": true
75+
},
76+
"env": {
77+
"es6": true,
78+
"node": true,
79+
"browser": true
80+
},
81+
"extends": "eslint:recommended",
82+
"root": true
83+
}

Makefile

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,69 @@
1-
.PHONY: setup lint build zip build/pseudocode clean
1+
.PHONY: default setup lint build release clean
22

3-
build: lint build/pseudocode.min.js build/pseudocode.min.css
3+
VERSION=1.1
44

5-
setup: setup-katex
5+
# Building tools
6+
BROWSERIFY = $(realpath ./node_modules/.bin/browserify)
7+
WATCHIFY = $(realpath ./node_modules/.bin/watchify)
8+
UGLIFYJS = $(realpath ./node_modules/.bin/uglifyjs) \
9+
--mangle \
10+
--beautify \
11+
ascii_only=true,beautify=false
12+
CLEANCSS = $(realpath ./node_modules/.bin/cleancss)
13+
ESLINT = $(realpath ./node_modules/.bin/eslint)
14+
15+
default: build
16+
17+
18+
setup: static/katex/
619
npm install
7-
mkdir -p build
8-
ln -s ../static/fonts build/fonts
9-
ln -s ../static/katex build/katex
20+
@echo "> Node.js packages installed"
1021

11-
setup-katex:
22+
static/katex/:
1223
@rm -rf static/katex
13-
cd static && wget https://github.com/Khan/KaTeX/releases/download/v0.2.0/katex.zip && unzip katex.zip
24+
cd static && wget https://github.com/Khan/KaTeX/releases/download/v0.8.0/katex.zip && unzip katex.zip
1425
@rm -rf static/katex.zip
26+
@echo "> Katex downloaded"
1527

16-
# Watch the changes to js source code and update the target js code
17-
watch-js: pseudocode.js $(wildcard src/*.js)
18-
./node_modules/.bin/watchify $< --standalone pseudocode -o build/pseudocode.js
1928

20-
clean:
21-
rm -rf build/*
22-
ln -s ../static/fonts build/fonts
29+
build: build/pseudocode.js build/pseudocode.css
30+
@echo "> Building succeeded"
2331

24-
zip: build/pseudocode-js.tar.gz build/pseudocode-js.zip
32+
build/pseudocode.min.js: build/pseudocode.js
33+
$(UGLIFYJS) < $< > $@
34+
35+
build/pseudocode.js: pseudocode.js $(wildcard src/*.js)
36+
@$(MAKE) --no-print-directory lint
37+
$(BROWSERIFY) $< --exclude katex --standalone pseudocode -o $@
2538

2639
lint: pseudocode.js $(wildcard src/*.js)
27-
./node_modules/.bin/jshint $^
40+
$(ESLINT) $^
2841

29-
build/pseudocode.js: pseudocode.js $(wildcard src/*.js)
30-
./node_modules/.bin/browserify --exclude katex $< --standalone pseudocode -o $@
42+
# Watch the changes to js source code and update the target js code
43+
watch-js: pseudocode.js $(wildcard src/*.js)
44+
$(WATCHIFY) $< --standalone pseudocode -o build/pseudocode.js
3145

32-
build/pseudocode.min.js: build/pseudocode.js
33-
./node_modules/.bin/uglifyjs --mangle --beautify beautify=false < $< > $@
46+
build/pseudocode.min.css: build/pseudocode.css
47+
$(CLEANCSS) -o $@ $<
3448

3549
build/pseudocode.css: static/pseudocode.css
3650
cp static/pseudocode.css build/pseudocode.css
3751

38-
build/pseudocode.min.css: build/pseudocode.css
39-
./node_modules/.bin/cleancss -o $@ $<
4052

41-
build/pseudocode: build/pseudocode.min.js build/pseudocode.min.css README.md
42-
mkdir -p build/pseudocode
43-
cp -r $^ build/pseudocode
53+
release: build/pseudocode-js.tar.gz build/pseudocode-js.zip
54+
@echo "> Release package generated"
4455

45-
build/pseudocode-js.tar.gz: build/pseudocode
46-
cd build && cp -r fonts pseudocode/ && tar czf pseudocode-js.tar.gz pseudocode/
56+
RELEASE_DIR=pseudocode-$(VERSION)/
57+
build/pseudocode-js.tar.gz: build/$(RELEASE_DIR)
58+
cd build && tar czf pseudocode-js.tar.gz $(RELEASE_DIR)
4759

48-
build/pseudocode-js.zip: build/pseudocode
49-
cd build && cp -r fonts pseudocode && zip -rq pseudocode-js.zip pseudocode/
60+
build/pseudocode-js.zip: build/$(RELEASE_DIR)
61+
cd build && zip -rq pseudocode-js.zip $(RELEASE_DIR)
62+
63+
build/$(RELEASE_DIR): build/pseudocode.min.js build/pseudocode.min.css README.md
64+
mkdir -p build/$(RELEASE_DIR)
65+
cp -r $^ build/$(RELEASE_DIR)
66+
67+
68+
clean:
69+
@rm -rf build/*

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ HTML.
1212
* **Math formula support:** Inserting math formulas in pseudocode.js is as easy
1313
as LaTeX. Just enclose math expression in `$...$` or `\(...\)`.
1414

15-
It supports all modern browsers, including Chrome, Safari,
16-
Firefox, Opera, and IE 8 - IE 11.
17-
15+
It supports all modern browsers, including Chrome, Safari, Firefox, Edge, and
16+
IE 9 - IE 11.
17+
1818
## Demo
1919
Visit the [project website](http://www.tatetian.io/pseudocode.js) for demo.
2020

2121
## Usage
2222

23-
### Basics
23+
### Quick Start
2424
Download [pseudocode.js](https://github.com/tatetian/pseudocode.js/releases),
2525
and host the files on your server. And then include the `js` and `css` files in
2626
your HTML files:
@@ -30,11 +30,9 @@ your HTML files:
3030
<script src="//path/to/pseudocode/pseudocode.min.js"></script>
3131
```
3232

33-
Pseudocode.js uses [KaTeX](https://github.com/Khan/KaTeX) to render math
34-
formulas. So if you want to include any math formulas in
35-
your pseudocode, make sure that [KaTeX is
36-
setup](https://github.com/Khan/KaTeX#usage).
37-
33+
Pseudocode.js depends on [KaTeX](https://github.com/Khan/KaTeX) to render math
34+
formulas and uses KaTeX's fonts to render texts. So make sure that [KaTeX is
35+
setup](https://github.com/Khan/KaTeX#usage) properly.
3836

3937
Assume the pseudocode to be rendered is in a `<pre>` DOM element:
4038
```html
@@ -218,6 +216,23 @@ var DEFAULT_OPTIONS = {
218216
captionCount: undefined
219217
};
220218
```
219+
220+
## Build and Test
221+
Pseudocode.js is written in JavaScript and built with [Node.js](https://nodejs.org).
222+
So, make sure you have Node.js installed before building pseudocode.js.
223+
224+
To compile the project on Ubuntu Linux, run the following commands in terminal:
225+
226+
```bash
227+
cd pseudocode.js/
228+
make setup
229+
make
230+
```
231+
232+
Then, open `static/test-suite.html` in your favourite browser to see whether
233+
algorithms are typeset correctly.
234+
235+
221236
## Author
222237
Tate Tian ([@tatetian](https://github.com/tatetian)) creates pseudocode.js. Any
223238
suggestions and bug reports are welcome.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
"src/"
1818
],
1919
"devDependencies": {
20-
"browserify": "~9.0.3",
21-
"watchify": "~2.4.0",
22-
"uglify-js": "~2.4.15",
23-
"clean-css": "~2.2.15",
24-
"jshint": "^2.5.6",
25-
"katex": "~0.1.1"
20+
"browserify": "^13.3.0",
21+
"watchify": "^3.9.0",
22+
"uglify-js": "~2.7.5",
23+
"clean-css-cli": "^4.0.0",
24+
"eslint": "^3.13.0"
2625
},
2726
"license": "MIT"
2827
}

pseudocode.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/*
22
* The entry points of pseudocode-js
3-
*
4-
* TODO:
5-
* * Test on IE8 - IE10
6-
* * Support color
73
**/
84

95
var ParseError = require('./src/ParseError');
@@ -32,5 +28,5 @@ module.exports = {
3228
var ele = renderer.toDOM();
3329
if (baseDomEle) baseDomEle.appendChild(ele);
3430
return ele;
35-
}
31+
},
3632
};

src/Lexer.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Lexer.prototype.expect = function(type, text) {
2626
// The next atom is NOT of the right type
2727
if (nextAtom.type !== type)
2828
throw new ParseError('Expect an atom of ' + type + ' but received ' +
29-
nextAtom.type, this._pos, this._input);
29+
nextAtom.type, this._pos, this._input);
3030
// Check whether the text is exactly the same
3131
if (!this._matchText(text))
32-
throw new ParseError('Expect `' + text + '` but received `' +
33-
nextAtom.text + '`', this._pos, this._input);
32+
throw new ParseError('Expect `' + text + '` but received `' +
33+
nextAtom.text + '`', this._pos, this._input);
3434

3535
this._next();
3636
return this._currentAtom.text;
@@ -48,7 +48,7 @@ var mathPattern = {
4848
exec: function(str) {
4949
var delimiters = [
5050
{start: '$', end: '$'},
51-
{start: '\\(', end: '\\)'}
51+
{start: '\\(', end: '\\)'},
5252
];
5353
var totalLen = str.length;
5454

@@ -62,7 +62,8 @@ var mathPattern = {
6262
while (endPos < totalLen) {
6363
var pos = remain.indexOf(endDel);
6464
if (pos < 0)
65-
throw new ParseError('Math environment is not closed', this._pos, this._input);
65+
throw new ParseError('Math environment is not closed',
66+
this._pos, this._input);
6667

6768
// false positive, it's escaped, not a match
6869
if (pos > 0 && remain[pos - 1] === '\\') {
@@ -73,13 +74,13 @@ var mathPattern = {
7374
}
7475

7576
var res = [str.slice(0, endPos + pos + endDel.length),
76-
str.slice(startDel.length, endPos + pos)];
77+
str.slice(startDel.length, endPos + pos)];
7778
return res;
7879
}
7980
}
8081

8182
return null;
82-
}
83+
},
8384
};
8485
var atomRegex = {
8586
// TODO: which is correct? func: /^\\(?:[a-zA-Z]+|.)/,
@@ -89,7 +90,7 @@ var atomRegex = {
8990
open: /^\{/,
9091
close: /^\}/,
9192
quote: /^(`|``|'|'')/,
92-
ordinary: /^[^\\{}$&#%_\s]+/
93+
ordinary: /^[^\\{}$&#%_\s]+/,
9394
};
9495
var commentRegex = /^%.*/;
9596
var whitespaceRegex = /^\s+/;
@@ -126,7 +127,7 @@ Lexer.prototype._next = function() {
126127
this._nextAtom = {
127128
type: 'EOF',
128129
text: null,
129-
whitespace: false
130+
whitespace: false,
130131
};
131132
return false;
132133
}
@@ -145,7 +146,7 @@ Lexer.prototype._next = function() {
145146
this._nextAtom = {
146147
type: type, /* special, func, open, close, ordinary, math */
147148
text: usefulText, /* the text value of the atom */
148-
whitespace: anyWhitespace /* any whitespace before the atom */
149+
whitespace: anyWhitespace, /* any whitespace before the atom */
149150
};
150151

151152
this._pos += matchText.length;

0 commit comments

Comments
 (0)