docs(v2): code block line highlighting (#1904)

* docs(v2): code block line highlighting

* misc: update CHANGELOG

* misc: respond to review

* docs: add line highlighting to the template
This commit is contained in:
Yangshun Tay 2019-10-29 14:59:24 +08:00 committed by GitHub
parent 7714afb00f
commit f635f9aba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 166 additions and 69 deletions

View file

@ -8,8 +8,8 @@
- Significantly reduce main bundle size and initial HTML payload on production build. Generated JS files from webpack is also shorter in name. - Significantly reduce main bundle size and initial HTML payload on production build. Generated JS files from webpack is also shorter in name.
- Refactor dark toggle into a hook. - Refactor dark toggle into a hook.
- Changed the way we read the `USE_SSH` env variable during deployment to be the same as in v1. - Changed the way we read the `USE_SSH` env variable during deployment to be the same as in v1.
- Add highlight specific lines in code blocks.
- Fix accessing `docs/` or `/docs/xxxx` that does not match any existing doc page should return 404 (Not found) page, not blank page. - Fix accessing `docs/` or `/docs/xxxx` that does not match any existing doc page should return 404 (Not found) page, not blank page.
- Added code block line highlighting feature (thanks @lex111)! If you have previously swizzled the `CodeBlock` theme component, it is recommended to update your source code to have this feature.
## 2.0.0-alpha.31 ## 2.0.0-alpha.31

View file

@ -110,6 +110,12 @@ No language indicated, so no syntax highlighting.
But let's throw in a <b>tag</b>. But let's throw in a <b>tag</b>.
``` ```
```js {2}
function highlightMe() {
console.log('This line can be highlighted!');
}
```
--- ---
## Tables ## Tables

View file

@ -21,3 +21,10 @@
--ifm-color-primary-lighter: rgb(102, 212, 189); --ifm-color-primary-lighter: rgb(102, 212, 189);
--ifm-color-primary-lightest: rgb(146, 224, 208); --ifm-color-primary-lightest: rgb(146, 224, 208);
} }
.docusaurus-highlight-code-line {
background-color: rgb(72, 77, 91);
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
}

View file

