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

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

@ -348,6 +348,18 @@ class Parser {
} }
array_push($elms, $obj); 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 } else
$buffer .= self::StripBackslashes($this->consume()->data); $buffer .= self::StripBackslashes($this->consume()->data);
} }
@ -657,9 +669,11 @@ class Parser {
$this->parseHeading(); $this->parseHeading();
break; break;
case TokenType::NUMBER: case TokenType::NUMBER:
$list = $this->parseList(ListType::ORDERED); if ($this->next()->type === TokenType::DOT) {
$this->document->appendChild($list); $list = $this->parseList(ListType::ORDERED);
break; $this->document->appendChild($list);
break;
}
case TokenType::BACKTICK: case TokenType::BACKTICK:
$this->parseCodeBlock(); $this->parseCodeBlock();
break; break;

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

Loading…
Cancel
Save