Skip to content

Commit ba2de8c

Browse files
committed
feat(syntax): add support for highlighting lines in code snippets
fix #520
1 parent 3a34a3e commit ba2de8c

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
Title: Code Snippets -- Highlight Lines
3+
Tags: markdown, code-snippets, gist
4+
Date: 2020-02-02 20:12
5+
comments: false
6+
Slug: code-snippets-highlight-lines
7+
authors: Talha Mansoor
8+
Category: Components
9+
---
10+
11+
[Python-Markdown](https://github.com/Python-Markdown/markdown/) uses
12+
[CodeHilite](https://python-markdown.github.io/extensions/code_hilite/) <!-- yaspeller ignore -->
13+
extension for syntax highlighting.
14+
15+
This extension lets you highlight specific lines in your code snippets. You can read the instructions [here](https://python-markdown.github.io/extensions/code_hilite/#colons).
16+
17+
Elegant supports this feature.
18+
19+
:::python hl_lines="1 3"
20+
# This line is emphasized
21+
# This line isn't
22+
# This line is emphasized
23+
24+
Another example,
25+
26+
:::html hl_lines="2"
27+
<div
28+
class="photoswipe-gallery"
29+
itemscope
30+
itemtype="http://schema.org/ImageGallery"
31+
>
32+
</div>
33+
34+
Another example,
35+
36+
#!python hl_lines="2"
37+
# Code goes here ..
38+
# This line is emphasized
39+
# This line isn't

static/css/code.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* For highlighting lines in code snippets */
2+
.highlight span.hll span {
3+
background-color: black;
4+
display: inline-block;
5+
width: 100%;
6+
}
17
div.highlight {
28
margin-bottom: 20px;
39
border-radius: var(--borderRadius);

static/css/pygments.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.highlight .hll {
2-
background-color: #ffffcc;
2+
/* This line results in highlighting whitespaces -- Talha */
3+
/* background-color: #ffffcc; */
34
}
45
.highlight {
56
background: #282828;
@@ -301,8 +302,8 @@
301302
color: #d3869b;
302303
background-color: #282828;
303304
} /* Literal.Number.Integer.Long */
304-
/* My fixes */
305+
/* My fixes -- Talha*/
305306
.highlight .cpf {
306307
color: #b8bb26;
307308
background-color: #282828;
308-
}
309+
}

0 commit comments

Comments
 (0)