Sort of get html and xml syntax highlighting working
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit
This commit is contained in:
parent
4d91919fb5
commit
131e6177e1
@ -0,0 +1,16 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Aviat\Kilo\Enum;
|
||||||
|
|
||||||
|
use Aviat\Kilo\Traits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SyntaxFamily {
|
||||||
|
use Traits\ConstList;
|
||||||
|
|
||||||
|
public const C = 'C';
|
||||||
|
|
||||||
|
public const XML = 'XML';
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Aviat\Kilo;
|
namespace Aviat\Kilo;
|
||||||
|
|
||||||
|
use Aviat\Kilo\Enum\SyntaxFamily;
|
||||||
|
|
||||||
class FileType {
|
class FileType {
|
||||||
/**
|
/**
|
||||||
* Create the FileType object from the filename
|
* Create the FileType object from the filename
|
||||||
@ -125,6 +127,45 @@ class FileType {
|
|||||||
hasCharType: true,
|
hasCharType: true,
|
||||||
highlightCharacters: true,
|
highlightCharacters: true,
|
||||||
),
|
),
|
||||||
|
'.html', '.htm', '.shtml' => 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: '<!--',
|
||||||
|
mce: '-->',
|
||||||
|
highlightNumbers: false,
|
||||||
|
hasCommonOperators: false,
|
||||||
|
syntaxFamily: SyntaxFamily::XML,
|
||||||
|
),
|
||||||
|
'.xml' => Syntax::new(
|
||||||
|
'XML',
|
||||||
|
[
|
||||||
|
'!doctype', '!element', '<?xml', '?>',
|
||||||
|
],
|
||||||
|
operators: ['<', '=', '>'],
|
||||||
|
slcs: '',
|
||||||
|
mcs: '<!--',
|
||||||
|
mce: '-->',
|
||||||
|
highlightNumbers: false,
|
||||||
|
hasCommonOperators: false,
|
||||||
|
syntaxFamily: SyntaxFamily::XML,
|
||||||
|
),
|
||||||
default => Syntax::default(),
|
default => Syntax::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Aviat\Kilo;
|
namespace Aviat\Kilo;
|
||||||
|
|
||||||
|
use Aviat\Kilo\Enum\SyntaxFamily;
|
||||||
|
|
||||||
class Syntax {
|
class Syntax {
|
||||||
// Tokens for PHP files
|
// Tokens for PHP files
|
||||||
public array $tokens = [];
|
public array $tokens = [];
|
||||||
@ -20,6 +22,7 @@ class Syntax {
|
|||||||
bool $hasCharType = false,
|
bool $hasCharType = false,
|
||||||
bool $highlightCharacters = false,
|
bool $highlightCharacters = false,
|
||||||
bool $hasCommonOperators = true,
|
bool $hasCommonOperators = true,
|
||||||
|
string $syntaxFamily = SyntaxFamily::C,
|
||||||
): self
|
): self
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
@ -36,6 +39,7 @@ class Syntax {
|
|||||||
$highlightStrings,
|
$highlightStrings,
|
||||||
$highlightComments,
|
$highlightComments,
|
||||||
$hasCommonOperators,
|
$hasCommonOperators,
|
||||||
|
$syntaxFamily,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +83,8 @@ class Syntax {
|
|||||||
private bool $highlightComments,
|
private bool $highlightComments,
|
||||||
/** should we highlight common operators? */
|
/** should we highlight common operators? */
|
||||||
private bool $hasCommonOperators,
|
private bool $hasCommonOperators,
|
||||||
|
/** What kind of general syntax family does this file belong to? */
|
||||||
|
private string $syntaxFamily,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function numbers(): bool
|
public function numbers(): bool
|
||||||
@ -117,4 +123,9 @@ class Syntax {
|
|||||||
{
|
{
|
||||||
return $this->hasCommonOperators;
|
return $this->hasCommonOperators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function syntaxFamily(): string
|
||||||
|
{
|
||||||
|
return $this->syntaxFamily;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user