Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 7ddd2ea

Browse files
authored
Merge pull request #6 from ckeditor/t/3
Feature: Implemented the user interface of the highlight feature. Closes #3. Closes #4.
2 parents bd99f11 + 0705945 commit 7ddd2ea

33 files changed

+1395
-247
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
33
* For licensing, see LICENSE.md.
44
*/
55

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Software License Agreement
22
==========================
33

44
**CKEditor 5 Highlight Feature**https://github.com/ckeditor/ckeditor5-highlight <br>
5-
Copyright (c) 2003-2017, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
5+
Copyright (c) 2003-2018, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
66

77
Licensed under the terms of any of the following licenses at your choice:
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<style>
2+
.marker-yellow {
3+
background-color: #fdfd77;
4+
}
5+
6+
.marker-green {
7+
background-color: #63f963;
8+
}
9+
10+
.marker-pink {
11+
background-color: #fc7999;
12+
}
13+
14+
.marker-blue {
15+
background-color: #72cdfd;
16+
}
17+
18+
.pen-red {
19+
background-color: transparent;
20+
color: #e91313;
21+
}
22+
23+
.pen-green {
24+
background-color: transparent;
25+
color: #118800;
26+
}
27+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* globals window */
7+
8+
import ClassicEditor from '@ckeditor/ckeditor5-build-classic/src/ckeditor';
9+
10+
import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
11+
12+
ClassicEditor.build.plugins.push( Highlight );
13+
14+
window.ClassicEditor = ClassicEditor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div id="snippet-custom-highlight-options">
2+
<p>
3+
Here are defined highlighters: <mark class="marker-green">green one</mark> and <mark class="pen-red">red one</mark>.
4+
</p>
5+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* globals ClassicEditor, console, window, document */
7+
ClassicEditor
8+
.create( document.querySelector( '#snippet-custom-highlight-options' ), {
9+
toolbar: {
10+
items: [
11+
'headings', '|', 'bulletedList', 'numberedList', 'highlightDropdown', 'undo', 'redo'
12+
],
13+
viewportTopOffset: 60
14+
},
15+
highlight: {
16+
options: [
17+
{ model: 'greenMarker', class: 'marker-green', title: 'Green marker', color: '#66ff00', type: 'marker' },
18+
{ model: 'redPen', class: 'pen-red', title: 'Red pen', color: '#e91313', type: 'pen' },
19+
]
20+
}
21+
} )
22+
.then( editor => {
23+
window.editor = editor;
24+
} )
25+
.catch( err => {
26+
console.error( err.stack );
27+
} );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div id="snippet-highlight-buttons">
2+
<p>Highlight feature example.</p>
3+
<p>
4+
Here are some markers:
5+
</p>
6+
<ul>
7+
<li>the <mark class="marker-yellow">yellow</mark> one,</li>
8+
<li>the <mark class="marker-pink">pink</mark> one,</li>
9+
<li>the <mark class="marker-green">green</mark> one,</li>
10+
<li>the <mark class="marker-blue">blue</mark> one</li>
11+
</ul>
12+
<p>
13+
Here are some pens:
14+
<mark class="pen-red">red pen</mark> and <mark class="pen-green">green one</mark>.
15+
</p>
16+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* globals ClassicEditor, console, window, document */
7+
8+
ClassicEditor
9+
.create( document.querySelector( '#snippet-highlight-buttons' ), {
10+
toolbar: {
11+
items: [
12+
'headings', '|', 'highlight:marker', 'highlight:greenMarker', 'highlight:pinkMarker',
13+
'highlight:greenPen', 'highlight:redPen', 'removeHighlight', '|', 'undo', 'redo'
14+
],
15+
viewportTopOffset: 60
16+
}
17+
} )
18+
.then( editor => {
19+
window.editor = editor;
20+
} )
21+
.catch( err => {
22+
console.error( err.stack );
23+
} );
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div id="snippet-highlight">
2+
<p>Highlight feature example.</p>
3+
<p>
4+
Here are some markers:
5+
</p>
6+
<ul>
7+
<li>the <mark class="marker-yellow">yellow</mark> one,</li>
8+
<li>the <mark class="marker-pink">pink</mark> one,</li>
9+
<li>the <mark class="marker-green">green</mark> one,</li>
10+
<li>the <mark class="marker-blue">blue</mark> one</li>
11+
</ul>
12+
<p>
13+
Here are some pens:
14+
<mark class="pen-red">red pen</mark> and <mark class="pen-green">green one</mark>.
15+
</p>
16+
</div>

