Skip to content

Commit

Permalink
Implemented copy code button feature (#1267)
Browse files Browse the repository at this point in the history
Implemented support for copy code button in code blocks (#1262), also updated blog post about code to reflect it.
  • Loading branch information
george-gca committed Mar 19, 2023
1 parent fa9e1c3 commit bacddc7
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 87 deletions.
1 change: 1 addition & 0 deletions _includes/scripts/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

<!-- Load Common JS -->
<script defer src="{{ '/assets/js/common.js' | relative_url }}"></script>
<script defer src="{{ '/assets/js/copy_code.js' | relative_url }}" type="text/javascript"></script>
32 changes: 31 additions & 1 deletion _posts/2015-07-15-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,37 @@ categories: sample-posts
This theme implements a built-in Jekyll feature, the use of Rouge, for syntax highlighting.
It supports more than 100 languages.
This example is in C++.
All you have to do is wrap your code in a liquid tag:
All you have to do is wrap your code in markdown code tags:

````markdown
```c++
code code code
```
````

```c++
int main(int argc, char const \*argv[])
{
string myString;

cout << "input a string: ";
getline(cin, myString);
int length = myString.length();

char charArray = new char * [length];

charArray = myString;
for(int i = 0; i < length; ++i){
cout << charArray[i] << " ";
}

return 0;
}
```
By default, it does not display line numbers. If you want to display line numbers for every code block, you can set `kramdown.syntax_highlighter_opts.block.line_numbers` to true in your `_config.yml` file.
If you want to display line numbers for a specific code block, all you have to do is wrap your code in a liquid tag:
{% raw %}
{% highlight c++ linenos %} <br/> code code code <br/> {% endhighlight %}
Expand Down
Loading

0 comments on commit bacddc7

Please sign in to comment.