@docusaurus/theme-classic 0.0.0-4951 → 0.0.0-4954

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -219,7 +219,7 @@ declare module '@theme/CodeBlock/Line' {
219
219
 
220
220
  export interface Props {
221
221
  readonly line: Token[];
222
- readonly highlight: boolean;
222
+ readonly classNames: string[] | undefined;
223
223
  readonly showLineNumbers: boolean;
224
224
  readonly getLineProps: GetLineProps;
225
225
  readonly getTokenProps: GetTokenProps;
@@ -19,11 +19,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
  * LICENSE file in the root directory of this source tree.
20
20
  */
21
21
  const DEFAULT_DOCS_CONFIG = {
22
- versionPersistence: 'localStorage'
22
+ versionPersistence: 'localStorage',
23
+ sidebar: {
24
+ hideable: false,
25
+ autoCollapseCategories: false
26
+ }
23
27
  };
24
28
 
25
29
  const DocsSchema = _utilsValidation.Joi.object({
26
- versionPersistence: _utilsValidation.Joi.string().equal('localStorage', 'none').default(DEFAULT_DOCS_CONFIG.versionPersistence)
30
+ versionPersistence: _utilsValidation.Joi.string().equal('localStorage', 'none').default(DEFAULT_DOCS_CONFIG.versionPersistence),
31
+ sidebar: _utilsValidation.Joi.object({
32
+ hideable: _utilsValidation.Joi.bool().default(DEFAULT_DOCS_CONFIG.sidebar.hideable),
33
+ autoCollapseCategories: _utilsValidation.Joi.bool().default(DEFAULT_DOCS_CONFIG.sidebar.autoCollapseCategories)
34
+ }).default(DEFAULT_DOCS_CONFIG.sidebar)
27
35
  }).default(DEFAULT_DOCS_CONFIG);
28
36
 
29
37
  const DEFAULT_COLOR_MODE_CONFIG = {
@@ -37,14 +45,20 @@ const DEFAULT_CONFIG = {
37
45
  metadata: [],
38
46
  prism: {
39
47
  additionalLanguages: [],
40
- theme: _palenight.default
48
+ theme: _palenight.default,
49
+ magicComments: [{
50
+ className: 'theme-code-block-highlighted-line',
51
+ line: 'highlight-next-line',
52
+ block: {
53
+ start: 'highlight-start',
54
+ end: 'highlight-end'
55
+ }
56
+ }]
41
57
  },
42
58
  navbar: {
43
59
  hideOnScroll: false,
44
60
  items: []
45
61
  },
46
- hideableSidebar: false,
47
- autoCollapseSidebarCategories: false,
48
62
  tableOfContents: {
49
63
  minHeadingLevel: 2,
50
64
  maxHeadingLevel: 3
@@ -314,10 +328,22 @@ const ThemeConfigSchema = _utilsValidation.Joi.object({
314
328
  styles: _utilsValidation.Joi.alternatives().try(_utilsValidation.Joi.array(), _utilsValidation.Joi.object()).required()
315
329
  }),
316
330
  defaultLanguage: _utilsValidation.Joi.string(),
317
- additionalLanguages: _utilsValidation.Joi.array().items(_utilsValidation.Joi.string()).default(DEFAULT_CONFIG.prism.additionalLanguages)
331
+ additionalLanguages: _utilsValidation.Joi.array().items(_utilsValidation.Joi.string()).default(DEFAULT_CONFIG.prism.additionalLanguages),
332
+ magicComments: _utilsValidation.Joi.array().items(_utilsValidation.Joi.object({
333
+ className: _utilsValidation.Joi.string().required(),
334
+ line: _utilsValidation.Joi.string(),
335
+ block: _utilsValidation.Joi.object({
336
+ start: _utilsValidation.Joi.string().required(),
337
+ end: _utilsValidation.Joi.string().required()
338
+ })
339
+ }).or('line', 'block')).default(DEFAULT_CONFIG.prism.magicComments)
318
340
  }).default(DEFAULT_CONFIG.prism).unknown(),
319
- hideableSidebar: _utilsValidation.Joi.bool().default(DEFAULT_CONFIG.hideableSidebar),
320
- autoCollapseSidebarCategories: _utilsValidation.Joi.bool().default(DEFAULT_CONFIG.autoCollapseSidebarCategories),
341
+ hideableSidebar: _utilsValidation.Joi.forbidden().messages({
342
+ 'any.unknown': 'themeConfig.hideableSidebar has been moved to themeConfig.docs.sidebar.hideable.'
343
+ }),
344
+ autoCollapseSidebarCategories: _utilsValidation.Joi.forbidden().messages({
345
+ 'any.unknown': 'themeConfig.autoCollapseSidebarCategories has been moved to themeConfig.docs.sidebar.autoCollapseCategories.'
346
+ }),
321
347
  sidebarCollapsible: _utilsValidation.Joi.forbidden().messages({
322
348
  'any.unknown': 'The themeConfig.sidebarCollapsible has been moved to docs plugin options. See: https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs'
323
349
  }),
@@ -30,7 +30,7 @@ export default function CodeBlockString({
30
30
  language: languageProp,
31
31
  }) {
32
32
  const {
33
- prism: {defaultLanguage},
33
+ prism: {defaultLanguage, magicComments},
34
34
  } = useThemeConfig();
35
35
  const language =
36
36
  languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage;
@@ -40,7 +40,11 @@ export default function CodeBlockString({
40
40
  // "title=\"xyz\"" => title: "\"xyz\""
41
41
 
42
42
  const title = parseCodeBlockTitle(metastring) || titleProp;
43
- const {highlightLines, code} = parseLines(children, metastring, language);
43
+ const {lineClassNames, code} = parseLines(children, {
44
+ metastring,
45
+ language,
46
+ magicComments,
47
+ });
44
48
  const showLineNumbers =
45
49
  showLineNumbersProp || containsLineNumbers(metastring);
46
50
  return (
@@ -76,7 +80,7 @@ export default function CodeBlockString({
76
80
  line={line}
77
81
  getLineProps={getLineProps}
78
82
  getTokenProps={getTokenProps}
79
- highlight={highlightLines.includes(i)}
83
+ classNames={lineClassNames[i]}
80
84
  showLineNumbers={showLineNumbers}
81
85
  />
82
86
  ))}
@@ -9,7 +9,7 @@ import clsx from 'clsx';
9
9
  import styles from './styles.module.css';
10
10
  export default function CodeBlockLine({
11
11
  line,
12
- highlight,
12
+ classNames,
13
13
  showLineNumbers,
14
14
  getLineProps,
15
15
  getTokenProps,
@@ -20,19 +20,8 @@ export default function CodeBlockLine({
20
20
 
21
21
  const lineProps = getLineProps({
22
22
  line,
23
- ...(showLineNumbers && {
24
- className: styles.codeLine,
25
- }),
23
+ className: clsx(classNames, showLineNumbers && styles.codeLine),
26
24
  });
27
-
28
- if (highlight) {
29
- lineProps.className = clsx(
30
- lineProps.className,
31
- styles.highlightedCodeLine,
32
- 'theme-code-block-highlighted-line',
33
- );
34
- }
35
-
36
25
  const lineTokens = line.map((token, key) => (
37
26
  <span
38
27
  key={key}
@@ -5,6 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ :global(.theme-code-block-highlighted-line) {
9
+ background-color: var(--docusaurus-highlighted-code-line-bg);
10
+ display: block;
11
+ margin: 0 calc(-1 * var(--ifm-pre-padding));
12
+ padding: 0 var(--ifm-pre-padding);
13
+ }
14
+
8
15
  /* Intentionally has zero specificity, so that to be able to override
9
16
  the background in custom CSS file due bug https://github.com/facebook/docusaurus/issues/3678 */
10
17
  :where(:root) {
@@ -15,13 +22,6 @@ the background in custom CSS file due bug https://github.com/facebook/docusaurus
15
22
  --docusaurus-highlighted-code-line-bg: rgb(100 100 100);
16
23
  }
17
24
 
18
- .highlightedCodeLine {
19
- background-color: var(--docusaurus-highlighted-code-line-bg);
20
- display: block;
21
- margin: 0 calc(-1 * var(--ifm-pre-padding));
22
- padding: 0 var(--ifm-pre-padding);
23
- }
24
-
25
25
  .codeLine {
26
26
  display: table-row;
27
27
  counter-increment: line-count;
@@ -15,7 +15,9 @@ import styles from './styles.module.css';
15
15
  function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
16
16
  const {
17
17
  navbar: {hideOnScroll},
18
- hideableSidebar,
18
+ docs: {
19
+ sidebar: {hideable},
20
+ },
19
21
  } = useThemeConfig();
20
22
  return (
21
23
  <div
@@ -26,7 +28,7 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
26
28
  )}>
27
29
  {hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
28
30
  <Content path={path} sidebar={sidebar} />
29
- {hideableSidebar && <CollapseButton onClick={onCollapse} />}
31
+ {hideable && <CollapseButton onClick={onCollapse} />}
30
32
  </div>
31
33
  );
32
34
  }
@@ -114,23 +114,21 @@ export default function DocSidebarItemCategory({
114
114
  setCollapsed(toCollapsed);
115
115
  }
116
116
 
117
- const {autoCollapseSidebarCategories} = useThemeConfig();
117
+ const {
118
+ docs: {
119
+ sidebar: {autoCollapseCategories},
120
+ },
121
+ } = useThemeConfig();
118
122
  useEffect(() => {
119
123
  if (
120
124
  collapsible &&
121
125
  expandedItem &&
122
126
  expandedItem !== index &&
123
- autoCollapseSidebarCategories
127
+ autoCollapseCategories
124
128
  ) {
125
129
  setCollapsed(true);
126
130
  }
127
- }, [
128
- collapsible,
129
- expandedItem,
130
- index,
131
- setCollapsed,
132
- autoCollapseSidebarCategories,
133
- ]);
131
+ }, [collapsible, expandedItem, index, setCollapsed, autoCollapseCategories]);
134
132
  return (
135
133
  <li
136
134
  className={clsx(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4951",
3
+ "version": "0.0.0-4954",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -21,15 +21,15 @@
21
21
  "format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
22
22
  },
23
23
  "dependencies": {
24
- "@docusaurus/core": "0.0.0-4951",
25
- "@docusaurus/plugin-content-blog": "0.0.0-4951",
26
- "@docusaurus/plugin-content-docs": "0.0.0-4951",
27
- "@docusaurus/plugin-content-pages": "0.0.0-4951",
28
- "@docusaurus/theme-common": "0.0.0-4951",
29
- "@docusaurus/theme-translations": "0.0.0-4951",
30
- "@docusaurus/utils": "0.0.0-4951",
31
- "@docusaurus/utils-common": "0.0.0-4951",
32
- "@docusaurus/utils-validation": "0.0.0-4951",
24
+ "@docusaurus/core": "0.0.0-4954",
25
+ "@docusaurus/plugin-content-blog": "0.0.0-4954",
26
+ "@docusaurus/plugin-content-docs": "0.0.0-4954",
27
+ "@docusaurus/plugin-content-pages": "0.0.0-4954",
28
+ "@docusaurus/theme-common": "0.0.0-4954",
29
+ "@docusaurus/theme-translations": "0.0.0-4954",
30
+ "@docusaurus/utils": "0.0.0-4954",
31
+ "@docusaurus/utils-common": "0.0.0-4954",
32
+ "@docusaurus/utils-validation": "0.0.0-4954",
33
33
  "@mdx-js/react": "^1.6.22",
34
34
  "clsx": "^1.1.1",
35
35
  "copy-text-to-clipboard": "^3.0.1",
@@ -46,8 +46,8 @@
46
46
  "@babel/cli": "^7.17.10",
47
47
  "@babel/core": "^7.17.10",
48
48
  "@babel/preset-typescript": "^7.16.7",
49
- "@docusaurus/module-type-aliases": "0.0.0-4951",
50
- "@docusaurus/types": "0.0.0-4951",
49
+ "@docusaurus/module-type-aliases": "0.0.0-4954",
50
+ "@docusaurus/types": "0.0.0-4954",
51
51
  "@types/mdx-js__react": "^1.5.5",
52
52
  "@types/nprogress": "^0.2.0",
53
53
  "@types/prismjs": "^1.26.0",
@@ -64,5 +64,5 @@
64
64
  "engines": {
65
65
  "node": ">=14"
66
66
  },
67
- "gitHead": "d3321f8bb35b07061d37fffea81392b0cd3b63ed"
67
+ "gitHead": "858b548c9cda08f8405325e1651c9f4234eabb34"
68
68
  }
@@ -34,7 +34,7 @@ export default function CodeBlockString({
34
34
  language: languageProp,
35
35
  }: Props): JSX.Element {
36
36
  const {
37
- prism: {defaultLanguage},
37
+ prism: {defaultLanguage, magicComments},
38
38
  } = useThemeConfig();
39
39
  const language =
40
40
  languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage;
@@ -46,7 +46,11 @@ export default function CodeBlockString({
46
46
  // "title=\"xyz\"" => title: "\"xyz\""
47
47
  const title = parseCodeBlockTitle(metastring) || titleProp;
48
48
 
49
- const {highlightLines, code} = parseLines(children, metastring, language);
49
+ const {lineClassNames, code} = parseLines(children, {
50
+ metastring,
51
+ language,
52
+ magicComments,
53
+ });
50
54
  const showLineNumbers =
51
55
  showLineNumbersProp || containsLineNumbers(metastring);
52
56
 
@@ -83,7 +87,7 @@ export default function CodeBlockString({
83
87
  line={line}
84
88
  getLineProps={getLineProps}
85
89
  getTokenProps={getTokenProps}
86
- highlight={highlightLines.includes(i)}
90
+ classNames={lineClassNames[i]}
87
91
  showLineNumbers={showLineNumbers}
88
92
  />
89
93
  ))}
@@ -12,7 +12,7 @@ import styles from './styles.module.css';
12
12
 
13
13
  export default function CodeBlockLine({
14
14
  line,
15
- highlight,
15
+ classNames,
16
16
  showLineNumbers,
17
17
  getLineProps,
18
18
  getTokenProps,
@@ -23,17 +23,9 @@ export default function CodeBlockLine({
23
23
 
24
24
  const lineProps = getLineProps({
25
25
  line,
26
- ...(showLineNumbers && {className: styles.codeLine}),
26
+ className: clsx(classNames, showLineNumbers && styles.codeLine),
27
27
  });
28
28
 
29
- if (highlight) {
30
- lineProps.className = clsx(
31
- lineProps.className,
32
- styles.highlightedCodeLine,
33
- 'theme-code-block-highlighted-line',
34
- );
35
- }
36
-
37
29
  const lineTokens = line.map((token, key) => (
38
30
  <span key={key} {...getTokenProps({token, key})} />
39
31
  ));
@@ -5,6 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ :global(.theme-code-block-highlighted-line) {
9
+ background-color: var(--docusaurus-highlighted-code-line-bg);
10
+ display: block;
11
+ margin: 0 calc(-1 * var(--ifm-pre-padding));
12
+ padding: 0 var(--ifm-pre-padding);
13
+ }
14
+
8
15
  /* Intentionally has zero specificity, so that to be able to override
9
16
  the background in custom CSS file due bug https://github.com/facebook/docusaurus/issues/3678 */
10
17
  :where(:root) {
@@ -15,13 +22,6 @@ the background in custom CSS file due bug https://github.com/facebook/docusaurus
15
22
  --docusaurus-highlighted-code-line-bg: rgb(100 100 100);
16
23
  }
17
24
 
18
- .highlightedCodeLine {
19
- background-color: var(--docusaurus-highlighted-code-line-bg);
20
- display: block;
21
- margin: 0 calc(-1 * var(--ifm-pre-padding));
22
- padding: 0 var(--ifm-pre-padding);
23
- }
24
-
25
25
  .codeLine {
26
26
  display: table-row;
27
27
  counter-increment: line-count;
@@ -18,7 +18,9 @@ import styles from './styles.module.css';
18
18
  function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}: Props) {
19
19
  const {
20
20
  navbar: {hideOnScroll},
21
- hideableSidebar,
21
+ docs: {
22
+ sidebar: {hideable},
23
+ },
22
24
  } = useThemeConfig();
23
25
 
24
26
  return (
@@ -30,7 +32,7 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}: Props) {
30
32
  )}>
31
33
  {hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
32
34
  <Content path={path} sidebar={sidebar} />
33
- {hideableSidebar && <CollapseButton onClick={onCollapse} />}
35
+ {hideable && <CollapseButton onClick={onCollapse} />}
34
36
  </div>
35
37
  );
36
38
  }
@@ -127,23 +127,21 @@ export default function DocSidebarItemCategory({
127
127
  setExpandedItem(toCollapsed ? null : index);
128
128
  setCollapsed(toCollapsed);
129
129
  }
130
- const {autoCollapseSidebarCategories} = useThemeConfig();
130
+ const {
131
+ docs: {
132
+ sidebar: {autoCollapseCategories},
133
+ },
134
+ } = useThemeConfig();
131
135
  useEffect(() => {
132
136
  if (
133
137
  collapsible &&
134
138
  expandedItem &&
135
139
  expandedItem !== index &&
136
- autoCollapseSidebarCategories
140
+ autoCollapseCategories
137
141
  ) {
138
142
  setCollapsed(true);
139
143
  }
140
- }, [
141
- collapsible,
142
- expandedItem,
143
- index,
144
- setCollapsed,
145
- autoCollapseSidebarCategories,
146
- ]);
144
+ }, [collapsible, expandedItem, index, setCollapsed, autoCollapseCategories]);
147
145
 
148
146
  return (
149
147
  <li
@@ -219,7 +219,7 @@ declare module '@theme/CodeBlock/Line' {
219
219
 
220
220
  export interface Props {
221
221
  readonly line: Token[];
222
- readonly highlight: boolean;
222
+ readonly classNames: string[] | undefined;
223
223
  readonly showLineNumbers: boolean;
224
224
  readonly getLineProps: GetLineProps;
225
225
  readonly getTokenProps: GetTokenProps;
@@ -14,11 +14,21 @@ import type {
14
14
 
15
15
  const DEFAULT_DOCS_CONFIG = {
16
16
  versionPersistence: 'localStorage',
17
+ sidebar: {
18
+ hideable: false,
19
+ autoCollapseCategories: false,
20
+ },
17
21
  };
18
22
  const DocsSchema = Joi.object({
19
23
  versionPersistence: Joi.string()
20
24
  .equal('localStorage', 'none')
21
25
  .default(DEFAULT_DOCS_CONFIG.versionPersistence),
26
+ sidebar: Joi.object({
27
+ hideable: Joi.bool().default(DEFAULT_DOCS_CONFIG.sidebar.hideable),
28
+ autoCollapseCategories: Joi.bool().default(
29
+ DEFAULT_DOCS_CONFIG.sidebar.autoCollapseCategories,
30
+ ),
31
+ }).default(DEFAULT_DOCS_CONFIG.sidebar),
22
32
  }).default(DEFAULT_DOCS_CONFIG);
23
33
 
24
34
  const DEFAULT_COLOR_MODE_CONFIG = {
@@ -34,13 +44,18 @@ export const DEFAULT_CONFIG = {
34
44
  prism: {
35
45
  additionalLanguages: [],
36
46
  theme: defaultPrismTheme,
47
+ magicComments: [
48
+ {
49
+ className: 'theme-code-block-highlighted-line',
50
+ line: 'highlight-next-line',
51
+ block: {start: 'highlight-start', end: 'highlight-end'},
52
+ },
53
+ ],
37
54
  },
38
55
  navbar: {
39
56
  hideOnScroll: false,
40
57
  items: [],
41
58
  },
42
- hideableSidebar: false,
43
- autoCollapseSidebarCategories: false,
44
59
  tableOfContents: {
45
60
  minHeadingLevel: 2,
46
61
  maxHeadingLevel: 3,
@@ -378,13 +393,29 @@ export const ThemeConfigSchema = Joi.object({
378
393
  additionalLanguages: Joi.array()
379
394
  .items(Joi.string())
380
395
  .default(DEFAULT_CONFIG.prism.additionalLanguages),
396
+ magicComments: Joi.array()
397
+ .items(
398
+ Joi.object({
399
+ className: Joi.string().required(),
400
+ line: Joi.string(),
401
+ block: Joi.object({
402
+ start: Joi.string().required(),
403
+ end: Joi.string().required(),
404
+ }),
405
+ }).or('line', 'block'),
406
+ )
407
+ .default(DEFAULT_CONFIG.prism.magicComments),
381
408
  })
382
409
  .default(DEFAULT_CONFIG.prism)
383
410
  .unknown(),
384
- hideableSidebar: Joi.bool().default(DEFAULT_CONFIG.hideableSidebar),
385
- autoCollapseSidebarCategories: Joi.bool().default(
386
- DEFAULT_CONFIG.autoCollapseSidebarCategories,
387
- ),
411
+ hideableSidebar: Joi.forbidden().messages({
412
+ 'any.unknown':
413
+ 'themeConfig.hideableSidebar has been moved to themeConfig.docs.sidebar.hideable.',
414
+ }),
415
+ autoCollapseSidebarCategories: Joi.forbidden().messages({
416
+ 'any.unknown':
417
+ 'themeConfig.autoCollapseSidebarCategories has been moved to themeConfig.docs.sidebar.autoCollapseCategories.',
418
+ }),
388
419
  sidebarCollapsible: Joi.forbidden().messages({
389
420
  'any.unknown':
390
421
  'The themeConfig.sidebarCollapsible has been moved to docs plugin options. See: https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs',