From 131e6177e1e1b334ebc2e34f74042c96618684f1 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 13 Aug 2021 11:17:35 -0400 Subject: [PATCH] Sort of get html and xml syntax highlighting working --- src/Enum/SyntaxFamily.php | 16 +++++++++++++++ src/FileType.php | 41 +++++++++++++++++++++++++++++++++++++++ src/Syntax.php | 11 +++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/Enum/SyntaxFamily.php b/src/Enum/SyntaxFamily.php index e69de29..3d516ab 100644 --- a/src/Enum/SyntaxFamily.php +++ b/src/Enum/SyntaxFamily.php @@ -0,0 +1,16 @@ + Syntax::new( + 'Html', + [ + '!doctype', '!DOCTYPE', 'html', 'base', 'head', 'link', 'meta', 'style', 'title', 'body', 'address', 'article', + 'aside', 'footer', 'header', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'main', 'nav', 'section', + 'blockquote', 'dd', 'div', 'dl', 'dt', 'figcaption', 'figure', 'hr', 'li', 'ol', 'p', 'pre', + 'ul', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', + 'mark', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', + 'u', 'var', 'wbr', 'area', 'audio', 'img', 'map', 'track', 'video', 'embed', 'iframe', 'object', + 'param', 'picture', 'portal', 'source', 'svg', 'math', 'canvas', 'noscript', 'script', 'del', + 'ins', 'caption', 'col', 'colgroup', 'table', 'td', 'tbody', 'tfoot', 'th', 'thead', 'tr', + 'button', 'datalist', 'fieldset', 'form', 'input', 'label', 'legend', 'meter', 'optgroup', + 'option', 'output', 'progress', 'select', 'textarea', 'details', 'dialog', 'menu', 'summary', + 'slot', 'template', 'frameset', 'frame', 'noframes', 'marquee', 'font', 'center', + ], + [ + 'id', 'class', 'for', 'style', 'charset' + ], + operators: [''], + slcs: '', + mcs: '', + highlightNumbers: false, + hasCommonOperators: false, + syntaxFamily: SyntaxFamily::XML, + ), + '.xml' => Syntax::new( + 'XML', + [ + '!doctype', '!element', '', + ], + operators: ['<', '=', '>'], + slcs: '', + mcs: '', + highlightNumbers: false, + hasCommonOperators: false, + syntaxFamily: SyntaxFamily::XML, + ), default => Syntax::default(), }; } diff --git a/src/Syntax.php b/src/Syntax.php index 93ea2e8..76986f7 100644 --- a/src/Syntax.php +++ b/src/Syntax.php @@ -2,6 +2,8 @@ namespace Aviat\Kilo; +use Aviat\Kilo\Enum\SyntaxFamily; + class Syntax { // Tokens for PHP files public array $tokens = []; @@ -20,6 +22,7 @@ class Syntax { bool $hasCharType = false, bool $highlightCharacters = false, bool $hasCommonOperators = true, + string $syntaxFamily = SyntaxFamily::C, ): self { return new self( @@ -36,6 +39,7 @@ class Syntax { $highlightStrings, $highlightComments, $hasCommonOperators, + $syntaxFamily, ); } @@ -79,6 +83,8 @@ class Syntax { private bool $highlightComments, /** should we highlight common operators? */ private bool $hasCommonOperators, + /** What kind of general syntax family does this file belong to? */ + private string $syntaxFamily, ) {} public function numbers(): bool @@ -117,4 +123,9 @@ class Syntax { { return $this->hasCommonOperators; } + + public function syntaxFamily(): string + { + return $this->syntaxFamily; + } } \ No newline at end of file