Skip to content

Commit 6330ffb

Browse files
authored
Merge pull request #1805 from ckeditor/t/773
Docs: Added an npm script docs:content-styles which build an editor with all plugins and save all occurrence of.ck-content class into a separate CSS file. Closes #773.
2 parents 0257460 + 65a56b6 commit 6330ffb

File tree

8 files changed

+549
-8
lines changed

8 files changed

+549
-8
lines changed
195 KB
Loading

docs/builds/guides/faq.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@ See the [relevant issue](https://github.com/ckeditor/ckeditor5/issues/592) on Gi
2222

2323
## What happened to the `contents.css` file? How do I style the content of the editor?
2424

25-
There is no such thing as the `contents.css` file because in CKEditor 5 features bring their own content styles, which are by default included in the JavaScript build and {@link framework/guides/theme-customization#styles-processing-and-bundling loaded by the style–loader} (they can be {@link builds/guides/integration/advanced-setup#option-extracting-css extracted}, too). It optimizes the size of the builds as the styles of unused features are simply excluded.
25+
There is no such thing as the `contents.css` file because in CKEditor 5 features bring their own content styles, which are by default included in the JavaScript build and {@link framework/guides/theme-customization#styles-processing-and-bundling loaded by the style–loader}. It optimizes the size of the builds as the styles of unused features are simply excluded.
2626

27-
Although some styles are provided by the features, it is up to the developers to make sure the content created by CKEditor 5 is properly styled, both in the front–end and in the back–end. To style the content in the editor (back–end), use the `.ck-content` CSS class:
28-
29-
```css
30-
.ck-content a {
31-
color: teal;
32-
}
33-
```
27+
You can get the full list of editor content styles in a {@link builds/guides/integration/content-styles dedicated guide}. You can also {@link builds/guides/integration/advanced-setup#option-extracting-css extract} all CSS brought by CKEditor 5 (content and UI) to a separate file when creating a custom editor build.
3428

3529
## The build I downloaded is missing some features. How do I add them?
3630

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
---
2+
# Scope:
3+
# * Explain what content styles are and how to use them.
4+
# * Offer developers a way to obtain editor content styles.
5+
6+
category: builds-integration
7+
order: 80
8+
---
9+
10+
# Content styles
11+
12+
Some of the {@link features/index core editor features} bring additional CSS to control the look of the content they produce. Take, for example, the {@link features/image Image feature} that needs special content styles to render images and their captions in the content. Or the {@link module:block-quote/blockquote~BlockQuote Block quote} plugin displays quotes in italic with a subtle border on the side.
13+
14+
{@img assets/img/builds-content-styles.png 823 Editor content styles.}
15+
16+
Content styles are bundled along with editor UI styles and, together with the JavaScript code of CKEditor 5, they create a monolithic structure called an {@link builds/guides/overview#available-builds editor build}. By default, content styles are inseparable from the rest of the editor which means there is no CSS file containing them you could take straight from the editor and use in your application (as opposed to the CKEditor 4 `contents.css` file). To get editor content styles, for instance, for the front–end of your application, you will have to take additional steps described in this guide.
17+
18+
## Sharing content styles between front–end and back–end
19+
20+
By default, content styles are loaded by the editor JavaScript which makes them only present when users edit their content and this, in turn, usually takes place in the back–end of an application. You want to use the same styles in the front–end, you may find yourself in a situation that requires you to load CKEditor just for that purpose, which is (performance–wise) not the best idea.
21+
22+
To avoid unnecessary dependencies in your front–end use a stylesheet with a complete list of CKEditor 5 content styles used by all editor features. There are two ways to obtain it:
23+
24+
* By taking it directly from [this guide](#the-full-list-of-content-styles) and saving it as a static resource in your application (e.g. `content-styles.css`) (**recommended**).
25+
* By generating it using a dedicated script. Learn more in the {@link framework/guides/contributing/development-environment#generating-content-styles "Development environment"} guide.
26+
27+
Load the `content-styles.css` file in your application by adding the following code to the template:
28+
29+
```html
30+
<link rel="stylesheet" href="path/to/assets/content-styles.css" type="text/css">
31+
```
32+
33+
The content in the front–end of your application should now look the same as when edited by the users.
34+
35+
<info-box warning>
36+
**Important!**
37+
38+
If you take a closer look at the content styles you may notice they all are prefixed by the `.ck-content` class selector. This narrows their scope when used in CKEditor so they do not affect the rest of the application. To use them in the front–end, **you will have to** add the `ck-content` CSS class to the container of your content. Otherwise styles will not apply.
39+
</info-box>
40+
41+
<info-box>
42+
If you are not afraid to get your hands dirty, you can always create a custom CKEditor 5 build from the source code with **all** the CSS (both UI and the content) extracted to a separate file. See how to do that in a {@link builds/guides/integration/advanced-setup#option-extracting-css dedicated guide}.
43+
</info-box>
44+
45+
## The full list of content styles
46+
47+
Below there is a full list of content styles used by editor features. You can copy it and use straight in your project. **Make sure to add the `ck-content` class to your content container for the styles to work** ([see above](#sharing-content-styles-between-frontend-and-backend)).
48+
49+
```css
50+
/*
51+
* CKEditor 5 (v12.3.1) content styles.
52+
* Generated on Tue, 06 Aug 2019 09:44:26 GMT.
53+
* For more information, check out https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/content-styles.html
54+
*/
55+
56+
:root {
57+
--ck-image-style-spacing: 1.5em;
58+
}
59+
60+
/* ckeditor5-image/theme/imagecaption.css */
61+
.ck-content .image > figcaption {
62+
display: table-caption;
63+
caption-side: bottom;
64+
word-break: break-word;
65+
color: hsl(0, 0%, 20%);
66+
background-color: hsl(0, 0%, 97%);
67+
padding: .6em;
68+
font-size: .75em;
69+
outline-offset: -1px;
70+
}
71+
/* ckeditor5-basic-styles/theme/code.css */
72+
.ck-content code {
73+
background-color: hsla(0, 0%, 78%, 0.3);
74+
padding: .15em;
75+
border-radius: 2px;
76+
}
77+
/* ckeditor5-table/theme/table.css */
78+
.ck-content .table {
79+
margin: 1em auto;
80+
display: table
81+
}
82+
/* ckeditor5-table/theme/table.css */
83+
.ck-content .table table {
84+
border-collapse: collapse;
85+
border-spacing: 0;
86+
border: 1px double hsl(0, 0%, 70%)
87+
}
88+
/* ckeditor5-table/theme/table.css */
89+
.ck-content .table table td,
90+
.ck-content .table table th {
91+
min-width: 2em;
92+
padding: .4em;
93+
border-color: hsl(0, 0%, 85%);
94+
}
95+
/* ckeditor5-table/theme/table.css */
96+
.ck-content .table table td,
97+
.ck-content .table table th {
98+
min-width: 2em;
99+
padding: .4em;
100+
border-color: hsl(0, 0%, 85%);
101+
}
102+
/* ckeditor5-table/theme/table.css */
103+
.ck-content .table table th {
104+
font-weight: bold;
105+
background: hsl(0, 0%, 98%);
106+
}
107+
/* ckeditor5-image/theme/image.css */
108+
.ck-content .image {
109+
display: table;
110+
clear: both;
111+
text-align: center;
112+
margin: 1em auto
113+
}
114+
/* ckeditor5-image/theme/image.css */
115+
.ck-content .image > img {
116+
display: block;
117+
margin: 0 auto;
118+
max-width: 100%;
119+
min-width: 50px;
120+
}
121+
/* ckeditor5-image/theme/imageuploadprogress.css */
122+
.ck-content .image {
123+
position: relative;
124+
overflow: hidden;
125+
}
126+
/* ckeditor5-image/theme/imageuploadprogress.css */
127+
.ck-content .image.ck-appear {
128+
animation: fadeIn 700ms;
129+
}
130+
/* ckeditor5-image/theme/imagestyle.css */
131+
.ck-content .image-style-side,
132+
.ck-content .image-style-align-left,
133+
.ck-content .image-style-align-center,
134+
.ck-content .image-style-align-right {
135+
max-width: 50%;
136+
}
137+
/* ckeditor5-image/theme/imagestyle.css */
138+
.ck-content .image-style-side,
139+
.ck-content .image-style-align-left,
140+
.ck-content .image-style-align-center,
141+
.ck-content .image-style-align-right {
142+
max-width: 50%;
143+
}
144+
/* ckeditor5-image/theme/imagestyle.css */
145+
.ck-content .image-style-side,
146+
.ck-content .image-style-align-left,
147+
.ck-content .image-style-align-center,
148+
.ck-content .image-style-align-right {
149+
max-width: 50%;
150+
}
151+
/* ckeditor5-image/theme/imagestyle.css */
152+
.ck-content .image-style-side,
153+
.ck-content .image-style-align-left,
154+
.ck-content .image-style-align-center,
155+
.ck-content .image-style-align-right {
156+
max-width: 50%;
157+
}
158+
/* ckeditor5-image/theme/imagestyle.css */
159+
.ck-content .image-style-side {
160+
float: right;
161+
margin-left: var(--ck-image-style-spacing);
162+
}
163+
/* ckeditor5-image/theme/imagestyle.css */
164+
.ck-content .image-style-align-left {
165+
float: left;
166+
margin-right: var(--ck-image-style-spacing);
167+
}
168+
/* ckeditor5-image/theme/imagestyle.css */
169+
.ck-content .image-style-align-center {
170+
margin-left: auto;
171+
margin-right: auto;
172+
}
173+
/* ckeditor5-image/theme/imagestyle.css */
174+
.ck-content .image-style-align-right {
175+
float: right;
176+
margin-left: var(--ck-image-style-spacing);
177+
}
178+
/* ckeditor5-block-quote/theme/blockquote.css */
179+
.ck-content blockquote {
180+
overflow: hidden;
181+
padding-right: 1.5em;
182+
padding-left: 1.5em;
183+
margin-left: 0;
184+
font-style: italic;
185+
border-left: solid 5px hsl(0, 0%, 80%);
186+
}
187+
/* ckeditor5-media-embed/theme/mediaembed.css */
188+
.ck-content .media {
189+
clear: both;
190+
margin: 1em 0;
191+
display: block;
192+
min-width: 15em;
193+
}
194+
```

docs/framework/guides/contributing/development-environment.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ Note: These arguments must be passed after additional `--`:
223223
yarn run docs --skip-api
224224
```
225225

226+
## Generating content styles
227+
228+
It is possible to generate a stylesheet containing content styles brought by all CKEditor 5 features. Execute `yarn docs:content-styles` and the stylesheet will be saved in the `build/content-styles` folder. To learn more, please refer to the {@link builds/guides/integration/content-styles "Content styles"} guide.
229+
226230
## Bisecting through a multi-repository
227231

228232
CKEditor 5 is a multi-repository project. It means that [`git bisect`](https://git-scm.com/docs/git-bisect) (which is super handy when tracking which commit introduced a bug) will not work out of the box.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"docs:api": "node ./scripts/docs/build-api-docs.js",
121121
"docs:build-and-publish": "node ./scripts/docs/build-and-publish.js",
122122
"docs:build-and-publish-nightly": "node ./scripts/docs/build-and-publish-nightly.js",
123+
"docs:content-styles": "node ./scripts/docs/build-content-styles.js",
123124
"translations:collect": "ckeditor5-dev-env-translations collect",
124125
"translations:download": "ckeditor5-dev-env-translations download",
125126
"translations:upload": "ckeditor5-dev-env-translations upload",

0 commit comments

Comments
 (0)