Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
There seemed to be some confusion between using type '#' and type
Browse files Browse the repository at this point in the history
'placeholder in the code. I switched everything to be 'placeholder'.

The real fix is that in Parser.prototype.scanToken, there was one 'if'
testing for '#' and another testing for 'placeholder'. The fix was to move
the 'placeholder' test into the '#' test so that when there was not
something to replace, a placeholder was inserted into the result.

Note: the previous code in that case (which probably was never used) used
the value of the placeholder token (typically a '0') for the placeholder.
That's not great visually, so I switch to using 'U+2753 = BLACK QUESTION
MARK ORNAMENT' which was used elsewhere.

Fixes arnog#33.
  • Loading branch information
NSoiffer committed Nov 6, 2017
1 parent 47a8c9c commit 68ceb2c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Lexer.prototype.makeToken = function() {
}
}
if (isParam) {
result = new Token('#');
result = new Token('placeholder');
next = this.get();
if (next >= '0' && next <= '9') {
result.value = parseInt(next);
Expand Down
11 changes: 5 additions & 6 deletions src/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ Parser.prototype.scanArg = function(parseMode) {

// If this is a param token, substitute it with the
// (optional) argument passed to the parser
if (this.hasToken('#')) {
if (this.hasToken('placeholder')) {
const paramToken = this.get();
this.skipUntilToken('}');
if (paramToken.value === '?') {
Expand Down Expand Up @@ -1141,10 +1141,6 @@ Parser.prototype.scanToken = function() {

result = new MathAtom(this.parseMode, 'command', body);

} else if (token.type === 'placeholder') {
// RENDER PLACEHOLDER
result = new MathAtom(this.parseMode, 'placeholder', token.value);

} else if (token.type === 'command') {
// RENDER COMMAND
if (token.value === 'char') {
Expand Down Expand Up @@ -1241,7 +1237,7 @@ Parser.prototype.scanToken = function() {
}
result.latex = Definitions.matchCodepoint(token.value);

} else if (token.type === '#') {
} else if (token.type === 'placeholder') {
// Parameter token in an implicit group (not as a parameter)
if (token.value === '?') {
// U+2753 = BLACK QUESTION MARK ORNAMENT
Expand All @@ -1254,6 +1250,9 @@ Parser.prototype.scanToken = function() {
const group = new MathAtom(this.parseMode, 'group');
group.children = result;
result = group;
} else {
// RENDER PLACEHOLDER (value is typically '0', so choose better value)
result = new MathAtom(this.parseMode, 'placeholder', '\u2753'); // U+2753 = BLACK QUESTION MARK ORNAMENT);
}
}
} else {
Expand Down

0 comments on commit 68ceb2c

Please sign in to comment.