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

copy to clipboard and code type information in the code block mentioned in the markdown #197

Open
automationxpert opened this issue Dec 26, 2022 · 1 comment

Comments

@automationxpert
Copy link

Is your feature request related to a problem? Please describe.

  1. The code snippets used in the markdown files are doesn't show the code type mentioned in markdown.
  2. The copy to clipboard option in the top right corner for each code snippets would be a great feature.

Describe the solution you'd like

  1. The code snippets used in the markdown files are getting detected but would love to show what code it is such as bash, javascript, python, php, powershell etc just as mentioned in the markdown.
  2. Also copy to clipboard option in the top right corner for each code snippets (where the button is changed upon click showing as copied with a color change for 3-4 seconds).

Describe alternatives you've considered
I tried to implement the 2nd feature mentioned, but the copy button always ends at the left side bottom inspite of using the css. Please find the code i tried below:

var codeBlocks = document.querySelectorAll('pre.highlight');


codeBlocks.forEach(function (codeBlock) {
  var  Button = document.createElement('button');
   Button.className = ' ';
   Button.type = 'button';
   Button.ariaLabel = 'Copy code to clipboard';
   Button.innerText = 'Copy';


  codeBlock.append( Button);


   Button.addEventListener('click', function () {
    var code = codeBlock.querySelector('code').innerText.trim();
    window.navigator.clipboard.writeText(code);


     Button.innerText = 'Copied';
    var fourSeconds = 4000;


    setTimeout(function () {
       Button.innerText = 'Copy';
    }, fourSeconds);
  });
});

Placed the below in the _includes/head.html

<script src="/assets/js/codeblock.js"></script>
pre.highlight {
    padding: 8px 12px;
    position: relative;
  
    // override skeleton styles
    > code {
      border: 0;
      overflow-x: auto;
      padding-right: 0;
      padding-left: 0;
    }
  
    &.highlight {
      border-left: 15px solid #35383c;
      color: #c1c2c3;
      overflow: auto;
      white-space: pre;
      word-wrap: normal;
  
      &,
      code {
        background-color: #222;
        font-size: 14px;
      }
    }
  
    //   code to clipboard
    .  {
      color: #4AF626;
      position: absolute;
      right: 1.2rem;
      top: 1.2rem;
      opacity: 0;
  
      &:active,
      &:focus,
      &:hover {
        background: rgba(0, 0, 0, 0.7);
        opacity: 1;
      }
    }
  
    &:active . ,
    &:focus . ,
    &:hover .  {
      background: rgba(0, 0, 0, 0.7);
      opacity: 1;
    }
  } 
@github-actions
Copy link

Thanks for submitting an issue! I'll check it at as soon as possible and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant