diff --git a/README.md b/README.md index 3b806b1..ca1316b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,50 @@ public function dW\Lit\Grammar::loadJSON(string $filename) ***filename*** - The JSON file to be imported +### dW\\Lit\\GrammarRegistry::clear ### + +Clears all grammars from the registry + +```php +public static function dW\Lit\GrammarRegistry::clear() +``` + + +### dW\\Lit\\GrammarRegistry::get ### + +Retrieves a grammar from the registry + +```php +public static function dW\Lit\GrammarRegistry::get(string $scopeName): Grammar|false +``` + +#### Parameters #### + +***scopeName*** - The scope name (eg: text.html.php) of the grammar that is being requested + +#### Return Values #### + +Returns a `dW\Lit\Grammar` object on success and `false` on failure. + + +### dW\\Lit\\GrammarRegistry::set ### + +Retrieves a grammar from the registry + +```php +public static function dW\Lit\GrammarRegistry::set(string $scopeName, dW\Lit\Grammar $grammar): bool +``` + +#### Parameters #### + +***scopeName*** - The scope name (eg: text.html.php) of the grammar that is being set +***grammar*** - The grammar to be put into the registry + +#### Return Values #### + +Returns `true` on success and `false` on failure. + + ### dW\\Lit\\Highlight::toElement ### Highlights incoming string data and outputs a PHP `DOMElement`. @@ -52,10 +96,10 @@ public static dW\Lit\Highlight::toElement(string $data, string $scopeName, ?\DOM #### Parameters #### -***data*** - The input data string. -***scopeName*** - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data. -***document*** - An existing `DOMDocument` to use as the owner document of the returned `DOMElement`; if omitted one will be created instead. -***encoding*** - The encoding of the input data string; only used if a document wasn't provided in the previous parameter, otherwise it uses the encoding of the existing `DOMDocument` +***data*** - The input data string +***scopeName*** - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data +***document*** - An existing `DOMDocument` to use as the owner document of the returned `DOMElement`; if omitted one will be created instead +***encoding*** - The encoding of the input data string; only used if a document wasn't provided in the previous parameter, otherwise it uses the encoding of the existing `DOMDocument`; defaults to HTML standard default windows-1252 #### Return Values #### @@ -74,7 +118,7 @@ public static dW\Lit\Highlight::toString(string $data, string $scopeName, string ***data*** - The input data string ***scopeName*** - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data -***encoding*** - The encoding of the input data string +***encoding*** - The encoding of the input data string; defaults to HTML standard default windows-1252 #### Return Values #### @@ -88,11 +132,11 @@ Here's an example of highlighting PHP code: ```php $code = << CODE; -$element = dW\Lit\Highlight::toElement($code, 'text.html.php'); +$element = dW\Lit\Highlight::toElement($code, 'text.html.php', null, 'UTF-8'); $element->setAttribute('class', 'highlighted'); // Use PHP DOM's DOMDocument::saveHTML method to print the highlighted markup @@ -104,7 +148,7 @@ This will produce: ```html
<?php
-echo "OOK!";
+echo "🐵 OOK! 🐵";
 ?>
``` diff --git a/lib/GrammarRegistry.php b/lib/GrammarRegistry.php index 5e9c08e..1f4da8d 100644 --- a/lib/GrammarRegistry.php +++ b/lib/GrammarRegistry.php @@ -12,14 +12,9 @@ class GrammarRegistry { protected static array $storage = []; - /** - * Clears all grammars from the registry - * - * @return bool - */ - public static function clear(): bool { + /** Clears all grammars from the registry */ + public static function clear() { self::$storage = []; - return true; } /** @@ -49,10 +44,8 @@ class GrammarRegistry { * * @param string $scopeName - The scope name (eg: text.html.php) of the grammar that is being set * @param dW\Lit\Grammar - The grammar to be put into the registry - * @return bool */ - public static function set(string $scopeName, Grammar $grammar): bool { + public static function set(string $scopeName, Grammar $grammar) { self::$storage[$scopeName] = $grammar; - return true; } } \ No newline at end of file diff --git a/lib/Highlight.php b/lib/Highlight.php index b864e50..a3194f6 100644 --- a/lib/Highlight.php +++ b/lib/Highlight.php @@ -15,7 +15,7 @@ class Highlight { * @param string $data - The input data string. * @param string $scopeName - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data. * @param ?\DOMDocument $document = null - An existing DOMDocument to use as the owner document of the returned DOMElement; if omitted one will be created instead. - * @param string $encoding = 'windows-1252' - The encoding of the input data string; only used if a document wasn't provided in the previous parameter, otherwise it uses the encoding of the existing DOMDocument + * @param string $encoding = 'windows-1252' - The encoding of the input data string; only used if a document wasn't provided in the previous parameter, otherwise it uses the encoding of the existing DOMDocument; defaults to HTML standard default windows-1252 * @return \DOMElement */ public static function toElement(string $data, string $scopeName, ?\DOMDocument $document = null, string $encoding = 'windows-1252'): \DOMElement { @@ -78,7 +78,7 @@ class Highlight { * * @param string $data - The input data string * @param string $scopeName - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data - * @param string $encoding = 'windows-1252' - The encoding of the input data string + * @param string $encoding = 'windows-1252' - The encoding of the input data string; defaults to HTML standard default windows-1252 * @return string */ public static function toString(string $data, string $scopeName, string $encoding = 'windows-1252'): string {