Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiCodeBlock] Replace highlight.js with prism.js via refractor #4638

Merged
merged 32 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e5cccd2
replace highlight.js with prism.js via refractor
thompsongl Mar 11, 2021
955654c
Merge branch 'master' into 3947-prism
thompsongl Mar 17, 2021
ecf4f65
merge fix: file renamed
thompsongl Mar 17, 2021
4a688ee
group lines
thompsongl Mar 18, 2021
7cd7617
update tests
thompsongl Mar 18, 2021
55dd561
Merge branch 'master' into 3947-prism
thompsongl Mar 18, 2021
71e1339
i18n block
thompsongl Mar 18, 2021
f7b852b
remove regex lookbehind not supported in safari
thompsongl Mar 18, 2021
205aa21
CL
thompsongl Mar 18, 2021
39dabe6
Merge branch 'master' into 3947-prism
thompsongl Mar 24, 2021
616915e
js -> jsx
thompsongl Mar 29, 2021
2b25bbe
Merge branch 'master' into 3947-prism
thompsongl Mar 29, 2021
971cc26
token color parity
thompsongl Mar 30, 2021
335a895
update line grouping method
thompsongl Apr 5, 2021
95567a0
use jsx language in docs
thompsongl Apr 5, 2021
4261382
Merge branch 'master' into 3947-prism
thompsongl Apr 5, 2021
bc3dfe8
reduce newlines
thompsongl Apr 7, 2021
75a2ae4
Merge branch 'master' into 3947-prism
thompsongl Apr 7, 2021
64b8418
docs
thompsongl Apr 7, 2021
8fda593
docs
thompsongl Apr 7, 2021
a111eeb
headings
thompsongl Apr 7, 2021
45dfed0
Update src-docs/src/views/code/code_example.js
thompsongl Apr 13, 2021
8fc6983
playground updates
thompsongl Apr 13, 2021
c02c97c
Merge branch 'master' into 3947-prism
thompsongl Apr 13, 2021
cfd6f7b
Merge branch 'master' into 3947-prism
thompsongl Apr 15, 2021
099aa73
Merge branch 'master' into 3947-prism
thompsongl Apr 15, 2021
02b10b4
Merge branch 'master' into 3947-prism
thompsongl Apr 22, 2021
ed7f20d
Merge branch '3947-prism' of https://github.com/thompsongl/eui into 3…
thompsongl Apr 22, 2021
c848aac
Merge branch 'master' into 3947-prism
thompsongl Apr 29, 2021
ee4e68d
os newlines
thompsongl Apr 29, 2021
a973b4c
Merge branch 'master' into 3947-prism
thompsongl May 4, 2021
18b0ccb
Merge branch 'master' into 3947-prism
thompsongl May 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `32.0.3`.

