@atlaskit/code 15.3.0 → 15.4.0
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.
- package/CHANGELOG.md +17 -0
- package/__perf__/source-code-examples/100-line-example.tsx +1 -1
- package/dist/cjs/bidi-warning/ui/styled.js +1 -1
- package/dist/cjs/code-block.js +4 -1
- package/dist/cjs/code.js +8 -5
- package/dist/cjs/syntax-highlighter/lib/highlight.js +5 -2
- package/dist/cjs/syntax-highlighter/lib/process/index.js +4 -2
- package/dist/es2019/bidi-warning/ui/styled.js +1 -1
- package/dist/es2019/code-block.js +3 -1
- package/dist/es2019/code.js +8 -5
- package/dist/es2019/syntax-highlighter/lib/highlight.js +3 -1
- package/dist/es2019/syntax-highlighter/lib/process/index.js +3 -2
- package/dist/esm/bidi-warning/ui/styled.js +1 -1
- package/dist/esm/code-block.js +4 -1
- package/dist/esm/code.js +8 -5
- package/dist/esm/syntax-highlighter/lib/highlight.js +5 -2
- package/dist/esm/syntax-highlighter/lib/process/index.js +4 -2
- package/dist/types/internal/types.d.ts +5 -0
- package/dist/types/syntax-highlighter/lib/process/index.d.ts +2 -1
- package/dist/types/syntax-highlighter/types.d.ts +5 -0
- package/dist/types-ts4.5/internal/types.d.ts +5 -0
- package/dist/types-ts4.5/syntax-highlighter/lib/process/index.d.ts +2 -1
- package/dist/types-ts4.5/syntax-highlighter/types.d.ts +5 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/code
|
|
2
2
|
|
|
3
|
+
## 15.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#116950](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/116950)
|
|
8
|
+
[`c3908db22d486`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3908db22d486) -
|
|
9
|
+
CodeBlock supports a new `firstLineNumber` prop, which allows the starting line number to be set
|
|
10
|
+
(defaulting to 1).
|
|
11
|
+
|
|
12
|
+
## 15.3.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#116025](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/116025)
|
|
17
|
+
[`cd506a937e44f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cd506a937e44f) -
|
|
18
|
+
Internal change to how typography is applied. There should be no visual change.
|
|
19
|
+
|
|
3
20
|
## 15.3.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -16,8 +16,8 @@ const CSS_VAR_TEXT_COLOR = '--banner-text-color';
|
|
|
16
16
|
|
|
17
17
|
const textStyles = css({
|
|
18
18
|
color: \`var(\${CSS_VAR_TEXT_COLOR})\`,
|
|
19
|
+
font: token('font.body'),
|
|
19
20
|
fontWeight: token('font.weight.medium', '500'),
|
|
20
|
-
lineHeight: token('font.lineHeight.300', '24px'),
|
|
21
21
|
overflow: 'hidden',
|
|
22
22
|
textOverflow: 'ellipsis',
|
|
23
23
|
whiteSpace: 'nowrap',
|
|
@@ -33,7 +33,7 @@ var decoration = (0, _react2.css)({
|
|
|
33
33
|
background: "var(--ds-background-warning, ".concat(_colors.Y75, ")"),
|
|
34
34
|
color: "var(--ds-text-warning, #7F5F01)",
|
|
35
35
|
content: '"<"attr(data-bidi-character-code)">"',
|
|
36
|
-
fontSize:
|
|
36
|
+
fontSize: '14px',
|
|
37
37
|
fontStyle: 'normal',
|
|
38
38
|
lineHeight: '18px',
|
|
39
39
|
/**
|
package/dist/cjs/code-block.js
CHANGED
|
@@ -30,6 +30,8 @@ var _syntaxHighlighter = _interopRequireDefault(require("./syntax-highlighter"))
|
|
|
30
30
|
var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
|
|
31
31
|
var _ref$showLineNumbers = _ref.showLineNumbers,
|
|
32
32
|
showLineNumbers = _ref$showLineNumbers === void 0 ? true : _ref$showLineNumbers,
|
|
33
|
+
_ref$firstLineNumber = _ref.firstLineNumber,
|
|
34
|
+
firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
|
|
33
35
|
_ref$language = _ref.language,
|
|
34
36
|
providedLanguage = _ref$language === void 0 ? 'text' : _ref$language,
|
|
35
37
|
_ref$highlight = _ref.highlight,
|
|
@@ -47,7 +49,7 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
|
|
|
47
49
|
codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT,
|
|
48
50
|
_ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
|
|
49
51
|
shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
|
|
50
|
-
var numLines = (text || '').split('\n').length;
|
|
52
|
+
var numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
|
|
51
53
|
var theme = (0, _react.useMemo)(function () {
|
|
52
54
|
return (0, _styles.getCodeBlockTheme)(numLines);
|
|
53
55
|
}, [numLines]);
|
|
@@ -81,6 +83,7 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
|
|
|
81
83
|
language: languageToUse,
|
|
82
84
|
css: styles,
|
|
83
85
|
showLineNumbers: showLineNumbers,
|
|
86
|
+
firstLineNumber: firstLineNumber,
|
|
84
87
|
lineProps: getLineProps
|
|
85
88
|
// shouldCreateParentElementForLines is needed to pass down props to each line.
|
|
86
89
|
// This is necessary for both line highlighting and testId's, as each of
|
package/dist/cjs/code.js
CHANGED
|
@@ -53,11 +53,14 @@ var Code = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(fu
|
|
|
53
53
|
codeBidiWarningLabel: codeBidiWarningLabel,
|
|
54
54
|
codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
|
|
55
55
|
}, children) : children;
|
|
56
|
-
return (
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
return (
|
|
57
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
58
|
+
(0, _react2.jsx)("code", (0, _extends2.default)({
|
|
59
|
+
ref: ref,
|
|
60
|
+
"data-testid": testId,
|
|
61
|
+
css: styles
|
|
62
|
+
}, otherProps), decoratedChildren)
|
|
63
|
+
);
|
|
61
64
|
}));
|
|
62
65
|
function RenderCodeChildrenWithBidiWarnings(_ref2) {
|
|
63
66
|
var children = _ref2.children,
|
|
@@ -10,7 +10,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
10
10
|
var _react = require("react");
|
|
11
11
|
var _process = _interopRequireDefault(require("./process"));
|
|
12
12
|
var _reactRenderer = _interopRequireDefault(require("./react-renderer"));
|
|
13
|
-
var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
|
|
13
|
+
var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "firstLineNumber", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
|
|
14
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
16
|
/**
|
|
@@ -33,6 +33,8 @@ var Highlight = /*#__PURE__*/(0, _react.memo)(function Highlight(_ref) {
|
|
|
33
33
|
} : _ref$codeTagProps,
|
|
34
34
|
_ref$showLineNumbers = _ref.showLineNumbers,
|
|
35
35
|
showLineNumbers = _ref$showLineNumbers === void 0 ? false : _ref$showLineNumbers,
|
|
36
|
+
_ref$firstLineNumber = _ref.firstLineNumber,
|
|
37
|
+
firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
|
|
36
38
|
_ref$shouldCreatePare = _ref.shouldCreateParentElementForLines,
|
|
37
39
|
shouldCreateParentElementForLines = _ref$shouldCreatePare === void 0 ? false : _ref$shouldCreatePare,
|
|
38
40
|
_ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
|
|
@@ -76,7 +78,8 @@ var Highlight = /*#__PURE__*/(0, _react.memo)(function Highlight(_ref) {
|
|
|
76
78
|
language: language,
|
|
77
79
|
shouldCreateParentElementForLines: shouldCreateParentElementForLines || !!shouldWrapLongLines,
|
|
78
80
|
lineProps: lineProps,
|
|
79
|
-
showLineNumbers: showLineNumbers
|
|
81
|
+
showLineNumbers: showLineNumbers,
|
|
82
|
+
firstLineNumber: firstLineNumber
|
|
80
83
|
});
|
|
81
84
|
|
|
82
85
|
// Rows + logic into a renderer
|
|
@@ -25,9 +25,11 @@ function processLines(_ref) {
|
|
|
25
25
|
language = _ref.language,
|
|
26
26
|
shouldCreateParentElementForLines = _ref.shouldCreateParentElementForLines,
|
|
27
27
|
lineProps = _ref.lineProps,
|
|
28
|
-
showLineNumbers = _ref.showLineNumbers
|
|
28
|
+
showLineNumbers = _ref.showLineNumbers,
|
|
29
|
+
_ref$firstLineNumber = _ref.firstLineNumber,
|
|
30
|
+
firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber;
|
|
29
31
|
var codeTree = (0, _getCodeTree.default)(language, code, astGenerator);
|
|
30
|
-
var startingLineNumber = 1;
|
|
32
|
+
var startingLineNumber = firstLineNumber > 0 ? firstLineNumber : 1;
|
|
31
33
|
var createLine = (0, _createLine.default)(lineProps, shouldCreateParentElementForLines, showLineNumbers);
|
|
32
34
|
var newTree = [];
|
|
33
35
|
var lastLineBreakIndex = -1;
|
|
@@ -25,7 +25,7 @@ const decoration = css({
|
|
|
25
25
|
background: `var(--ds-background-warning, ${Y75})`,
|
|
26
26
|
color: "var(--ds-text-warning, #7F5F01)",
|
|
27
27
|
content: '"<"attr(data-bidi-character-code)">"',
|
|
28
|
-
fontSize:
|
|
28
|
+
fontSize: '14px',
|
|
29
29
|
fontStyle: 'normal',
|
|
30
30
|
lineHeight: '18px',
|
|
31
31
|
/**
|
|
@@ -22,6 +22,7 @@ import SyntaxHighlighter from './syntax-highlighter';
|
|
|
22
22
|
*/
|
|
23
23
|
const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
|
|
24
24
|
showLineNumbers = true,
|
|
25
|
+
firstLineNumber = 1,
|
|
25
26
|
language: providedLanguage = 'text',
|
|
26
27
|
highlight = '',
|
|
27
28
|
highlightedStartText = 'Highlight start',
|
|
@@ -33,7 +34,7 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
|
|
|
33
34
|
codeBidiWarningTooltipEnabled = true,
|
|
34
35
|
shouldWrapLongLines = false
|
|
35
36
|
}) {
|
|
36
|
-
const numLines = (text || '').split('\n').length;
|
|
37
|
+
const numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
|
|
37
38
|
const theme = useMemo(() => getCodeBlockTheme(numLines), [numLines]);
|
|
38
39
|
const getStyles = useMemo(() => getCodeBlockStyles(theme), [theme]);
|
|
39
40
|
const styles = useMemo(() => css(
|
|
@@ -58,6 +59,7 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
|
|
|
58
59
|
language: languageToUse,
|
|
59
60
|
css: styles,
|
|
60
61
|
showLineNumbers: showLineNumbers,
|
|
62
|
+
firstLineNumber: firstLineNumber,
|
|
61
63
|
lineProps: getLineProps
|
|
62
64
|
// shouldCreateParentElementForLines is needed to pass down props to each line.
|
|
63
65
|
// This is necessary for both line highlighting and testId's, as each of
|
package/dist/es2019/code.js
CHANGED
|
@@ -36,11 +36,14 @@ const Code = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Code({
|
|
|
36
36
|
codeBidiWarningLabel: codeBidiWarningLabel,
|
|
37
37
|
codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
|
|
38
38
|
}, children) : children;
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
return (
|
|
40
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
41
|
+
jsx("code", _extends({
|
|
42
|
+
ref: ref,
|
|
43
|
+
"data-testid": testId,
|
|
44
|
+
css: styles
|
|
45
|
+
}, otherProps), decoratedChildren)
|
|
46
|
+
);
|
|
44
47
|
}));
|
|
45
48
|
function RenderCodeChildrenWithBidiWarnings({
|
|
46
49
|
children,
|
|
@@ -18,6 +18,7 @@ const Highlight = /*#__PURE__*/memo(function Highlight({
|
|
|
18
18
|
className: `language-${language}`
|
|
19
19
|
},
|
|
20
20
|
showLineNumbers = false,
|
|
21
|
+
firstLineNumber = 1,
|
|
21
22
|
shouldCreateParentElementForLines = false,
|
|
22
23
|
shouldWrapLongLines = false,
|
|
23
24
|
lineProps = {},
|
|
@@ -59,7 +60,8 @@ const Highlight = /*#__PURE__*/memo(function Highlight({
|
|
|
59
60
|
language,
|
|
60
61
|
shouldCreateParentElementForLines: shouldCreateParentElementForLines || !!shouldWrapLongLines,
|
|
61
62
|
lineProps,
|
|
62
|
-
showLineNumbers
|
|
63
|
+
showLineNumbers,
|
|
64
|
+
firstLineNumber
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
// Rows + logic into a renderer
|
|
@@ -18,10 +18,11 @@ export default function processLines({
|
|
|
18
18
|
language,
|
|
19
19
|
shouldCreateParentElementForLines,
|
|
20
20
|
lineProps,
|
|
21
|
-
showLineNumbers
|
|
21
|
+
showLineNumbers,
|
|
22
|
+
firstLineNumber = 1
|
|
22
23
|
}) {
|
|
23
24
|
const codeTree = getCodeTree(language, code, astGenerator);
|
|
24
|
-
const startingLineNumber = 1;
|
|
25
|
+
const startingLineNumber = firstLineNumber > 0 ? firstLineNumber : 1;
|
|
25
26
|
const createLine = createLineGenerator(lineProps, shouldCreateParentElementForLines, showLineNumbers);
|
|
26
27
|
const newTree = [];
|
|
27
28
|
let lastLineBreakIndex = -1;
|
|
@@ -25,7 +25,7 @@ var decoration = css({
|
|
|
25
25
|
background: "var(--ds-background-warning, ".concat(Y75, ")"),
|
|
26
26
|
color: "var(--ds-text-warning, #7F5F01)",
|
|
27
27
|
content: '"<"attr(data-bidi-character-code)">"',
|
|
28
|
-
fontSize:
|
|
28
|
+
fontSize: '14px',
|
|
29
29
|
fontStyle: 'normal',
|
|
30
30
|
lineHeight: '18px',
|
|
31
31
|
/**
|
package/dist/esm/code-block.js
CHANGED
|
@@ -23,6 +23,8 @@ import SyntaxHighlighter from './syntax-highlighter';
|
|
|
23
23
|
var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
|
|
24
24
|
var _ref$showLineNumbers = _ref.showLineNumbers,
|
|
25
25
|
showLineNumbers = _ref$showLineNumbers === void 0 ? true : _ref$showLineNumbers,
|
|
26
|
+
_ref$firstLineNumber = _ref.firstLineNumber,
|
|
27
|
+
firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
|
|
26
28
|
_ref$language = _ref.language,
|
|
27
29
|
providedLanguage = _ref$language === void 0 ? 'text' : _ref$language,
|
|
28
30
|
_ref$highlight = _ref.highlight,
|
|
@@ -40,7 +42,7 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
|
|
|
40
42
|
codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT,
|
|
41
43
|
_ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
|
|
42
44
|
shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
|
|
43
|
-
var numLines = (text || '').split('\n').length;
|
|
45
|
+
var numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
|
|
44
46
|
var theme = useMemo(function () {
|
|
45
47
|
return getCodeBlockTheme(numLines);
|
|
46
48
|
}, [numLines]);
|
|
@@ -74,6 +76,7 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
|
|
|
74
76
|
language: languageToUse,
|
|
75
77
|
css: styles,
|
|
76
78
|
showLineNumbers: showLineNumbers,
|
|
79
|
+
firstLineNumber: firstLineNumber,
|
|
77
80
|
lineProps: getLineProps
|
|
78
81
|
// shouldCreateParentElementForLines is needed to pass down props to each line.
|
|
79
82
|
// This is necessary for both line highlighting and testId's, as each of
|
package/dist/esm/code.js
CHANGED
|
@@ -38,11 +38,14 @@ var Code = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Code(_ref, ref) {
|
|
|
38
38
|
codeBidiWarningLabel: codeBidiWarningLabel,
|
|
39
39
|
codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
|
|
40
40
|
}, children) : children;
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
return (
|
|
42
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
43
|
+
jsx("code", _extends({
|
|
44
|
+
ref: ref,
|
|
45
|
+
"data-testid": testId,
|
|
46
|
+
css: styles
|
|
47
|
+
}, otherProps), decoratedChildren)
|
|
48
|
+
);
|
|
46
49
|
}));
|
|
47
50
|
function RenderCodeChildrenWithBidiWarnings(_ref2) {
|
|
48
51
|
var children = _ref2.children,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
|
|
3
|
+
var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "firstLineNumber", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
6
|
import { memo } from 'react';
|
|
@@ -27,6 +27,8 @@ var Highlight = /*#__PURE__*/memo(function Highlight(_ref) {
|
|
|
27
27
|
} : _ref$codeTagProps,
|
|
28
28
|
_ref$showLineNumbers = _ref.showLineNumbers,
|
|
29
29
|
showLineNumbers = _ref$showLineNumbers === void 0 ? false : _ref$showLineNumbers,
|
|
30
|
+
_ref$firstLineNumber = _ref.firstLineNumber,
|
|
31
|
+
firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
|
|
30
32
|
_ref$shouldCreatePare = _ref.shouldCreateParentElementForLines,
|
|
31
33
|
shouldCreateParentElementForLines = _ref$shouldCreatePare === void 0 ? false : _ref$shouldCreatePare,
|
|
32
34
|
_ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
|
|
@@ -70,7 +72,8 @@ var Highlight = /*#__PURE__*/memo(function Highlight(_ref) {
|
|
|
70
72
|
language: language,
|
|
71
73
|
shouldCreateParentElementForLines: shouldCreateParentElementForLines || !!shouldWrapLongLines,
|
|
72
74
|
lineProps: lineProps,
|
|
73
|
-
showLineNumbers: showLineNumbers
|
|
75
|
+
showLineNumbers: showLineNumbers,
|
|
76
|
+
firstLineNumber: firstLineNumber
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
// Rows + logic into a renderer
|
|
@@ -18,9 +18,11 @@ export default function processLines(_ref) {
|
|
|
18
18
|
language = _ref.language,
|
|
19
19
|
shouldCreateParentElementForLines = _ref.shouldCreateParentElementForLines,
|
|
20
20
|
lineProps = _ref.lineProps,
|
|
21
|
-
showLineNumbers = _ref.showLineNumbers
|
|
21
|
+
showLineNumbers = _ref.showLineNumbers,
|
|
22
|
+
_ref$firstLineNumber = _ref.firstLineNumber,
|
|
23
|
+
firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber;
|
|
22
24
|
var codeTree = getCodeTree(language, code, astGenerator);
|
|
23
|
-
var startingLineNumber = 1;
|
|
25
|
+
var startingLineNumber = firstLineNumber > 0 ? firstLineNumber : 1;
|
|
24
26
|
var createLine = createLineGenerator(lineProps, shouldCreateParentElementForLines, showLineNumbers);
|
|
25
27
|
var newTree = [];
|
|
26
28
|
var lastLineBreakIndex = -1;
|
|
@@ -14,6 +14,11 @@ export interface CodeBlockProps {
|
|
|
14
14
|
* @default true
|
|
15
15
|
*/
|
|
16
16
|
showLineNumbers?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Sets the number of the first line, if showLineNumbers is set to true.
|
|
19
|
+
* @default 1
|
|
20
|
+
*/
|
|
21
|
+
firstLineNumber?: number;
|
|
17
22
|
/**
|
|
18
23
|
* Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
|
|
19
24
|
* `design-system/code`. Run against language grammars from PrismJS (full list
|
|
@@ -6,6 +6,7 @@ interface ProcessLines {
|
|
|
6
6
|
shouldCreateParentElementForLines: boolean;
|
|
7
7
|
lineProps: SyntaxHighlighterLineProps;
|
|
8
8
|
showLineNumbers: boolean;
|
|
9
|
+
firstLineNumber?: number;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* __Line Processor__
|
|
@@ -13,5 +14,5 @@ interface ProcessLines {
|
|
|
13
14
|
* A line processor, that uses refractor to turn code into a tree structure
|
|
14
15
|
* with highlighting metadata and collapses this tree into lines for a renderer.
|
|
15
16
|
*/
|
|
16
|
-
export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, }: ProcessLines): RefractorNode[];
|
|
17
|
+
export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, firstLineNumber, }: ProcessLines): RefractorNode[];
|
|
17
18
|
export {};
|
|
@@ -45,6 +45,11 @@ export interface SyntaxHighlighterProps {
|
|
|
45
45
|
* Sets whether to display code line numbers or not. Defaults to `true`
|
|
46
46
|
*/
|
|
47
47
|
showLineNumbers?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the number of the first line, if showLineNumbers is set to true.
|
|
50
|
+
* @default 1
|
|
51
|
+
*/
|
|
52
|
+
firstLineNumber?: number;
|
|
48
53
|
/**
|
|
49
54
|
* Determines whether or not each line of code should be wrapped in a parent
|
|
50
55
|
* element.
|
|
@@ -14,6 +14,11 @@ export interface CodeBlockProps {
|
|
|
14
14
|
* @default true
|
|
15
15
|
*/
|
|
16
16
|
showLineNumbers?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Sets the number of the first line, if showLineNumbers is set to true.
|
|
19
|
+
* @default 1
|
|
20
|
+
*/
|
|
21
|
+
firstLineNumber?: number;
|
|
17
22
|
/**
|
|
18
23
|
* Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
|
|
19
24
|
* `design-system/code`. Run against language grammars from PrismJS (full list
|
|
@@ -6,6 +6,7 @@ interface ProcessLines {
|
|
|
6
6
|
shouldCreateParentElementForLines: boolean;
|
|
7
7
|
lineProps: SyntaxHighlighterLineProps;
|
|
8
8
|
showLineNumbers: boolean;
|
|
9
|
+
firstLineNumber?: number;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* __Line Processor__
|
|
@@ -13,5 +14,5 @@ interface ProcessLines {
|
|
|
13
14
|
* A line processor, that uses refractor to turn code into a tree structure
|
|
14
15
|
* with highlighting metadata and collapses this tree into lines for a renderer.
|
|
15
16
|
*/
|
|
16
|
-
export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, }: ProcessLines): RefractorNode[];
|
|
17
|
+
export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, firstLineNumber, }: ProcessLines): RefractorNode[];
|
|
17
18
|
export {};
|
|
@@ -45,6 +45,11 @@ export interface SyntaxHighlighterProps {
|
|
|
45
45
|
* Sets whether to display code line numbers or not. Defaults to `true`
|
|
46
46
|
*/
|
|
47
47
|
showLineNumbers?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the number of the first line, if showLineNumbers is set to true.
|
|
50
|
+
* @default 1
|
|
51
|
+
*/
|
|
52
|
+
firstLineNumber?: number;
|
|
48
53
|
/**
|
|
49
54
|
* Determines whether or not each line of code should be wrapped in a parent
|
|
50
55
|
* element.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/code",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.4.0",
|
|
4
4
|
"description": "Code highlights short strings of code snippets inline with body text.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
31
|
-
"@atlaskit/theme": "^12.
|
|
32
|
-
"@atlaskit/tokens": "^1.
|
|
31
|
+
"@atlaskit/theme": "^12.11.0",
|
|
32
|
+
"@atlaskit/tokens": "^1.53.0",
|
|
33
33
|
"@atlaskit/tooltip": "^18.5.0",
|
|
34
34
|
"@atlaskit/visually-hidden": "^1.4.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|