Skip to content

Commit bacddc7

Browse files
authored
Implemented copy code button feature (alshedivat#1267)
Implemented support for copy code button in code blocks (alshedivat#1262), also updated blog post about code to reflect it.
1 parent fa9e1c3 commit bacddc7

File tree

4 files changed

+286
-87
lines changed

4 files changed

+286
-87
lines changed

_includes/scripts/misc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
<!-- Load Common JS -->
1414
<script defer src="{{ '/assets/js/common.js' | relative_url }}"></script>
15+
<script defer src="{{ '/assets/js/copy_code.js' | relative_url }}" type="text/javascript"></script>

_posts/2015-07-15-code.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,37 @@ categories: sample-posts
99
This theme implements a built-in Jekyll feature, the use of Rouge, for syntax highlighting.
1010
It supports more than 100 languages.
1111
This example is in C++.
12-
All you have to do is wrap your code in a liquid tag:
12+
All you have to do is wrap your code in markdown code tags:
13+
14+
````markdown
15+
```c++
16+
code code code
17+
```
18+
````
19+
20+
```c++
21+
int main(int argc, char const \*argv[])
22+
{
23+
string myString;
24+
25+
cout << "input a string: ";
26+
getline(cin, myString);
27+
int length = myString.length();
28+
29+
char charArray = new char * [length];
30+
31+
charArray = myString;
32+
for(int i = 0; i < length; ++i){
33+
cout << charArray[i] << " ";
34+
}
35+
36+
return 0;
37+
}
38+
```
39+
40+
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.
41+
42+
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:
1343
1444
{% raw %}
1545
{% highlight c++ linenos %} <br/> code code code <br/> {% endhighlight %}

0 commit comments

Comments
 (0)