PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/static/js/highlight/README.md

https://gitlab.com/1851616111/toropress
Markdown | 143 lines | 97 code | 46 blank | 0 comment | 0 complexity | f6f60037f77ffb9ac7b00dc0aee00a14 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://softwaremaniacs.org/soft/highlight/en/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. [classref.txt][cr] from the downloaded package.
  23. [cr]: http://github.com/isagalaev/highlight.js/blob/master/classref.txt
  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. python 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. ## Tab replacement
  39. You can replace TAB ('\x09') characters used for indentation in your code
  40. with some fixed number of spaces or with a `<span>` to give them special
  41. styling:
  42. ```html
  43. <script type="text/javascript">
  44. hljs.tabReplace = ' '; // 4 spaces
  45. // ... or
  46. hljs.tabReplace = '<span class="indent">\t</span>';
  47. hljs.initHighlightingOnLoad();
  48. </script>
  49. ```
  50. ## Custom initialization
  51. If you use different markup for code blocks you can initialize them manually
  52. with `highlightBlock(code, tabReplace, useBR)` function. It takes a DOM element
  53. containing the code to highlight and optionally a string with which to replace
  54. TAB characters.
  55. Initialization using, for example, jQuery might look like this:
  56. ```javascript
  57. $(document).ready(function() {
  58. $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
  59. });
  60. ```
  61. You can use `highlightBlock` to highlight blocks dynamically inserted into
  62. the page. Just make sure you don't do it twice for already highlighted
  63. blocks.
  64. If your code container relies on `<br>` tags instead of line breaks (i.e. if
  65. it's not `<pre>`) pass `true` into the third parameter of `highlightBlock`
  66. to make highlight.js use `<br>` in the output:
  67. ```javascript
  68. $('div.code').each(function(i, e) {hljs.highlightBlock(e, null, true)});
  69. ```
  70. ## Heuristics
  71. Autodetection of a code's language is done using a simple heuristic:
  72. the program tries to highlight a fragment with all available languages and
  73. counts all syntactic structures that it finds along the way. The language
  74. with greatest count wins.
  75. This means that in short fragments the probability of an error is high
  76. (and it really happens sometimes). In this cases you can set the fragment's
  77. language explicitly by assigning a class to the `<code>` element:
  78. ```html
  79. <pre><code class="html">...</code></pre>
  80. ```
  81. You can use class names recommended in HTML5: "language-html",
  82. "language-php". Classes also can be assigned to the `<pre>` element.
  83. To disable highlighting of a fragment altogether use "no-highlight" class:
  84. ```html
  85. <pre><code class="no-highlight">...</code></pre>
  86. ```
  87. ## Export
  88. File export.html contains a little program that allows you to paste in a code
  89. snippet and then copy and paste the resulting HTML code generated by the
  90. highlighter. This is useful in situations when you can't use the script itself
  91. on a site.
  92. ## Meta
  93. - Version: 7.3
  94. - URL: http://softwaremaniacs.org/soft/highlight/en/
  95. - Author: Ivan Sagalaev (<maniac@softwaremaniacs.org>)
  96. For the license terms see LICENSE files.
  97. For the list of contributors see AUTHORS.en.txt file.