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

DOP-1604: Allow code blocks to render with caption #299

Merged
merged 5 commits into from
Oct 19, 2020
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
5 changes: 4 additions & 1 deletion src/components/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getLanguage = lang => {
};

const Code = ({
nodeData: { copyable, emphasize_lines: emphasizeLines, lang, linenos, value },
nodeData: { copyable, caption, emphasize_lines: emphasizeLines, lang, linenos, value },
uriWriter: { cloudURI, localURI },
}) => {
const { activeTabs } = useContext(TabContext);
Expand Down Expand Up @@ -72,6 +72,8 @@ const Code = ({
highlightLines={emphasizeLines}
language={getLanguage(lang)}
showLineNumbers={linenos}
showWindowChrome={caption ? true : false}
chromeTitle={caption ? caption : ''}
>
{code}
</CodeBlock>
Expand All @@ -86,6 +88,7 @@ Code.propTypes = {
lang: PropTypes.string,
linenos: PropTypes.bool,
value: PropTypes.string.isRequired,
caption: PropTypes.string,
}).isRequired,
uriWriter: PropTypes.shape({
cloudURI: PropTypes.object,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/__snapshots__/Code.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`renders correctly 1`] = `
<Code
nodeData={
Object {
"caption": "Test Caption",
"copyable": true,
"lang": "javascript",
"position": Object {
Expand All @@ -30,6 +31,7 @@ exports[`renders with javascript disabled correctly 1`] = `
<Code
nodeData={
Object {
"caption": "Test Caption",
"copyable": true,
"lang": "javascript",
"position": Object {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/data/Code.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
},
"lang": "javascript",
"copyable": true,
"caption": "Test Caption",
"value": "mongoimport --db test --collection inventory ^\n --authenticationDatabase admin --username <user> --password <password> ^\n --drop --file ~\\downloads\\inventory.crud.json"
}
}