TEXT   141
Crayon Language Files
Guest on 31st May 2022 02:07:28 AM


  1. # Crayon Language Files
  2.  
  3. By Aram Kocharyan
  4.  
  5. ## Known Elements
  6.  
  7. These are known, recognised and highlighted by Crayon. You can defined others, but if you want to highlight them, you must add your custom CSS class into a Theme file. The CSS classes are in square brackets, but have a "crayon-" prefix added to them to avoid conflicts.
  8.  
  9. * `COMMENT [c]`
  10. * `STRING [s]`
  11. * `PREPROCESSOR [p]`
  12. * `TAG [ta]`
  13. * `KEYWORD [k]`
  14.     * `STATEMENT [st]`
  15.     * `RESERVED [r]`
  16.     * `TYPE [t]`
  17.     * `MODIFIER [m]`
  18. * `IDENTIFIER [i]`
  19.     * `ENTITY [e]`
  20.     * `VARIABLE [v]`
  21. * `CONSTANT [cn]`
  22. * `OPERATOR [o]`
  23. * `SYMBOL [sy]`
  24. * `NOTATION [n]`
  25. * `FADED [f]`
  26. * `HTML_CHAR [h]`
  27.  
  28. ## Rules
  29.  
  30. ### Global
  31.  
  32. * Whitespace must be used to separate element names, css classes and regex
  33. * Must be defined on a single line
  34.  
  35. ### Elements
  36.  
  37. * Defined as `ELEMENT_NAME [css] REGEX` on a single line, in that order only
  38. * Names cannot contain whitespace (must match `[-_a-zA-Z]+[-_a-zA-Z0-9]*`).
  39. * When defining an unknown element, you can specify a fallback with a colon:
  40.     * e.g. `MAGIC_WORD:KEYWORD [mg] \bmagic|words|here\b`
  41.     * If the Theme doesn't support the '.mg' class, it will still highlight using the `KEYWORD` class from the Known Elements section.
  42.     * Add support for the '.mg' class by adding it at the bottom of the Theme CSS file, after the fallback
  43. * If duplicate exists, it replaces previous
  44.  
  45. ### CSS
  46.  
  47. * CSS classes are defined in [square brackets], they are optional.
  48. * No need to use '.' in class name. All characters are converted to lowercase and dots removed.
  49. * If you use a space, then two classes are applied to the element matches e.g. [first second]
  50. * If not specified, either default is used (if element is known), or element name is used
  51. * Class can be applied to multiple elements
  52. * Class should be valid: `[-_a-zA-Z]+[-_a-zA-Z0-9]*`
  53. * If class is invalid, element is still parsed, error reported
  54.  
  55. ### Regex
  56.  
  57. * Written as per normal, without delimiters or escaping
  58. * Applied in the order they appear in the file. If language has reserved keywords, these should be higher than variables
  59. * Whitespace around regex is ignored - only first character to last forms regex
  60. * If single space is intended, use \s to avoid conflict with whitespace used for separation e.g. `TEST [t] \s\s\shello`
  61.  
  62. ### Comments
  63.  
  64. * can be added to this file using `#`, `//` or `/* */`
  65. * `//`, `#` and `/*` must be the first non-whitespace characters on that line
  66. * The `*/` must be on a line by itself
  67.  
  68. ## Special Functions
  69.  
  70. * Written inside regex, replaced by their outputs when regex is parsed.
  71.  
  72. ### (?alt:file.txt)
  73.  
  74. * Import lines from a file and separate with alternation. e.g. `catdog|dog|cat`
  75. * File should list words from longest to shortest to avoid clashes
  76.  
  77. ### (?default) or (?default:element_name)
  78.  
  79. * Substitute regex with Default language's regex for that element, or a specific element given after a colon.
  80.  
  81. ### (?html:somechars)
  82.  
  83. * Convert somechars to html entities. e.g. `(?html:<>"'&)` becomes `&lt;&gt;&quot;&amp;`.
  84.  
  85. ## Aliases
  86.  
  87. The `aliases.txt` contains aliases in the following structure. They are case insensitive:
  88.  
  89.         Format: id alias1 alias2 ...
  90.         Example: c# cs csharp
  91.  
  92. Specifying the alias will use the original language, though it's recommended to use the original if manually specifying the language to reduce confusion and length.
  93.  
  94. ## Extensions
  95.  
  96. Crayon can autodetect a language when highlighting local or remote files with extensions. The `extensions.txt` file uses the following format:
  97.  
  98.         Format: ID EXTENSION1 EXTENSION2 ...
  99.         Example: python py pyw pyc pyo pyd
  100.  
  101. ## Delimiters
  102.  
  103. Certain languages have tags which separate content in that language with that of another. An example is PHP's `<?php ?>` tags and the `<script>` and `<style>` tags in XHTML and CSS. The `delimiters.txt` file contains regex to capture delimiters that allow code with  mixed highlighting. The format of these is:
  104.  
  105.         Format: id REGEX1 REGEX2 ...
  106.         Example: php <\?(?:php)?.*?\?\>

Raw Paste

Login or Register to edit or fork this paste. It's free.