docs/_snippets/features/highlight.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* globals ClassicEditor, console, window, document */
7+
8+
ClassicEditor
9+
.create( document.querySelector( '#snippet-highlight' ), {
10+
toolbar: {
11+
items: [
12+
'headings', '|', 'bulletedList', 'numberedList', 'highlightDropdown', 'undo', 'redo'
13+
],
14+
viewportTopOffset: 60
15+
}
16+
} )
17+
.then( editor => {
18+
window.editor = editor;
19+
} )
20+
.catch( err => {
21+
console.error( err.stack );
22+
} );

docs/api/highlight.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
category: api-reference
3+
---
4+
5+
# CKEditor 5 highlight feature
6+
7+
[![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-highlight.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-highlight)
8+
9+
This package implements the highlight feature for CKEditor 5.
10+
11+
## Documentation
12+
13+
See the {@link features/highlight Highlight feature} guide and the {@link module:highlight/highlight~Highlight} plugin documentation.
14+
15+
## Installation
16+
17+
```bash
18+
npm install --save @ckeditor/ckeditor5-highlight
19+
```
20+
21+
## Contribute
22+
23+
The source code of this package is available on GitHub in https://github.com/ckeditor/ckeditor5-highlight.
24+
25+
## External links
26+
27+
* [`@ckeditor/ckeditor5-highlight` on npm](https://www.npmjs.com/package/@ckeditor/ckeditor5-highlight)
28+
* [`ckeditor/ckeditor5-highlight` on GitHub](https://github.com/ckeditor/ckeditor5-highlight)
29+
* [Issue tracker](https://github.com/ckeditor/ckeditor5-highlight/issues)
30+
* [Changelog](https://github.com/ckeditor/ckeditor5-highlight/blob/master/CHANGELOG.md)

docs/features/highlight.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: Highlight
3+
category: features
4+
---
5+
6+
{@snippet features/build-highlight-source}
7+
8+
The {@link module:highlight/highlight~Highlight} feature offers a text marking tools that help content authors speed up their work, e.g. reviewing content or marking it for the future reference. It uses inline `<marker>` elements in the view, supports both markers (background color) and pens (text color), and comes with a flexible configuration.
9+
10+
## Demo
11+
12+
{@snippet features/highlight}
13+
14+
## Configuring the highlight options
15+
16+
It is possible to configure which highlight options are supported by the editor.
17+
You can use the {@link module:highlight/highlight~HighlightConfig#options `highlight.options`} configuration and define your own highlight styles.
18+
19+
For example, the following editor supports only two styles (a green marker and a red pen):
20+
21+
```js
22+
ClassicEditor
23+
.create( document.querySelector( '#editor' ), {
24+
highlight: {
25+
options: [
26+
{
27+
model: 'greenMarker',
28+
class: 'marker-green',
29+
title: 'Green marker',
30+
color: '#63f963',
31+
type: 'marker'
32+
},
33+
{
34+
model: 'redPen',
35+
class: 'pen-red',
36+
title: 'Red pen',
37+
color: '#e91313',
38+
type: 'pen'
39+
}
40+
]
41+
},
42+
toolbar: [
43+
'headings', '|', 'bulletedList', 'numberedList', 'highlightDropdown', 'undo', 'redo'
44+
]
45+
} )
46+
.then( ... )
47+
.catch( ... );
48+
```
49+
50+
{@snippet features/custom-highlight-options}
51+
52+
Instead of using the (default) `highlightDropdown`, the feature also supports a configuration with separate buttons directly in the toolbar:
53+
54+
```js
55+
ClassicEditor
56+
.create( document.querySelector( '#editor' ), {
57+
toolbar: {
58+
items: [
59+
'headings', '|', 'highlight:marker', 'highlight:greenMarker',
60+
'highlight:pinkMarker', 'highlight:greenPen',
61+
'highlight:redPen', 'removeHighlight', 'undo', 'redo'
62+
]
63+
}
64+
} )
65+
.then( ... )
66+
.catch( ... );
67+
```
68+
69+
{@snippet features/highlight-buttons}
70+
71+
## Installation
72+
73+
To add this feature to your editor install the [`@ckeditor/ckeditor5-highlight`](https://www.npmjs.com/package/@ckeditor/ckeditor5-highlight) package:
74+
75+
```
76+
npm install --save @ckeditor/ckeditor5-highlight
77+
```
78+
79+
And add it to your plugin list and the toolbar configuration:
80+
81+
```js
82+
import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
83+
84+
ClassicEditor
85+
.create( document.querySelector( '#editor' ), {
86+
plugins: [ Highlight, ... ],
87+
toolbar: [ 'highlightDropdown', ... ]
88+
} )
89+
.then( ... )
90+
.catch( ... );
91+
```
92+
93+
<info-box info>
94+
Read more about {@link builds/guides/development/installing-plugins installing plugins}.
95+
</info-box>
96+
97+
## Common API
98+
99+
The {@link module:highlight/highlight~Highlight} plugin registers:
100+
101+
* The `'highlightDropdown'` dropdown,
102+
* The {@link module:highlight/highlightcommand~HighlightCommand `'highlight'`} command.
103+
104+
The number of options and their names correspond to the {@link module:highlight/highlight~HighlightConfig#options `highlight.options`} configuration option.
105+
106+
You can change the highlight of the current selection by executing the command with a desired value:
107+
108+
```js
109+
editor.execute( 'highlight', { value: 'yellowMarker' } );
110+
```
111+
112+
The `value` corresponds to the `model` property in configuration object. For the default configuration:
113+
```js
114+
highlight.options = [
115+
{ model: 'yellowMarker', class: 'marker-yellow', title: 'Yellow Marker', color: '#fdfd77', type: 'marker' },
116+
{ model: 'greenMarker', class: 'marker-green', title: 'Green marker', color: '#63f963', type: 'marker' },
117+
{ model: 'pinkMarker', class: 'marker-pink', title: 'Pink marker', color: '#fc7999', type: 'marker' },
118+
{ model: 'blueMarker', class: 'marker-blue', title: 'Blue marker', color: '#72cdfd', type: 'marker' },
119+
{ model: 'redPen', class: 'pen-red', title: 'Red pen', color: '#e91313', type: 'pen' },
120+
{ model: 'greenPen', class: 'pen-green', title: 'Green pen', color: '#118800', type: 'pen' }
121+
]
122+
```
123+
124+
the `highlight` command will accept the corresponding strings as values:
125+
- `'yellowMarker'` – available as a `'highlight:yellowMarker'` button,
126+
- `'greenMarker'` – available as a `'highlight:greenMarker'` button,
127+
- `'pinkMarker'` – available as a `'highlight:pinkMarker'` button,
128+
- `'blueMarker'` – available as a `'highlight:blueMarker'` button,
129+
- `'redPen'` – available as a `'highlight:redPen'` button,
130+
- `'greenPen'` – available as a `'highlight:greenPen'` button.
131+
132+
passing an empty `value` will remove any `highlight` from the selection:
133+
134+
```js
135+
editor.execute( 'highlight' );
136+
```
137+
138+
## Contribute
139+
140+
The source code of the feature is available on GitHub in https://github.com/ckeditor/ckeditor5-highlight.

package.json

+15-13
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
"ckeditor5-feature"
88
],
99
"dependencies": {
10-
"@ckeditor/ckeditor5-core": "^1.0.0-alpha.1",
11-
"@ckeditor/ckeditor5-engine": "^1.0.0-alpha.1",
12-
"@ckeditor/ckeditor5-ui": "^1.0.0-alpha.1"
10+
"@ckeditor/ckeditor5-core": "^1.0.0-alpha.2",
11+
"@ckeditor/ckeditor5-engine": "^1.0.0-alpha.2",
12+
"@ckeditor/ckeditor5-ui": "^1.0.0-alpha.2"
1313
},
1414
"devDependencies": {
15-
"@ckeditor/ckeditor5-block-quote": "^1.0.0-alpha.1",
16-
"@ckeditor/ckeditor5-enter": "^1.0.0-alpha.1",
17-
"@ckeditor/ckeditor5-heading": "^1.0.0-alpha.1",
18-
"@ckeditor/ckeditor5-image": "^1.0.0-alpha.1",
19-
"@ckeditor/ckeditor5-list": "^1.0.0-alpha.1",
20-
"@ckeditor/ckeditor5-paragraph": "^1.0.0-alpha.1",
21-
"@ckeditor/ckeditor5-typing": "^1.0.0-alpha.1",
22-
"eslint": "^4.8.0",
23-
"eslint-config-ckeditor5": "^1.0.6",
15+
"@ckeditor/ckeditor5-block-quote": "^1.0.0-alpha.2",
16+
"@ckeditor/ckeditor5-editor-classic": "^1.0.0-alpha.2",
17+
"@ckeditor/ckeditor5-enter": "^1.0.0-alpha.2",
18+
"@ckeditor/ckeditor5-heading": "^1.0.0-alpha.2",
19+
"@ckeditor/ckeditor5-image": "^1.0.0-alpha.2",
20+
"@ckeditor/ckeditor5-list": "^1.0.0-alpha.2",
21+
"@ckeditor/ckeditor5-paragraph": "^1.0.0-alpha.2",
22+
"@ckeditor/ckeditor5-typing": "^1.0.0-alpha.2",
23+
"@ckeditor/ckeditor5-utils": "^1.0.0-alpha.2",
24+
"eslint": "^4.15.0",
25+
"eslint-config-ckeditor5": "^1.0.7",
2426
"husky": "^0.14.3",
25-
"lint-staged": "^4.2.3"
27+
"lint-staged": "^6.0.0"
2628
},
2729
"engines": {
2830
"node": ">=6.0.0",

0 commit comments

Comments
 (0)