- Replaced `highlight.js` with `prism.js`/`refractor` for code syntax highlighting in `EuiCodeBlock` ([#4638](https://github.com/elastic/eui/pull/4638))

**Breaking changes**

- Changed some language syntax references in `EuiCodeBlock`, such as `jsx` ([#4638](https://github.com/elastic/eui/pull/4638))
- Removed ability to parse non-string content in `EuiCodeBlock` ([#4638](https://github.com/elastic/eui/pull/4638))

## [`32.0.3`](https://github.com/elastic/eui/tree/v32.0.3)

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"@types/react-input-autosize": "^2.2.0",
"@types/react-virtualized-auto-sizer": "^1.0.0",
"@types/react-window": "^1.8.2",
"@types/refractor": "^3.0.0",
"@types/vfile-message": "^2.0.0",
"chroma-js": "^2.1.0",
"classnames": "^2.2.6",
"highlight.js": "^9.18.5",
"lodash": "^4.17.21",
"numeral": "^2.0.6",
"prop-types": "^15.6.0",
Expand All @@ -68,11 +68,11 @@
"react-is": "~16.3.0",
"react-virtualized-auto-sizer": "^1.0.2",
"react-window": "^1.8.5",
"refractor": "^3.3.1",
"rehype-raw": "^5.0.0",
"rehype-react": "^6.0.0",
"rehype-stringify": "^8.0.0",
"remark-emoji": "^2.1.0",
"remark-highlight.js": "^6.0.0",
"remark-parse": "^8.0.3",
"remark-rehype": "^8.0.0",
"tabbable": "^3.0.0",
Expand Down Expand Up @@ -101,7 +101,6 @@
"@svgr/plugin-svgo": "^4.0.3",
"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.5",
"@types/highlight.js": "^9.12.4",
"@types/jest": "^24.0.6",
"@types/node": "^10.17.5",
"@types/react": "^16.9.34",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const GuideSectionExampleCode: FunctionComponent<GuideSectionExampleCode>

return (
<>
<EuiCodeBlock language={'javascript'} overflowHeight={400} isCopyable>
<EuiCodeBlock language="jsx" overflowHeight={400} isCopyable>
{codeToRender}
</EuiCodeBlock>
{codeSandboxLink}
Expand Down
18 changes: 10 additions & 8 deletions src-docs/src/services/playground/knobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '../../../../src/components/';

export const markup = (text) => {
const regex = /(#[a-zA-Z]+)|(`[^`]+`)/g;
const regex = /(\B#[a-zA-Z]+)|(`[^`]+`)/g;
return text.split('\n').map((token) => {
const values = token.split(regex).map((token, index) => {
if (!token) {
Expand Down Expand Up @@ -382,7 +382,7 @@ const KnobColumn = ({ state, knobNames, error, set, isPlayground }) => {

if (humanizedType) {
typeMarkup = humanizedType && (
<EuiCodeBlock {...codeBlockProps}>{markup(humanizedType)}</EuiCodeBlock>
<EuiCodeBlock {...codeBlockProps}>{humanizedType}</EuiCodeBlock>
);

const functionMatches = [
Expand All @@ -392,17 +392,19 @@ const KnobColumn = ({ state, knobNames, error, set, isPlayground }) => {
const types = humanizedType.split(/\([^=]*\) =>\s\w*\)*/);

if (functionMatches.length > 0) {
const elements = [];
let elements = '';
let j = 0;
for (let i = 0; i < types.length; i++) {
if (functionMatches[j]) {
elements.push(<div key={`type-${i}`}>{types[i]}</div>);
elements.push(
<div key={`function-${i}`}>{functionMatches[j][0]}</div>
);
elements =
`${elements}` +
`${types[i]}` +
'\n' +
`${functionMatches[j][0]}` +
'\n';
j++;
} else {
elements.push(<div key={`type-${i}`}>{types[i]}</div>);
elements = `${elements}` + `${types[i]}` + '\n';
}
}
typeMarkup = (
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/services/playground/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default ({
</div>
<EuiSpacer />
<EuiCodeBlock
language="html"
language="jsx"
fontSize="m"
paddingSize="m"
isCopyable>
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/code/code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default () => (
<EuiSpacer />

<EuiCodeBlock
language="js"
language="jsx"
fontSize="m"
paddingSize="m"
overflowHeight={300}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/code/code_block_pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EuiCodeBlock } from '../../../../src/components';
export default () => (
<div>
<EuiCodeBlock
language="js"
language="jsx"
fontSize="m"
paddingSize="m"
color="dark"
Expand Down
36 changes: 35 additions & 1 deletion src-docs/src/views/code/code_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';

import { EuiCode, EuiCodeBlock } from '../../../../src/components';
import {
EuiCode,
EuiCodeBlock,
EuiLink,
EuiText,
} from '../../../../src/components';
import { codeBlockConfig, codeConfig } from './playground';

import Code from './code';
Expand All @@ -26,6 +31,35 @@ const codeBlockPreHtml = renderToHtml(CodeBlockPre);

export const CodeExample = {
title: 'Code',
intro: (
<>
<EuiText>
<p>
The <strong>EuiCode</strong> and <strong>EuiCodeBlock</strong>{' '}
components support{' '}
<EuiLink external href="https://github.com/wooorm/refractor#syntaxes">
all language syntaxes
</EuiLink>{' '}
supported by the
<EuiCode>prism</EuiCode>{' '}
<EuiLink external href="https://prismjs.com/">
library
</EuiLink>
.
<br />
The <EuiCode>language</EuiCode> prop can also be omitted to simply
render formatted but unhighlighted code.
</p>
<p>
JSX code (often React) has distinct language syntaxes from the base
JavaScript and TypeScript languages. For instance, use{' '}
<EuiCode>language=&quot;jsx&quot;</EuiCode> or{' '}
<EuiCode>language=&quot;tsx&quot;</EuiCode> when the code in question
is JSX.
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
</p>
</EuiText>
</>
),
sections: [
{
title: 'Inline',
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/package/i18n_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const columns = [
render({ defString, highlighting }) {
return (
<EuiCodeBlock
language={highlighting === 'code' ? 'javascript' : 'text'}
language={highlighting === 'code' ? 'javascript' : undefined}
paddingSize="none"
transparentBackground
fontSize="s">
Expand Down
18 changes: 9 additions & 9 deletions src/components/code/__snapshots__/_code_block.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

exports[`EuiCodeBlockImpl block highlights javascript code, adding "js" class 1`] = `
<div
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge prismjs language-js"
>
<pre
class="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePreWrap"
tabindex="-1"
>
<code
class="euiCodeBlock__code js hljs javascript"
class="euiCodeBlock__code js"
/>
</pre>
</div>
`;

exports[`EuiCodeBlockImpl block renders a pre block tag 1`] = `
<div
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge testClass1 testClass2"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge prismjs language-none testClass1 testClass2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the old version used to also default to no highlighting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

>
<pre
class="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePreWrap"
Expand All @@ -37,7 +37,7 @@ console.log(some);

exports[`EuiCodeBlockImpl block renders a pre block tag with a css class modifier 1`] = `
<div
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge testClass1 testClass2"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge prismjs language-none testClass1 testClass2"
>
<pre
class="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePre"
Expand All @@ -57,7 +57,7 @@ console.log(some);

exports[`EuiCodeBlockImpl block renders with transparent background 1`] = `
<div
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--transparentBackground"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--transparentBackground prismjs language-none"
>
<pre
class="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePreWrap"
Expand All @@ -72,17 +72,17 @@ exports[`EuiCodeBlockImpl block renders with transparent background 1`] = `

exports[`EuiCodeBlockImpl inline highlights javascript code, adding "js" class 1`] = `
<span
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline prismjs language-js"
>
<code
class="euiCodeBlock__code js hljs javascript"
class="euiCodeBlock__code js"
/>
</span>
`;

exports[`EuiCodeBlockImpl inline renders an inline code tag 1`] = `
<span
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline testClass1 testClass2"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline prismjs language-none testClass1 testClass2"
>
<code
aria-label="aria-label"
Expand All @@ -97,7 +97,7 @@ console.log(some);

exports[`EuiCodeBlockImpl inline renders with transparent background 1`] = `
<span
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--transparentBackground euiCodeBlock--inline"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--transparentBackground euiCodeBlock--inline prismjs language-none"
>
<code
class="euiCodeBlock__code"
Expand Down
2 changes: 1 addition & 1 deletion src/components/code/__snapshots__/code.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiCode renders a code snippet 1`] = `
<span
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline testClass1 testClass2"
class="euiCodeBlock euiCodeBlock--fontSmall euiCodeBlock--paddingLarge euiCodeBlock--inline prismjs language-none testClass1 testClass2"
>
<code
aria-label="aria-label"
Expand Down
Loading