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

fix(v2): remove auto wrap for code blocks #2048

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 38 additions & 35 deletions packages/docusaurus-theme-classic/src/theme/CodeBlock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,46 @@ export default ({children, className: languageClassName, metastring}) => {
};

return (
<Highlight
{...defaultProps}
theme={prism.theme || defaultTheme}
code={children.trim()}
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<div className={styles.codeBlockWrapper}>
<pre
ref={target}
className={classnames(className, styles.codeBlock)}
style={style}>
{tokens.map((line, i) => {
const lineProps = getLineProps({line, key: i});
<div className={styles.codeBlockWrapper}>
<button
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={styles.copyButton}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>

if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
}
<Highlight
{...defaultProps}
theme={prism.theme || defaultTheme}
code={children.trim()}
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<pre className={classnames(className, styles.codeBlock)}>
<code
ref={target}
className={classnames(className, styles.codeBlockLines)}
style={style}>
{tokens.map((line, i) => {
const lineProps = getLineProps({line, key: i});

return (
<div key={i} {...lineProps}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token, key})} />
))}
</div>
);
})}
if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
}

return (
<div key={i} {...lineProps}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token, key})} />
))}
</div>
);
})}
</code>
</pre>
<button
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={styles.copyButton}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>
</div>
)}
</Highlight>
)}
</Highlight>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
.codeBlock {
border-radius: 0;
margin-bottom: 0;
overflow: hidden;
overflow-wrap: break-word;
white-space: pre-wrap;
}

.codeBlockWrapper {
position: relative;
}
Expand All @@ -32,3 +24,18 @@
transition: opacity 200ms ease-in-out, visibility 200ms ease-in-out,
bottom 200ms ease-in-out;
}

.codeBlock {
overflow: auto;
display: block;
padding: 0;
font-size: inherit;
}

.codeBlockLines {
border-radius: 0;
margin-bottom: 0;
float: left;
min-width: 100%;
padding: var(--ifm-pre-padding);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function DocItem(props) {
<div className="padding-vert--lg">
<div className="container">
<div className="row">
<div className="col">
<div className="col col--9">
<div className={styles.docItemContainer}>
<article>
{version && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,43 +81,46 @@ export default ({
};

return (
<Highlight
{...defaultProps}
theme={prism.theme || defaultTheme}
code={children.trim()}
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<div className={styles.codeBlockWrapper}>
<pre
ref={target}
className={classnames(className, styles.codeBlock)}
style={style}>
{tokens.map((line, i) => {
const lineProps = getLineProps({line, key: i});

if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
}

return (
<div key={i} {...lineProps}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token, key})} />
))}
</div>
);
})}
<div className={styles.codeBlockWrapper}>
<button
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={styles.copyButton}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>

<Highlight
{...defaultProps}
theme={prism.theme || defaultTheme}
code={children.trim()}
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<pre className={classnames(className, styles.codeBlock)}>
<code
ref={target}
className={classnames(className, styles.codeBlockLines)}
style={style}>
{tokens.map((line, i) => {
const lineProps = getLineProps({line, key: i});

if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
}

return (
<div key={i} {...lineProps}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token, key})} />
))}
</div>
);
})}
</code>
</pre>
<button
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={styles.copyButton}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>
</div>
)}
</Highlight>
)}
</Highlight>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
.codeBlock {
border-radius: 0;
font-size: inherit;
margin-bottom: 0;
overflow: hidden;
overflow-wrap: break-word;
white-space: pre-wrap;
}

.codeBlockWrapper {
position: relative;
}
Expand All @@ -33,3 +24,18 @@
transition: opacity 200ms ease-in-out, visibility 200ms ease-in-out,
bottom 200ms ease-in-out;
}

.codeBlock {
overflow: auto;
display: block;
padding: 0;
font-size: inherit;
}

.codeBlockLines {
border-radius: 0;
margin-bottom: 0;
float: left;
min-width: 100%;
padding: var(--ifm-pre-padding);
}