highlight.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module highlight/highlight
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import HighlightEditing from './highlightediting';
  10. import HighlightUI from './highlightui';
  11. /**
  12. * The highlight plugin.
  13. *
  14. * It loads the {@link module:highlight/highlightediting~HighlightEditing} and
  15. * {@link module:highlight/highlightui~HighlightUI} plugins.
  16. *
  17. * Read more about the feature in the {@glink api/highlight highlight package} page.
  18. *
  19. * @extends module:core/plugin~Plugin
  20. */
  21. export default class Highlight extends Plugin {
  22. /**
  23. * @inheritDoc
  24. */
  25. static get requires() {
  26. return [ HighlightEditing, HighlightUI ];
  27. }
  28. /**
  29. * @inheritDoc
  30. */
  31. static get pluginName() {
  32. return 'Highlight';
  33. }
  34. }
  35. /**
  36. * The highlight option descriptor. See the {@link module:highlight/highlight~HighlightConfig} to learn more.
  37. *
  38. * {
  39. * model: 'pinkMarker',
  40. * class: 'marker-pink',
  41. * title: 'Pink Marker',
  42. * color: 'var(--ck-highlight-marker-pink)',
  43. * type: 'marker'
  44. * }
  45. *
  46. * @typedef {Object} module:highlight/highlight~HighlightOption
  47. * @property {String} title The user-readable title of the option.
  48. * @property {String} model The unique attribute value in the model.
  49. * @property {String} color The CSS var() used for the highlighter. The color is used in the user interface to represent the highlighter.
  50. * There is possibility to use default color format like rgb, hex or hsl, but you need to care about color of `<mark>`
  51. * by adding CSS classes definition.
  52. * @property {String} class The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
  53. * @property {'marker'|'pen'} type The type of highlighter:
  54. * - `'marker'` – uses the `color` as a `background-color` style,
  55. * - `'pen'` – uses the `color` as a font `color` style.
  56. */
  57. /**
  58. * The configuration of the {@link module:highlight/highlight~Highlight} feature.
  59. *
  60. * Read more in {@link module:highlight/highlight~HighlightConfig}.
  61. *
  62. * @member {module:highlight/highlight~HighlightConfig} module:core/editor/editorconfig~EditorConfig#highlight
  63. */
  64. /**
  65. * The configuration of the {@link module:highlight/highlight~Highlight Highlight feature}.
  66. *
  67. * ClassicEditor
  68. * .create( editorElement, {
  69. * highlight: ... // Highlight feature config.
  70. * } )
  71. * .then( ... )
  72. * .catch( ... );
  73. *
  74. * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
  75. *
  76. * @interface HighlightConfig
  77. */
  78. /**
  79. * The available highlighters options. The default value is:
  80. *
  81. * options: [
  82. * {
  83. * model: 'yellowMarker',
  84. * class: 'marker-yellow',
  85. * title: 'Yellow marker',
  86. * color: 'var(--ck-highlight-marker-yellow)',
  87. * type: 'marker'
  88. * },
  89. * {
  90. * model: 'greenMarker',
  91. * class: 'marker-green',
  92. * title: 'Green marker',
  93. * color: 'var(--ck-highlight-marker-green)',
  94. * type: 'marker'
  95. * },
  96. * {
  97. * model: 'pinkMarker',
  98. * class: 'marker-pink',
  99. * title: 'Pink marker',
  100. * color: 'var(--ck-highlight-marker-pink)',
  101. * type: 'marker'
  102. * },
  103. * {
  104. * model: 'blueMarker',
  105. * class: 'marker-blue',
  106. * title: 'Blue marker',
  107. * color: 'var(--ck-highlight-marker-blue)',
  108. * type: 'marker'
  109. * },
  110. * {
  111. * model: 'redPen',
  112. * class: 'pen-red',
  113. * title: 'Red pen',
  114. * color: 'var(--ck-highlight-pen-red)',
  115. * type: 'pen'
  116. * },
  117. * {
  118. * model: 'greenPen',
  119. * class: 'pen-green',
  120. * title: 'Green pen',
  121. * color: 'var(--ck-highlight-pen-green)',
  122. * type: 'pen'
  123. * }
  124. * ]
  125. *
  126. * There are two types of highlighters available:
  127. * - `'marker'` - rendered as a `<mark>` element, styled with the `background-color`,
  128. * - `'pen'` - rendered as a `<mark>` element, styled with the font `color`.
  129. *
  130. * **Note**: The highlight feature provides a style sheet with the CSS classes and corresponding colors defined
  131. * as CSS variables.
  132. *
  133. * :root {
  134. * --ck-highlight-marker-yellow: #fdfd77;
  135. * --ck-highlight-marker-green: #63f963;
  136. * --ck-highlight-marker-pink: #fc7999;
  137. * --ck-highlight-marker-blue: #72cdfd;
  138. * --ck-highlight-pen-red: #e91313;
  139. * --ck-highlight-pen-green: #118800;
  140. * }
  141. *
  142. * .marker-yellow { ... }
  143. * .marker-green { ... }
  144. * .marker-pink { ... }
  145. * .marker-blue { ... }
  146. * .pen-red { ... }
  147. * .pen-green { ... }
  148. *
  149. * **Note**: It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
  150. * `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
  151. * the editor and the `<mark>` elements in the content must be styled by custom classes provided by
  152. * a dedicated style sheet.
  153. *
  154. * **Note**: It is recommended for the `color` property to correspond to the class in the content
  155. * style sheet because it represents the highlighter in the user interface of the editor.
  156. *
  157. * ClassicEditor
  158. * .create( editorElement, {
  159. * highlight: {
  160. * options: [
  161. * {
  162. * model: 'pinkMarker',
  163. * class: 'marker-pink',
  164. * title: 'Pink Marker',
  165. * color: 'var(--ck-highlight-marker-pink)',
  166. * type: 'marker'
  167. * },
  168. * {
  169. * model: 'redPen',
  170. * class: 'pen-red',
  171. * title: 'Red Pen',
  172. * color: 'var(--ck-highlight-pen-red)',
  173. * type: 'pen'
  174. * },
  175. * ]
  176. * }
  177. * } )
  178. * .then( ... )
  179. * .catch( ... );
  180. *
  181. * @member {Array.<module:highlight/highlight~HighlightOption>} module:highlight/highlight~HighlightConfig#options
  182. */