Skip to content

Commit 13399b9

Browse files
authored
Merge pull request #183 from NMFS-RADFish/add-code-diff-highlighting
Add code diff highlighting
2 parents 6213ad5 + 353c37f commit 13399b9

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

docusaurus.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,16 @@ ${content}`,
559559
prism: {
560560
theme: prismThemes.github,
561561
darkTheme: prismThemes.dracula,
562+
magicComments: [
563+
{
564+
className: 'code-block-diff-add-line',
565+
line: 'diff-add'
566+
},
567+
{
568+
className: 'code-block-diff-remove-line',
569+
line: 'diff-remove'
570+
}
571+
]
562572
},
563573
}),
564574
};

src/css/custom.css

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,52 @@
8585

8686
.button--secondary:hover {
8787
background-color: var(--ifm-color-secondary-light);
88-
}
88+
}
89+
90+
/* Code diff highlighting start */
91+
.code-block-diff-add-line {
92+
background-color: #ccffd8;
93+
display: block;
94+
margin: 0 -40px;
95+
padding: 0 40px;
96+
}
97+
98+
.code-block-diff-add-line::before {
99+
position: absolute;
100+
left: 8px;
101+
padding-right: 8px;
102+
content: '+';
103+
}
104+
105+
.code-block-diff-remove-line {
106+
background-color: #ffebe9;
107+
display: block;
108+
margin: 0 -40px;
109+
padding: 0 40px;
110+
}
111+
112+
.code-block-diff-remove-line::before {
113+
position: absolute;
114+
left: 8px;
115+
padding-right: 8px;
116+
content: '-';
117+
}
118+
119+
/**
120+
* use magic comments to mark diff blocks
121+
*/
122+
pre code:has(.code-block-diff-add-line) {
123+
padding-left: 40px!important;
124+
}
125+
126+
pre code:has(.code-block-diff-remove-line) {
127+
padding-left: 40px!important;
128+
}
129+
130+
[data-theme="dark"] pre code .token-line.code-block-diff-add-line {
131+
background-color: #4A5827;
132+
}
133+
[data-theme="dark"] pre code .token-line.code-block-diff-remove-line {
134+
background-color: #542936;
135+
}
136+
/* Code diff highlighting end */

0 commit comments

Comments
 (0)