Compare commits

..

4 Commits

Author SHA1 Message Date
Michael Ochmann 21713e2209 added functionality to force a linebreak 3 years ago
Michael Ochmann 3b7e772fc7 now tokenizing spaces 3 years ago
Michael Ochmann 594b85a81e fixed bug where ordered lists and tables were wrongly detected 3 years ago
Michael Ochmann f3bbcb07e7 removed unnecessary console.log 3 years ago
  1. 5
      playground/index.php
  2. 4
      src/Lexer.php
  3. 20
      src/Parser.php
  4. 1
      src/Token.php

@ -91,8 +91,6 @@
const fromTop = Math.min(100, Math.max(0, Math.round(top * 100 / height)));
percent.innerHTML = `${fromTop}%`;
console.log("SCROOLLL", fromTop, height, top);
});
});
@ -215,6 +213,9 @@
border: none;
color: #888;
}
.statusbar > * {
margin-left: 0.5rem;
}
#position {
color: dodgerblue;

@ -119,6 +119,10 @@ class Lexer {
$clearBuffer();
array_push($tokens, new Token(TokenType::RBRACE, $char, [$col, $row, $this->fileName]));
break;
case ' ':
$clearBuffer();
array_push($tokens, new Token(TokenType::SPACE, $char, [$col, $row, $this->fileName]));
break;
default:
$buffer .= $char;
break;

@ -348,6 +348,18 @@ class Parser {
}
array_push($elms, $obj);
} elseif ($this->current()->type === TokenType::SPACE) { // do linebreak when two spaces are at the EOL
if ($this->last()->type === TokenType::SPACE && $this->next()->type === TokenType::EOL) {
$this->consume();
$clearBuffer();
$elm = $this->document->createElement("br");
array_push($elms, $elm);
continue;
} else {
$this->consume();
$buffer .= " ";
}
} else
$buffer .= self::StripBackslashes($this->consume()->data);
}
@ -657,9 +669,11 @@ class Parser {
$this->parseHeading();
break;
case TokenType::NUMBER:
$list = $this->parseList(ListType::ORDERED);
$this->document->appendChild($list);
break;
if ($this->next()->type === TokenType::DOT) {
$list = $this->parseList(ListType::ORDERED);
$this->document->appendChild($list);
break;
}
case TokenType::BACKTICK:
$this->parseCodeBlock();
break;

@ -24,6 +24,7 @@ enum TokenType {
case TAB ;
case LBRACE ;
case RBRACE ;
case SPACE ;
}
class Token {

Loading…
Cancel
Save