@ -31,6 +31,7 @@ export default ({children, className: languageClassName, metastring}) => {
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1]; const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0); highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
} }
useEffect(() => { useEffect(() => {
let clipboard; let clipboard;
@ -73,7 +74,7 @@ export default ({children, className: languageClassName, metastring}) => {
const lineProps = getLineProps({line, key: i}); const lineProps = getLineProps({line, key: i});
if (highlightLines.includes(i + 1)) { if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} highlight-line`; lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
} }
return ( return (

View file

@ -92,7 +92,7 @@ export default ({
const lineProps = getLineProps({line, key: i}); const lineProps = getLineProps({line, key: i});
if (highlightLines.includes(i + 1)) { if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} highlight-line`; lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
} }
return ( return (

View file

@ -19,10 +19,10 @@ To summarize:
## Writing customized Docusaurus themes ## Writing customized Docusaurus themes
A Docusaurus theme normally includes an `index.js` file where you hook up to the lifecycle methods, alongside with a `theme/` directory of components. A typical Docusaurus theme folder looks like this: A Docusaurus theme normally includes an `index.js` file where you hook up to the lifecycle methods, alongside with a `theme/` directory of components. A typical Docusaurus `theme` folder looks like this:
```shell ```shell {5-7}
. website
├── package.json ├── package.json
└── src └── src
├── index.js ├── index.js
@ -32,6 +32,7 @@ A Docusaurus theme normally includes an `index.js` file where you hook up to the
``` ```
There are two lifecycle methods that are essential to theme implementation: There are two lifecycle methods that are essential to theme implementation:
- [getThemePath](lifecycle-apis.md#getthemepath) - [getThemePath](lifecycle-apis.md#getthemepath)
- [getClientModules](lifecycle-apis.md#getclientmodules) - [getClientModules](lifecycle-apis.md#getclientmodules)

View file

@ -56,7 +56,7 @@ The only required field is `title`; however, we provide options to add author in
Use the `<!--truncate-->` marker in your blog post to represent what will be shown as the summary when viewing all published blog posts. Anything above `<!--truncate-->` will be part of the summary. For example: Use the `<!--truncate-->` marker in your blog post to represent what will be shown as the summary when viewing all published blog posts. Anything above `<!--truncate-->` will be part of the summary. For example:
```md ```md {9}
--- ---
title: Truncation Example title: Truncation Example
--- ---
@ -82,7 +82,7 @@ You can run your Docusaurus 2 site without a landing page and instead have your
**Note:** Make sure there's no `index.js` page in `src/pages` or else there will be two files mapping to the same route! **Note:** Make sure there's no `index.js` page in `src/pages` or else there will be two files mapping to the same route!
```js ```js {10}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ... // ...

View file

@ -36,8 +36,6 @@ It is recommended to check the [deployment docs](deployment.md) for more informa
### Themes, Plugins, and Presets configurations ### Themes, Plugins, and Presets configurations
_This section is a work in progress. [Welcoming PRs](https://github.com/facebook/docusaurus/issues/1640)._ _This section is a work in progress. [Welcoming PRs](https://github.com/facebook/docusaurus/issues/1640)._
<!-- <!--
@ -59,7 +57,7 @@ Docusaurus guards `docusaurus.config.js` from unknown fields. To add a custom fi
Example: Example:
```js ```js {3-6}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
customFields: { customFields: {
@ -75,7 +73,7 @@ Your configuration object will be made available to all the components of your s
Basic Example: Basic Example:
```jsx ```jsx {2,5-6}
import React from 'react'; import React from 'react';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

View file

@ -56,7 +56,7 @@ You may refer to GitHub Pages' documentation [User, Organization, and Project Pa
Example: Example:
```jsx ```jsx {3-6}
module.exports = { module.exports = {
... ...
url: 'https://endiliey.github.io', // Your website URL url: 'https://endiliey.github.io', // Your website URL
@ -102,7 +102,7 @@ References:
To deploy your Docusaurus 2 sites to [Netlify](https://www.netlify.com/), first make sure the following options are properly configured: To deploy your Docusaurus 2 sites to [Netlify](https://www.netlify.com/), first make sure the following options are properly configured:
```js ```js {3-4}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
url: 'https://docusaurus-2.netlify.com', // url to your site with no trailing slash url: 'https://docusaurus-2.netlify.com', // url to your site with no trailing slash

View file

@ -11,7 +11,7 @@ This reusable React component will manage all of your changes to the document he
Usage Example: Usage Example:
```jsx ```jsx {2,6,11}
import React from 'react'; import React from 'react';
import Head from '@docusaurus/Head'; import Head from '@docusaurus/Head';
@ -29,7 +29,7 @@ const MySEO = () => (
Nested or latter components will override duplicate usages: Nested or latter components will override duplicate usages:
```jsx ```jsx {2,5,8,11}
<Parent> <Parent>
<Head> <Head>
<title>My Title</title> <title>My Title</title>
@ -60,7 +60,7 @@ This component enables linking to internal pages as well as a powerful performan
The component is a wrapper around react-routers `<NavLink>` component that adds useful enhancements specific to Docusaurus. All props are passed through to react-routers `<NavLink>` component. The component is a wrapper around react-routers `<NavLink>` component that adds useful enhancements specific to Docusaurus. All props are passed through to react-routers `<NavLink>` component.
```jsx ```jsx {2,7}
import React from 'react'; import React from 'react';
import Link from '@docusaurus/Link'; import Link from '@docusaurus/Link';
@ -89,7 +89,7 @@ The target location to navigate to. Example: `/docs/introduction`.
The class to give the `<Link>` when it is active. The default given class is `active`. This will be joined with the `className` prop. The class to give the `<Link>` when it is active. The default given class is `active`. This will be joined with the `className` prop.
```jsx ```jsx {1}
<Link to="/faq" activeClassName="selected"> <Link to="/faq" activeClassName="selected">
FAQs FAQs
</Link> </Link>
@ -107,7 +107,7 @@ interface DocusaurusContext {
Usage example: Usage example:
```jsx ```jsx {2,5}
import React from 'react'; import React from 'react';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
@ -126,7 +126,7 @@ React Hook to automatically append `baseUrl` to a string automatically. This is
Example usage: Example usage:
```jsx ```jsx {3,11}
import React, {useEffect} from 'react'; import React, {useEffect} from 'react';
import Link from '@docusaurus/Link'; import Link from '@docusaurus/Link';
import useBaseUrl from '@docusaurus/useBaseUrl'; import useBaseUrl from '@docusaurus/useBaseUrl';

View file

@ -125,7 +125,7 @@ Example:
```js ```js
async postBuild({siteConfig = {}, routesPaths = [], outDir}) { async postBuild({siteConfig = {}, routesPaths = [], outDir}) {
// Print out to console all the rendered routes // Print out to console all the rendered routes
routesPaths.map(route => { routesPaths.map(route => {
console.log(route); console.log(route);
}) })
@ -157,8 +157,8 @@ If you use the folder directory above, your `getThemePath` can be:
```js ```js
// my-theme/src/index.js // my-theme/src/index.js
const path = require('path'); const path = require('path');
module.exports = function(context, options) { module.exports = function(context, options) {
return { return {
name: 'name-of-my-theme', name: 'name-of-my-theme',
@ -177,8 +177,8 @@ As an example, to make your theme load a `customCss` object from `options` passe
```js ```js
// my-theme/src/index.js // my-theme/src/index.js
const path = require('path'); const path = require('path');
module.exports = function(context, options) { module.exports = function(context, options) {
const {customCss} = options || {}; const {customCss} = options || {};
return { return {

View file

@ -120,7 +120,6 @@ keywords:
- docusaurus - docusaurus
image: https://i.imgur.com/mErPwqL.png image: https://i.imgur.com/mErPwqL.png
--- ---
``` ```
### Embedding React components ### Embedding React components
@ -202,13 +201,11 @@ Use the matching language meta string for your code block, and Docusaurus will p
console.log('Every repo must come with a mascot.'); console.log('Every repo must come with a mascot.');
``` ```
By default, the Prism [syntax highlighting theme](https://github.com/FormidableLabs/prism-react-renderer#theming) By default, the Prism [syntax highlighting theme](https://github.com/FormidableLabs/prism-react-renderer#theming) we use is [Palenight](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/themes/palenight.js). You can change this to another theme by passing `prismTheme` as `themeConfig` in your docusaurus.config.js.
we use is [Palenight](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/themes/palenight.js).
You can change this to another theme by passing `prismTheme` as `themeConfig` in your docusaurus.config.js.
For example, if you prefer to use the `dracula` highlighting theme: For example, if you prefer to use the `dracula` highlighting theme:
```js ```js {4}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
themeConfig: { themeConfig: {
@ -217,13 +214,9 @@ module.exports = {
}; };
``` ```
By default, Docusaurus comes with this subset of By default, Docusaurus comes with this subset of [commonly used languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js).
[commonly used languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js).
To add syntax highlighting for any of the other To add syntax highlighting for any of the other [Prism supported languages](https://prismjs.com/#supported-languages), install the `prismjs` npm package, then swizzle the `CodeBlock` component and add the desired language(s) there.
[Prism supported languages](https://prismjs.com/#supported-languages),
install the `prismjs` npm package, then swizzle the `CodeBlock`
component and add the desired language(s) there.
For example, if you want to add highlighting for the `powershell` language: For example, if you want to add highlighting for the `powershell` language:
@ -234,6 +227,72 @@ import Prism from 'prism-react-renderer/prism';
require('prismjs/components/prism-powershell'); require('prismjs/components/prism-powershell');
``` ```
### Line highlighting
You can bring emphasis to certain lines of code by specifying line ranges after the language meta string (leave a space after the language).
```jsx {3}
function HighlightSomeText(highlight) {
if (highlight) {
return 'This text is highlighted!';
}
return 'Nothing highlighted';
}
```
```jsx {3}
function HighlightSomeText(highlight) {
if (highlight) {
return 'This text is highlighted!';
}
return 'Nothing highlighted';
}
```
To accomplish this, Docusaurus adds the `docusaurus-highlight-code-line` class to the highlighted lines. You will need to define your own styling for this CSS, possibly in your `src/css/custom.css` with a custom background color which is dependent on your selected syntax highlighting theme. The color given below works for the default highlighting theme (Palenight), so if you are using another theme will have to tweak the color accordingly.
```css
/* /src/css/custom.css */
.docusaurus-highlight-code-line {
background-color: rgb(72, 77, 91);
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
}
```
To highlight multiple lines, separate the line numbers by commas or use the range syntax to select a chunk of lines. This feature uses the `parse-number-range` library and you can find [more syntax](<(https://www.npmjs.com/package/parse-numeric-range)>) on their project details.
```jsx {1,4-6,11}
import React from 'react';
function MyComponent(props) {
if (props.isBar) {
return <div>Bar</div>;
}
return <div>Foo</div>;
}
export default MyComponent;
```
```jsx {1,4-6,11}
import React from 'react';
function MyComponent(props) {
if (props.isBar) {
return <div>Bar</div>;
}
return <div>Foo</div>;
}
export default MyComponent;
```
### Interactive code editor ### Interactive code editor
(Powered by [React Live](https://github.com/FormidableLabs/react-live)) (Powered by [React Live](https://github.com/FormidableLabs/react-live))
@ -248,10 +307,10 @@ npm i @docusaurus/theme-live-codeblock
You will also need to add the plugin to your `docusaurus.config.js`. You will also need to add the plugin to your `docusaurus.config.js`.
```diff ```js {3}
module.exports = { module.exports = {
... ...
+ themes: ['@docusaurus/theme-live-codeblock'], themes: ['@docusaurus/theme-live-codeblock'],
... ...
} }
``` ```

View file

@ -49,13 +49,14 @@ Meanwhile, CLI commands are renamed to `docusaurus <command>` (instead of `docus
The `"scripts"` section of your `package.json` should be updated as follows: The `"scripts"` section of your `package.json` should be updated as follows:
```json ```json {3-6}
{ {
"scripts": { "scripts": {
"start": "docusaurus start", "start": "docusaurus start",
"build": "docusaurus build", "build": "docusaurus build",
"swizzle": "docusaurus swizzle", "swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy" "deploy": "docusaurus deploy"
...
} }
} }
``` ```
@ -125,7 +126,7 @@ No actions needed.
Deprecated. We wrote a custom CSS framework for Docusaurus 2 called Infima which uses CSS variables for theming. The docs are not quite ready yet and we will update here when it is. To overwrite Infima' CSS variables, create your own CSS file (e.g. `./src/css/custom.css`) and import it globally by passing it as an option to `@docusaurus/preset-classic`: Deprecated. We wrote a custom CSS framework for Docusaurus 2 called Infima which uses CSS variables for theming. The docs are not quite ready yet and we will update here when it is. To overwrite Infima' CSS variables, create your own CSS file (e.g. `./src/css/custom.css`) and import it globally by passing it as an option to `@docusaurus/preset-classic`:
```diff ```js {8-10}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ... // ...
@ -133,9 +134,9 @@ module.exports = {
[ [
'@docusaurus/preset-classic', '@docusaurus/preset-classic',
{ {
+ theme: { theme: {
+ customCss: require.resolve('./src/css/custom.css'), customCss: require.resolve('./src/css/custom.css'),
+ }, },
}, },
], ],
], ],
@ -168,6 +169,7 @@ Site meta info such as assets, SEO, copyright info are now handled by themes. To
```jsx ```jsx
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
themeConfig: { themeConfig: {
footer: { footer: {
logo: { logo: {
@ -179,7 +181,7 @@ module.exports = {
image: 'img/docusaurus.png', image: 'img/docusaurus.png',
// Equivalent to `docsSideNavCollapsible` // Equivalent to `docsSideNavCollapsible`
sidebarCollapsible: false, sidebarCollapsible: false,
... // ...
}, },
}; };
``` ```
@ -200,9 +202,10 @@ headerLinks: [
Now, these two fields are both handled by the theme: Now, these two fields are both handled by the theme:
```jsx ```jsx {7-20}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
themeConfig: { themeConfig: {
navbar: { navbar: {
title: 'Docusaurus', title: 'Docusaurus',
@ -221,23 +224,24 @@ module.exports = {
{to: 'blog', label: 'Blog', position: 'left'}, {to: 'blog', label: 'Blog', position: 'left'},
], ],
}, },
... // ...
}, },
}; };
``` ```
#### `algolia` #### `algolia`
```jsx ```jsx {5-9}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
themeConfig: { themeConfig: {
algolia: { algolia: {
apiKey: '47ecd3b21be71c5822571b9f59e52544', apiKey: '47ecd3b21be71c5822571b9f59e52544',
indexName: 'docusaurus-2', indexName: 'docusaurus-2',
algoliaOptions: { ... }, algoliaOptions: { ... },
}, },
... // ...
}, },
}; };
``` ```
@ -246,9 +250,10 @@ module.exports = {
Deprecated. Pass it as a blog option to `@docusaurus/preset-classic` instead: Deprecated. Pass it as a blog option to `@docusaurus/preset-classic` instead:
```jsx ```jsx {9}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
presets: [ presets: [
[ [
'@docusaurus/preset-classic', '@docusaurus/preset-classic',
@ -256,7 +261,7 @@ module.exports = {
blog: { blog: {
postsPerPage: 10, postsPerPage: 10,
}, },
... // ...
}, },
], ],
], ],
@ -271,9 +276,10 @@ Deprecated. Create a `CNAME` file in your `static` folder instead with your cust
Deprecated. Pass it as an option to `@docusaurus/preset-classic` docs instead: Deprecated. Pass it as an option to `@docusaurus/preset-classic` docs instead:
```jsx ```jsx {9-22}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
presets: [ presets: [
[ [
'@docusaurus/preset-classic', '@docusaurus/preset-classic',
@ -282,7 +288,8 @@ module.exports = {
// Equivalent to `customDocsPath`. // Equivalent to `customDocsPath`.
path: 'docs', path: 'docs',
// Equivalent to `editUrl` // Equivalent to `editUrl`
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/', editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/docs/',
// Equivalent to `docsUrl`. // Equivalent to `docsUrl`.
routeBasePath: 'docs', routeBasePath: 'docs',
// Remark and Rehype plugins passed to MDX. Replaces `markdownOptions` and `markdownPlugins`. // Remark and Rehype plugins passed to MDX. Replaces `markdownOptions` and `markdownPlugins`.
@ -293,7 +300,7 @@ module.exports = {
// Equivalent to `enableUpdateTime`. // Equivalent to `enableUpdateTime`.
showLastUpdateTime: true, showLastUpdateTime: true,
}, },
... // ...
}, },
], ],
], ],
@ -302,26 +309,30 @@ module.exports = {
#### `gaTrackingId` #### `gaTrackingId`
```jsx ```jsx {6}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
themeConfig: { themeConfig: {
googleAnalytics: { googleAnalytics: {
trackingID: 'UA-141789564-1', trackingID: 'UA-141789564-1',
}, },
// ...
}, },
}; };
``` ```
#### `gaGtag` #### `gaGtag`
```jsx ```jsx {6}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
themeConfig: { themeConfig: {
gtag: { gtag: {
trackingID: 'UA-141789564-1', trackingID: 'UA-141789564-1',
}, },
// ...
}, },
}; };
``` ```

View file

@ -15,20 +15,22 @@ npm install --save docusaurus-preset-name
Then, add it in your site's `docusaurus.config.js`'s `presets` option: Then, add it in your site's `docusaurus.config.js`'s `presets` option:
```jsx ```jsx {4}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
presets: ['@docusaurus/preset-xxxx'], presets: ['@docusaurus/preset-xxxx'],
}; };
``` ```
To load presets from your local directory, specify how to resolve them: To load presets from your local directory, specify how to resolve them:
```jsx ```jsx {6}
// docusaurus.config.js // docusaurus.config.js
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
// ...
presets: [path.resolve(__dirname, '/path/to/docusaurus-local-presets')], presets: [path.resolve(__dirname, '/path/to/docusaurus-local-presets')],
}; };
``` ```
@ -48,9 +50,10 @@ module.exports = function preset(context, opts = {}) {
then in your Docusaurus config, you may configure the preset instead: then in your Docusaurus config, you may configure the preset instead:
```jsx ```jsx {4}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
presets: ['@docusaurus/preset-a'], presets: ['@docusaurus/preset-a'],
}; };
``` ```

View file

@ -18,7 +18,7 @@ Algolia DocSearch works by crawling the content of your website every 24 hours a
To connect your docs with Algolia, add an `algolia` field in your `themeConfig`. Note that you will need algolia API key and algolia index. You can [apply for DocSearch here](https://community.algolia.com/docsearch/). To connect your docs with Algolia, add an `algolia` field in your `themeConfig`. Note that you will need algolia API key and algolia index. You can [apply for DocSearch here](https://community.algolia.com/docsearch/).
```jsx ```jsx {4-8}
// docusaurus.config.js // docusaurus.config.js
themeConfig: { themeConfig: {
// .... // ....

View file

@ -5,7 +5,7 @@ title: Sidebar
To generate a sidebar to your Docusaurus site, you need to define a file that exports a sidebar object and pass that into the `@docusaurus/plugin-docs` plugin directly or via `@docusaurus/preset-classic`. To generate a sidebar to your Docusaurus site, you need to define a file that exports a sidebar object and pass that into the `@docusaurus/plugin-docs` plugin directly or via `@docusaurus/preset-classic`.
```js ```js {9-10}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ... // ...
@ -83,8 +83,8 @@ For example, `greeting.md` id is `greeting` and `guide/hello.md` id is `guide/he
```bash ```bash
website # root directory of your site website # root directory of your site
── docs ── docs
   ── greeting.md    ── greeting.md
└── guide └── guide
└── hello.md └── hello.md
``` ```

View file

@ -8,7 +8,7 @@ description: A Docusaurus site is a pre-rendered single-page React application.
If you're using `@docusaurus/preset-classic`, you can create your own CSS files (e.g. `/src/css/custom.css`) and import them globally by passing it as an option into the preset. If you're using `@docusaurus/preset-classic`, you can create your own CSS files (e.g. `/src/css/custom.css`) and import them globally by passing it as an option into the preset.
```diff ```js {8-10}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ... // ...
@ -16,9 +16,9 @@ module.exports = {
[ [
'@docusaurus/preset-classic', '@docusaurus/preset-classic',
{ {
+ theme: { theme: {
+ customCss: require.resolve('./src/css/custom.css'), customCss: require.resolve('./src/css/custom.css'),
+ }, },
}, },
], ],
], ],

View file

@ -18,20 +18,22 @@ npm install --save docusaurus-plugin-name
Then you add it in your site's `docusaurus.config.js`'s `plugins` option: Then you add it in your site's `docusaurus.config.js`'s `plugins` option:
```jsx ```jsx {4}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
plugins: ['@docusaurus/plugin-content-pages'], plugins: ['@docusaurus/plugin-content-pages'],
}; };
``` ```
Docusaurus can also load plugins from your local directory, you can do something like the following: Docusaurus can also load plugins from your local directory, you can do something like the following:
```jsx ```jsx {6}
// docusaurus.config.js // docusaurus.config.js
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
// ...
plugins: [path.resolve(__dirname, '/path/to/docusaurus-local-plugin')], plugins: [path.resolve(__dirname, '/path/to/docusaurus-local-plugin')],
}; };
``` ```
@ -42,9 +44,10 @@ For the most basic usage of plugins, you can provide just the plugin name or the
However, plugins can have options specified by wrapping the name and an options object in an array inside your config. This style is usually called `Babel Style`. However, plugins can have options specified by wrapping the name and an options object in an array inside your config. This style is usually called `Babel Style`.
```js ```js {5-10}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
plugins: [ plugins: [
[ [
'@docusaurus/plugin-xxx', '@docusaurus/plugin-xxx',

View file

@ -10,9 +10,10 @@ Like plugins, themes are designed to add functionality to your Docusaurus site.
To use themes, specify the themes in your `docusaurus.config.js`. You may use multiple themes: To use themes, specify the themes in your `docusaurus.config.js`. You may use multiple themes:
```js ```js {4}
// docusaurus.config.js // docusaurus.config.js
module.exports = { module.exports = {
// ...
themes: ['@docusaurus/theme-classic', '@docusaurus/theme-live-codeblock'], themes: ['@docusaurus/theme-classic', '@docusaurus/theme-live-codeblock'],
}; };
``` ```
@ -60,7 +61,7 @@ For example, a Docusaurus blog consists of a blog plugin and a blog theme.
} }
``` ```
and if you want to use Bootstrap styling, you can swap out the theme with `theme-blog-bootstrap`: and if you want to use Bootstrap styling, you can swap out the theme with `theme-blog-bootstrap` (fictitious non-existing theme):
```js ```js
// docusaurus.config.js // docusaurus.config.js

View file

@ -31,3 +31,10 @@ html[data-theme='dark'] {
--ifm-font-size-base: 17px; --ifm-font-size-base: 17px;
} }
} }
.docusaurus-highlight-code-line {
background-color: rgb(72, 77, 91);
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
}