Skip to content

Commit

Permalink
feat: Fix issue with wrap long lines and styles applied together.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Jul 14, 2022
1 parent df25a75 commit cb0cf3c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/components/Block/DefaultView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import clipboardSVG from '@plone/volto/icons/copy.svg';

const CodeView = (props) => {
const { data } = props;
const className = `code-block-wrapper ${data.style}`;
const { style, showLineNumbers, wrapLongLines } = data;
const styleWrap = wrapLongLines ? 'wrapLongLines' : '';
const className = `code-block-wrapper ${style} ${styleWrap}`;
const [copied, copy, setCopied] = useCopy(data.code);

const copyText = () => {
Expand Down Expand Up @@ -35,8 +37,8 @@ const CodeView = (props) => {
<SyntaxHighlighter
language={data.language}
useInlineStyles={false}
showLineNumbers={data.showLineNumbers}
wrapLongLines={data.wrapLongLines}
showLineNumbers={showLineNumbers}
wrapLongLines={wrapLongLines}
>
{data.code}
</SyntaxHighlighter>
Expand Down
19 changes: 18 additions & 1 deletion src/components/Block/DefaultView.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import Wrapper from '@plone/volto/storybook';
const codePython =
'import requests\nresp = requests.get("https://plone.org")\nassert resp.status_code == 200';

const codeLongLines = '# Code to show how wrap long lines would work\n\ntext = "This is a really, really, really, really long line including a lot of words and letters and a text that should not make any sense, but should be long, very long"\n\nprint(text)'

const StoryComponent = injectIntl(({ children, ...args }) => {
const { language, style, code, showLineNumbers, wrapLongLines } = args;
return (
<Wrapper>
<div>
<div style={{ maxWidth: '1000px', margin: 'auto' }}>
<CodeView
data={{
language: language,
Expand Down Expand Up @@ -39,6 +41,21 @@ LightStyle.args = {
code: codePython,
};

export const LongLines = StoryComponent.bind({});
LongLines.args = {
language: 'python',
style: 'dark',
code: codeLongLines,
};

export const LongLinesNoLineNumbers = StoryComponent.bind({});
LongLinesNoLineNumbers.args = {
language: 'python',
style: 'dark',
showLineNumbers: false,
code: codeLongLines,
};

export default {
title: 'Public/Blocks/CodeBlock',
component: CodeView,
Expand Down
8 changes: 8 additions & 0 deletions src/theme/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
}
}

&.wrapLongLines {
code {
> span {
display: block !important;
}
}
}

.hljs {
padding: 10px;
}
Expand Down

0 comments on commit cb0cf3c

Please sign in to comment.