Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from victorg1991/code-tabs
Browse files Browse the repository at this point in the history
Add a way to add labels different than the code language in code tabs
  • Loading branch information
diegonvs authored Dec 4, 2018
2 parents 02b3d40 + f1bd335 commit 0a5335b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
5 changes: 4 additions & 1 deletion content/onboarding/one.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ stepNumber: 1

#### Github
Clone the project running
```sh
```bash http
git clone https://github.com/diegonvs/gatsby-boilerplate.git
```
```bash ssh
git clone [email protected]:diegonvs/gatsby-boilerplate.git
```
and after access `gatsby-boilerplate/` folder and run `yarn`.

#### Gatsby CLI
Expand Down
3 changes: 3 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module.exports = {
options: {
extensions: ['.mdx', '.md'],
gatsbyRemarkPlugins: [
{
resolve: path.resolve(__dirname, './plugins/gatsby-remark-code-label-extractor'),
},
{
resolve: path.resolve(__dirname, './plugins/gatsby-remark-foreach-icons'),
},
Expand Down
14 changes: 14 additions & 0 deletions plugins/gatsby-remark-code-label-extractor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const visit = require("unist-util-visit");

module.exports = ({ markdownAST }) => {
visit(markdownAST, "code", node => {
if (node.lang) {
const [lang, label] = node.lang.split(" ");

node.lang = lang;
node.label = label || lang;
}

return node;
});
};
4 changes: 4 additions & 0 deletions plugins/gatsby-remark-code-label-extractor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "gatsby-remark-code-label-extractor",
"version": "0.0.1"
}
2 changes: 1 addition & 1 deletion plugins/gatsby-remark-use-clipboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = ({markdownAST}) => {
return;
}

node.value = `<div class="code-container">
node.value = `<div class="code-container" data-label="${node.label}">
<button class="btn btn-sm btn-copy" title="Copy"><svg class="lexicon-icon"><use xlink:href="/images/icons/icons.svg#paste"></use></svg></button>
${node.value}
</div>`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodeTabs/CodeTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CodeTabs {
}

_getTabLabelFromElement(element) {
return element.querySelector('.gatsby-highlight').getAttribute('data-language');
return element.getAttribute('data-label');
}

_hide(element) {
Expand Down
12 changes: 0 additions & 12 deletions src/styles/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,3 @@
color: rgba($brand-dark, 0.6);
}
}

.nav.nav-tabs.nav-code-tabs {
li:nth-last-child(3) + li > button {
font-size: 0;

&:before {
content: 'WEB COMPONENTS';
display: inline-block;
font-size: 13px;
}
}
}

0 comments on commit 0a5335b

Please sign in to comment.