Code
Code renders inline code snippets and code blocks.
Installation
yarn add @atlaskit/code
Usage
Detailed docs and example usage can be found here.
Code highlights short strings of code snippets inline with body text.
Code renders inline code snippets and code blocks.
yarn add @atlaskit/code
Detailed docs and example usage can be found here.
cb318c8c28c26
-
Internal changes to typography.962b5e77810fb
-
Adds side-effect config to support Compiled css extraction in third-party appsfba89f308ab2b
-
[ux] Removed feature flag resulting typography style changes but no visual changes.0f13c972be628
-
[ux] Fix background color override using CSS variable for inlinde code behind a feature flag. If
successful, these changes will be made available in a later release.55f40e0488d9e
-
[ux] Use typography tokens where possible for code block component behind a feature flag. If
successful, these changes will be made available in a later release.9e6563c10af4c
-
Updating font styles for code component inline with the new typography system behind a feature
flag. If successful, these changes will be made available in a later release.#127511
db30e29344013
-
Widening range of react
and react-dom
peer dependencies from ^16.8.0 || ^17.0.0 || ~18.2.0
to the wider range of ^16.8.0 || ^17.0.0 || ^18.0.0` (where applicable).
This change has been done to enable usage of `react@18.3as well as to have a consistent peer
dependency range for
reactand
react-domfor
/platform` packages.
77504ff274f72
-
DSP-19576: Assign names to anonymous default exportsd5fe97a9a6bc1
-
Remove remnants of extract-react-types
.c3908db22d486
-
CodeBlock supports a new firstLineNumber
prop, which allows the starting line number to be set
(defaulting to 1).cd506a937e44f
-
Internal change to how typography is applied. There should be no visual change.223959ef57c80
-
Explicitly set jsxRuntime to classic via pragma comments in order to avoid issues where jsxRuntime
is implicitly set to automatic.61432c68027c1
-
[ux] CodeBlock now renders tab size as 4 characters wide.71a555d49484
-
Add support for React 18 in non-strict mode.cd5d06cd3329
-
Minor adjustments to improve compatibility with React 188d4e99057fe0
-
Upgrade Typescript from 4.9.5
to 5.4.2
96e3a0ee5b7
- [ux] Add
support for Dockerfile, HCL, NGINX and Protobuf languages73adf14896c
- Remove
usage of legacy theming from the Code component and refactor where necessary to accomodate the
updated API.ffa68309c76
- update
children variable to have type definitionfd6bb9c9184
- Delete
version.json4ae083a7e66
- Use
@af/accessibility-testing
for default jest-axe config and jest-axe import in accessibility
testing.59b808d6a46
- [ux]
Improves the accessibility of the bidirectional character warnings.e7ea6832ad2
- Bans the
use of React.FC/React.FunctionComponent type in ADS components as part of the React 18 migration
work. The change is internal only and should not introduce any changes for the component
consumers.49b08bfdf5f
- Migrated
use of gridSize
to space tokens where possible. There is no expected visual or behaviour change.9d00501a414
- Ensure
legacy types are published for TS 4.5-4.841fae2c6f68
- Upgrade
Typescript from 4.5.5
to 4.9.5
56507598609
- Skip
minor dependency bump2e01c9c74b5
- DUMMY
remove before merging to master; dupe adf-schema via adf-utils74750bef5c4
- Fixes
some bugs with the long line wrapping and syntax-highlighting changes that were released in
v14.5.0.3ca97be0c06
- Internal
change only. Replace usages of Inline/Stack with stable version from @atlaskit/primitives
.261420360ec
- Upgrades
component types to support React 18.#30248
f5ca132a05e
- [ux]
CodeBlock has had some significant under-the-hood changes in this version. While technically it is
a minor update as all API changes are additive and backwards-compatible, this is a heads up that
there are some small visual changes that may require visual regression snapshots to be updated.
Adds a new shouldWrapLongLines
prop that allows you to wrap long lines of code over multiple
lines, instead of always forcing the container to scroll horizontally.
Fixes a frustrating bug where copying code from CodeBlock
would also copy line numbers — this
no longer occurs!
Replaces the dependency of react-syntax-highlighter
with our own implementation that is more
maintainable and performant. This also lead to a bump in an underlying dependency prismjs
which added new syntax highlighting features for some languages. This may cause some blocks of
code to look slightly different, potentially impacting VR tests — some changes are expected!
Reach out to #help-design-system if you have any questions.
Improves the presentation and security of CodeBlock
's with bidirectional characters to present
the source code exactly how it was written. The bidirectional characters themselves are still
highlighted in the same way as before with a warning and a tooltip. This may also impact VR
tests, but is expected.
18aeca8c199
- Internal
change to update token references. There is no expected behaviour or visual change.b0f6dd0bc35
- Updated
to use typography tokens. There is no expected behaviour or visual change.f1765efdca6
- [ux] Fix
bug that caused misalignment of Code Block content which contain a mixture of spaces and tabsbc989043572
- Internal
changes to apply spacing tokens. This should be a no-op change.d6bf753bb43
- Updates
@emotion/core
to @emotion/react
; v10 to v11. There is no expected behavior change.8cc2f888c83
- Upgrade
Typescript from 4.3.5
to 4.5.5
8d4228767b0
- Upgrade
Typescript from 4.2.4
to 4.3.5
.8202e37941b
- Internal
code change turning on new linting rules.cb2392f6d33
- Upgrade
to TypeScript 4.2.446824ff1acd
- [ux]
<CodeBlock />
s with no content no longer vertically collapse, and maintain their intended
minimum height#19019
a1a89347baa
- [ux]
Instrumented @atlaskit/code
with the new theming package, @atlaskit/tokens
.
New tokens will be visible only in applications configured to use the new Tokens API (currently in alpha). These changes are intended to be interoperable with the legacy theme implementation. Legacy dark mode users should expect no visual or breaking changes.
Updated dependencies
b5226ba2c15
- Replace
bolt
with yarn
for rendered example changeset commands7a34eeea327
- Bump
prismjs due to vulnerabilitydb3477abb18
- [ux]
ED-13938 disabled code-bidi warning tooltip for mobile, reworked TextWrapper to fix bidi
mitigation, and fixed issue where bidi warnings were not presented when renderer used with an
annotation provider with draftMode set to truec80c71b537d
- [ux]
ED-13860 add bidi warning decorations to code componentsb85e7ce12cd
- Internal
upgrade of memoize-one to 6.0.0378d1cef00f
- Bump
@atlaskit/theme
to version ^11.3.0
.d827fec15b2
- Fixes a
regression in ^14.0.0 that meant the function getCodeStyles
didn't work correctly with
interpolations using the styled-components
theming.cd488f9d370
- Bumps
prismjs to address a security vulnerability in the underlying lib.aef12f51c46
- Add an
entry point for constants to expose SUPPORTED_LANGUAGES and export the type of
SUPPORTED_LANGUAGES. Splunk SPl has also been added as a supported language.596f1eb2fca
- [ux]
Line height property remvoved from inline code. This was a bug as the line height was being under
calculated relative to the code's font size. It now inherits correctly.#10230
e8f66c36dd7
-
BREAKING CHANGES
This version includes several breaking changes to improve performance of the @atlaskit/code
package.
<Code />
no longer supports syntax highlighting, greatly simplifying the component.
Additionally, the text
prop has been removed in favour of using children
directly. This allows
users to provide complex nodes (not just plain text) to Code.
// previous
<Code text="const x = 10;" language="js" />
// now with language no longer supported
<Code>const x = 10;</Code>
Component theming is no longer supported in <Code />
or <CodeBlock />
; this change does not
effect global theming. As an escape hatch, two CSS variables are exposed:
--ds--code--line-number-bg-color
: which controls the background color of the line numbers if
set--ds--code--bg-color
: which controls the background color of the block body if setComponents can now be imported individually using individual entrypoints. Using these entrypoints will reduce the overall bundle size of this package if you do not need both components.
import { Code } from '@atlaskit/code';
// --> to
import Code from '@atlaskit/code/inline';
import { CodeBlock } from '@atlaskit/code';
// --> to
import CodeBlock from '@atlaskit/code/block';
// note this will still work
import { Code, CodeBlock } from '@atlaskit/code';
Finally, CodeBlock
has had type improvements, and internal optimisations to facilitate faster
rendering and updates.
7e091c1d415
- BREAKING
CHANGE:
The codeStyle
prop has now been removed on the Code
component.
For reference, previously this type of usage would effect the styling of any numbers in the code text.
<Code codeStyle={{ number: 'red' }} text={someCode} />
Due to internal changes the above usage is no longer possible.
This release also includes internal changes to the syntax highlighting element to use class names instead of inline styles for syntax highlighting. This results in a substantial performance gain.
07e012bfc5b
- Updates
to internal package structure, exposing additional entrypoints. Types also tightened for language
support to better match underlying component.b46ca884bc8
- Add a
codemod to remove usages of the language
prop and convert the text
prop to be a child.900819ca759
- Update
to VR test suite, to make diffs easier to reason about.c9da1eecd2a
- Internal
changes moving class components to functional components, added updated types for
react-syntax-highlighter413cc46d307
- [ux]
Added colors for missing syntax keywords3c7be954dbd
- [ux]
Line highlighting now meets WCAG 2.1 guidelines. Colors that were failing contrast have been
updated and there is now a new visual cue consisting of a left border to the highlighted lines.23ef692842a
- [ux]
Code
and CodeBlock
now use react-syntax-highlighter@^15 to highlight code. As part of this
change the fontSize for the line numbers and the code body have been normalised. This will be a
breaking visual change for all consumers. No action is required other than a callout that this
will affect any existing visual regression tests.
Users can now use the themeOverride
prop to customise the application of the default theme. This
is an escape hatch which will likley be removed in a future major version.
This change also includes:
Code
and CodeBlock
now expose additional options in their theme
prop. These are
codeFontSize
and codeLineHeight
which allow customisation of the component's rendered font
size.7c2f2056ef7
- [ux]
Added code syntax highlighting for the following languages: AppleScript, Clojure, Delphi, Diff,
FoxPro, Object Pascal, QML, Standard ML, Visual Basic, JSX and TSX
72d19d3f308
- Internal
changes relating to types, and tests. Includes a small bugfix to the way Code component had styles
applied and adds testId as a prop to both Code and CodeBlock.84c4d95e2e0
- [ux]
Line numbers now have correct spacing in Firefox and Safari.a4bcf21a972
- [ux]
Syntax highlighting now uses accessibile colors that meet WCAG 2.0 Level AA guidelines for color
contrastb5873e7bf01
- [ux]
Fixed highlighted line left border alignment.d3265f19be
- Transpile
packages using babel rather than tsc17162a77f2
- types of
Supported Languages for @atlaskit/code is maintained by the package itself. Useful for when one
references Supported Languages, wanting to know what types of languages are supported by
@atlaskit/code.5f58283e1f
- Export
types using Typescript's new "export type" syntax to satisfy Typescript's --isolatedModules
compiler option. This requires version 3.8 of Typescript, read more about how we handle Typescript
versions here: https://atlaskit.atlassian.com/get-started Also add typescript
to
devDependencies
to denote version that the package was built with.ade5203287
- Fix
codemod utilities being exposed through the codemod cli37f8133702
- - Rename
AkCode
and AkCodeBlock
exports to Code
and CodeBlock
respectively.lineNumberContainerStyle
, showLineNumbers
and highlight
) from
Code
.Theme
type into CodeTheme
and CodeBlockTheme
.lineNumberColor
and lineNumberBgColor
type from CodeTheme
. They are available only
in CodeBlockTheme
now.336f870e37
- fix
exception errors of syntax highlighter for several languages#3885
6c525a8229
- Upgraded
to TypeScript 3.9.6 and tslib to 2.0.0
Since tslib is a dependency for all our packages we recommend that products also follow this tslib upgrade to prevent duplicates of tslib being bundled.
954cc87b62
- The readme
and package information has been updated to point to the new design system website.db053b24d8
- Update all
the theme imports to be tree-shakable87f4720f27
- Officially
dropping IE11 support, from this version onwards there are no warranties of the package working in
IE11. For more information see:
https://community.developer.atlassian.com/t/atlaskit-to-drop-support-for-internet-explorer-11-from-1st-july-2020/3953454a9514fcf
- Build and
supporting files will no longer be published to npm[patch]f7f2068a76:
Change imports to comply with Atlassian conventions
[patch]5f5b93071f:
Code highlighting now works as expected when highlighting single to double digit lines.- Updated dependencies dae900bf82:
Updated dependencies 8c9e4f1ec6:
[patch]6548261c9a:
Remove namespace imports from React, ReactDom, and PropTypes- Updated dependencies 6548261c9a:
[patch]b52f2be5d9:
ThemedCode and ThemeCodeBlock props are now correctly typed- Updated dependencies d2b8166208:
[patch]4a223473c5:
Removes babel/runtime from dependencies. Users should see a smaller bundlesize as a result- Updated dependencies 82747f2922:
[minor]9648afc5be:
Adds highlight
prop to AkCodeBlock
, Example
, and the code
template literal. Use this to
emphasize which lines of code you would like people to look at!
The highlight
prop can be used as follows:
highlight="3"
highlight="1-5"
highlight="1-5,7,10,15-20"
AkCodeBlock
component
Use the highlight
prop.
import { AkCodeBlock } from '@atlaskit/code';
<AkCodeBlock
highlight="1-2"
text={`
<div>
hello there
<span>buds</span>
</div>
`}
/>;
Example
component
Use the highlight
prop.
import { Example } from '@atlaskit/docs';
<Example
packageName="@atlaskit/code"
Component={require('../examples/00-inline-code-basic').default}
title="Basic"
highlight="19,24,30,36"
source={require('!!raw-loader!../examples/00-inline-code-basic')}
/>;
code
template literal
Add highlight=
to the top of your code snippet. It takes the same values as the highlight
prop.
import { code } from '@atlaskit/docs';
code`highlight=5-7
import React from 'react';
() => (
<div>
hello there
<span>buds</span>
</div>
)`;
[patch]35d2229b2a:
Adding missing license to packages and update to Copyright 2019 Atlassian Pty Ltd.
[patch]a2d0043716:
Updated version of analytics-next to fix potential incompatibilities with TS 3.6
[patch]65ada7f318:
FABDODGEM-12 Editor Cashmere Release
Affected editor components:
tables, media, mobile, text color, emoji, copy/paste, analytics
Performance
Table
Text color
Mobile - Implement undo/redo interface on Hybrid Editor - https://product-fabric.atlassian.net/browse/FM-2393
Copy and Paste
- Support copy & paste when missing context-id attr
- https://product-fabric.atlassian.net/browse/MS-2344
- Right click + copy image fails the second time that is pasted
- https://product-fabric.atlassian.net/browse/MS-2324
- Copying a never touched image for the first time from editor fails to paste
- https://product-fabric.atlassian.net/browse/MS-2338
- Implement analytics when a file is copied
- https://product-fabric.atlassian.net/browse/MS-2036
Media
Notable Bug Fixes
- Implement consistent behaviour for rule and mediaSingle on insertion
- Feature Flag:
- allowNewInsertionBehaviour - [default: true]
- https://product-fabric.atlassian.net/browse/ED-7503
- Fixed bug where we were showing table controls on mobile.
- https://product-fabric.atlassian.net/browse/ED-7690
- Fixed bug where editor crashes after unmounting react component.
- https://product-fabric.atlassian.net/browse/ED-7318
- Fixed bug where custom emojis are not been showed on the editor
- https://product-fabric.atlassian.net/browse/ED-7726
[patch]1715ad2bd5:
ED-7731: add support for GraphQL syntax highlighting
[patch]097b696613:
Components now depend on TS 3.6 internally, in order to fix an issue with TS resolving non-relative imports as relative imports
[patch]ecca4d1dbb:
Upgraded Typescript to 3.3.x
[patch]708028db86:
Change all the imports to theme in Core to use multi entry points
[patch]abee1a5f4f:
Bumping internal dependency (memoize-one) to latest version (5.1.0). memoize-one@5.1.0 has full typescript support so it is recommended that typescript consumers use it also.
[patch]de35ce8c67:
Updates component maintainers
[patch]bbff8a7d87:
Fixes bug, missing version.json file
[patch]18dfac7332:
In this PR, we are:
[patch]29a1f158c1:
Use default react import in typescript files.
[patch]4615439434:
index.ts will now be ignored when publishing to npm
[patch]93bcf314c6:
Added missing tslib dep
[patch]b0ef06c685:
[major]97bfe81ec8:
[major]7c17b35107:
[major]76299208e6:
As a breaking change, all @atlaskit packages will be dropping cjs distributions and will only
distribute esm. This means all distributed code will be transpiled, but will still contain
import
and export
declarations.
The major reason for doing this is to allow us to support multiple entry points in packages, e.g:
import colors from `@atlaskit/theme/colors`;
Previously this was sort of possible for consumers by doing something like:
import colors from `@atlaskit/theme/dist/esm/colors`;
This has a couple of issues. 1, it treats the file system as API making internal refactors harder, we have to worry about how consumers might be using things that aren't actually supposed to be used. 2. We are unable to do this internally in @atlaskit packages. This leads to lots of packages bundling all of theme, just to use a single color, especially in situations where tree shaking fails.
To support being able to use multiple entrypoints internally, we unfortunately cannot have multiple distributions as they would need to have very different imports from of their own internal dependencies.
ES Modules are widely supported by all modern bundlers and can be worked around in node environments.
We may choose to revisit this solution in the future if we find any unintended condequences, but we see this as a pretty sane path forward which should lead to some major bundle size decreases, saner API's and simpler package architecture.
Please reach out to #fabric-build (if in Atlassian) or create an issue in Design System Support (for external) if you have any questions or queries about this.
[patch]d49e9bbb13:
[minor]10fe416:
[patch]84e8015:
[minor]26027dd: