Browse Source

Added documentation for Grammar to readme

main
Dustin Wilson 3 years ago
parent
commit
bf10cca1db
  1. 184
      README.md

184
README.md

@ -10,6 +10,38 @@ Lit is a multilanguage syntax highlighter written in PHP. It takes code as input
## Documentation ##
### dW\\Lit\\Grammar::__construct ###
Creates a new `dW\Lit\Grammar` object.
```php
public function dW\Lit\Grammar::__construct(?string $scopeName = null, ?array $patterns = null, ?string $name = null, ?array $injections = null, ?array $repository = null)
```
#### Parameters ####
In normal usage of the library the parameters won't be used (see `dW\Lit\Grammar::loadJSON` and examples below for more information), but they are listed below for completeness' sake.
***scopeName*** - The scope name of the grammar
***patterns*** - The list of patterns in the grammar
***name*** - A human-readable name for the grammar
***injections*** - The list of injections in the grammar
***repository*** - The list of repository items in the grammar
### dW\\Lit\\Grammar::loadJSON ###
Imports an Atom JSON grammar into the `dW\Lit\Grammar` object.
```php
public function dW\Lit\Grammar::loadJSON(string $filename)
```
#### Parameters ####
***filename*** - The JSON file to be imported
### dW\\Lit\\Highlight::toElement ###
Highlights incoming string data and outputs a PHP `DOMElement`.
@ -48,159 +80,11 @@ echo $element->ownerDocument->saveHTML($element);
This will produce:
<style>
body {
line-height: 1.6;
font-size: 16px;
}
pre.highlighted {
background-color: #414452;
color: #f5f3f2
}
pre.highlighted .comment, pre.highlighted .comment .punctuation {
color: #898a92
}
pre.highlighted .constant {
color: #ffae71
}
pre.highlighted .constant.character.escape {
color: #b0d5d1
}
pre.highlighted .constant.numeric {
color: #ffae71
}
pre.highlighted .constant.other.color {
color: #b0d5d1
}
pre.highlighted .constant.other.symbol {
color: #ccd479
}
pre.highlighted .entity.name.class,pre.highlighted .entity.name.namespace {
color: #f2c784
}
pre.highlighted .entity.name.function,pre.highlighted .entity.name.section {
color: #88d8fa
}
pre.highlighted .entity.name.tag {
color: #ffb0a2
}
pre.highlighted .entity.name.type.class {
color: #f2c784
}
pre.highlighted .entity.other.attribute-name {
color: #d9c6ea
}
pre.highlighted .entity.other.attribute-name.id {
color: #88d8fa
}
pre.highlighted .entity.other.inherited-class {
color: #ccd479
}
pre.highlighted .invalid.illegal {
color: #414452;
background-color: #ffb0a2
}
pre.highlighted .keyword {
color: #d9c6ea
}
pre.highlighted .keyword.arithmetic {
color: #f5f3f2
}
pre.highlighted .keyword.other.special-method {
color: #88d8fa
}
pre.highlighted .keyword.other.unit {
color: #ffae71
}
pre.highlighted .markup.bold {
font-weight: 700;
color: #f2c784
}
pre.highlighted .markup.changed {
color: #d9c6ea
}
pre.highlighted .markup.deleted {
color: #ffb0a2
}
pre.highlighted .markup.heading {
color: #88d8fa
}
pre.highlighted .markup.inserted {
color: #ccd479
}
pre.highlighted .markup.italic {
font-style: italic;
color: #d9c6ea
}
pre.highlighted .markup.list {
color: #ffb0a2
}
pre.highlighted .markup.quote {
color: #ffae71
}
pre.highlighted .markup.raw.inline {
color: #ccd479
}
pre.highlighted .meta.class {
color: #f5f3f2
}
pre.highlighted .meta.link {
color: #ffae71
}
pre.highlighted .meta.require {
color: #88d8fa
}
pre.highlighted .meta.selector {
color: #d9c6ea
}
pre.highlighted .meta.separator {
color: #f5f3f2;
background-color: #adadb2
}
pre.highlighted .meta .support.type.property-name,pre.highlighted .meta.property-name {
color: #f2c784
}
pre.highlighted .none, pre.highlighted .punctuation {
color: #f5f3f2
}
pre.highlighted .storage {
color: #d9c6ea
}
pre.highlighted .string {
color: #ccd479
}
pre.highlighted .string.other.link {
color: #ffb0a2
}
pre.highlighted .string.regexp {
color: #b0d5d1
}
pre.highlighted .string .variable {
color: #ffbd91
}
pre.highlighted .support.class, pre.highlighted .support.namespace {
color: #f2c784
}
pre.highlighted .support.function,pre.highlighted .support.type {
color: #b0d5d1
}
pre.highlighted .support.function.any-method {
color: #88d8fa
}
pre.highlighted .variable {
color: #ffb0a2
}
pre.highlighted .variable.interpolation {
color: #ffbd91
}
pre.highlighted .variable.parameter.function {
color: #f5f3f2
}
</style>
```html
<pre class="highlighted"><code class="text html php"><span class="meta embedded block php"><span class="punctuation section embedded begin php">&lt;?php</span><span class="source php">
<span class="support function construct output php">echo</span> <span class="string quoted double php"><span class="punctuation definition string begin php">"</span>OOK!<span class="punctuation definition string end php">"</span></span><span class="punctuation terminator expression php">;</span>
</span><span class="punctuation section embedded end php"><span class="source php">?</span>&gt;</span></span></code></pre>
```
An existing `DOMDocument` may be used as the owner document of the returned `pre` element:

Loading…
Cancel
Save