PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/assets/ckeditor/plugins/codesnippet/lib/highlight/README.md

https://gitlab.com/noosfero-themes/angular-theme
Markdown | 167 lines | 112 code | 55 blank | 0 comment | 0 complexity | 42a956d5c3ba32a3bdb3f3406af8575e MD5 | raw file
  1. # Highlight.js
  2. Highlight.js highlights syntax in code examples on blogs, forums and,
  3. in fact, on any web page. It's very easy to use because it works
  4. automatically: finds blocks of code, detects a language, highlights it.
  5. Autodetection can be fine tuned when it fails by itself (see "Heuristics").
  6. ## Basic usage
  7. Link the library and a stylesheet from your page and hook highlighting to
  8. the page load event:
  9. ```html
  10. <link rel="stylesheet" href="styles/default.css">
  11. <script src="highlight.pack.js"></script>
  12. <script>hljs.initHighlightingOnLoad();</script>
  13. ```
  14. This will highlight all code on the page marked up as `<pre><code> .. </code></pre>`.
  15. If you use different markup or need to apply highlighting dynamically, read
  16. "Custom initialization" below.
  17. - You can download your own customized version of "highlight.pack.js" or
  18. use the hosted one as described on the download page:
  19. <http://highlightjs.org/download/>
  20. - Style themes are available in the download package or as hosted files.
  21. To create a custom style for your site see the class reference in the file
  22. [CSS classes reference][cr] from the downloaded package.
  23. [cr]: http://highlightjs.readthedocs.org/en/latest/css-classes-reference.html
  24. ## node.js
  25. Highlight.js can be used under node.js. The package with all supported languages is
  26. installable from NPM:
  27. npm install highlight.js
  28. Alternatively, you can build it from the source with only languages you need:
  29. python3 tools/build.py -tnode lang1 lang2 ..
  30. Using the library:
  31. ```javascript
  32. var hljs = require('highlight.js');
  33. // If you know the language
  34. hljs.highlight(lang, code).value;
  35. // Automatic language detection
  36. hljs.highlightAuto(code).value;
  37. ```
  38. ## AMD
  39. Highlight.js can be used with an AMD loader. You will need to build it from
  40. source in order to do so:
  41. ```bash
  42. $ python3 tools/build.py -tamd lang1 lang2 ..
  43. ```
  44. Which will generate a `build/highlight.pack.js` which will load as an AMD
  45. module with support for the built languages and can be used like so:
  46. ```javascript
  47. require(["highlight.js/build/highlight.pack"], function(hljs){
  48. // If you know the language
  49. hljs.highlight(lang, code).value;
  50. // Automatic language detection
  51. hljs.highlightAuto(code).value;
  52. });
  53. ```
  54. ## Tab replacement
  55. You can replace TAB ('\x09') characters used for indentation in your code
  56. with some fixed number of spaces or with a `<span>` to give them special
  57. styling:
  58. ```html
  59. <script type="text/javascript">
  60. hljs.configure({tabReplace: ' '}); // 4 spaces
  61. // ... or
  62. hljs.configure({tabReplace: '<span class="indent">\t</span>'});
  63. hljs.initHighlightingOnLoad();
  64. </script>
  65. ```
  66. ## Custom initialization
  67. If you use different markup for code blocks you can initialize them manually
  68. with `highlightBlock(code)` function. It takes a DOM element containing the
  69. code to highlight and optionally a string with which to replace TAB
  70. characters.
  71. Initialization using, for example, jQuery might look like this:
  72. ```javascript
  73. $(document).ready(function() {
  74. $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
  75. });
  76. ```
  77. You can use `highlightBlock` to highlight blocks dynamically inserted into
  78. the page. Just make sure you don't do it twice for already highlighted
  79. blocks.
  80. If your code container relies on `<br>` tags instead of line breaks (i.e. if
  81. it's not `<pre>`) set the `useBR` option to `true`:
  82. ```javascript
  83. hljs.configure({useBR: true});
  84. $('div.code').each(function(i, e) {hljs.highlightBlock(e)});
  85. ```
  86. ## Heuristics
  87. Autodetection of a code's language is done using a simple heuristic:
  88. the program tries to highlight a fragment with all available languages and
  89. counts all syntactic structures that it finds along the way. The language
  90. with greatest count wins.
  91. This means that in short fragments the probability of an error is high
  92. (and it really happens sometimes). In this cases you can set the fragment's
  93. language explicitly by assigning a class to the `<code>` element:
  94. ```html
  95. <pre><code class="html">...</code></pre>
  96. ```
  97. You can use class names recommended in HTML5: "language-html",
  98. "language-php". Classes also can be assigned to the `<pre>` element.
  99. To disable highlighting of a fragment altogether use "no-highlight" class:
  100. ```html
  101. <pre><code class="no-highlight">...</code></pre>
  102. ```
  103. ## Export
  104. File export.html contains a little program that allows you to paste in a code
  105. snippet and then copy and paste the resulting HTML code generated by the
  106. highlighter. This is useful in situations when you can't use the script itself
  107. on a site.
  108. ## Meta
  109. - Version: 8.0
  110. - URL: http://highlightjs.org/
  111. For the license terms see LICENSE files.
  112. For authors and contributors see AUTHORS.en.txt file.