Skip to content

Commit 91c32da

Browse files
committed
source code css
1 parent 0c11029 commit 91c32da

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

docs/src/.vitepress/theme/style.css

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pre, code {
5252
--vp-c-brand-dark: #535bf2;
5353
--vp-c-brand-darker: #454ce1;
5454
--vp-c-brand-dimm: #212425;
55-
--vp-tip-bg: rgb(254, 254, 254);
55+
--vp-tip-bg: rgb(224, 223, 223);
5656
/* Greens */
5757
--vp-dark-green: #155f3e; /* Main accent green */
5858
--vp-dark-green-dark: #2b855c;
@@ -69,12 +69,14 @@ pre, code {
6969
/* Text Colors */
7070
--vp-dark-text: #e5e5e5; /* Primary text color */
7171
--vp-dark-subtext: #c1c1c1; /* Subtle text */
72+
--vp-source-text: #e5e5e5;
7273

7374
/* Backgrounds */
7475
--vp-dark-bg: #121212; /* Main background */
7576
--vp-dark-bg-alt: #1a1a1a; /* Alternative background */
7677
--vp-dark-bg-dimm: #101010;
77-
78+
--vp-source-bg: #414040;
79+
7880
/* Borders */
7981
--vp-dark-border: #3b8a65;
8082
/* custom tip */
@@ -90,6 +92,7 @@ pre, code {
9092
}
9193

9294
:root.dark {
95+
--vp-source-bg: var(--vp-tip-bg);
9396
/* custom tip */
9497
--vp-custom-block-tip-border: var(--vp-dark-green-dark);
9598
--vp-custom-block-tip-text: var(--vp-dark-subtext);
@@ -113,6 +116,7 @@ pre, code {
113116
:root.dark {
114117
--vp-dark-link: var(--vp-dark-green-lighter);
115118
--vp-dark-link-hover: var(--vp-dark-green-light);
119+
--vp-source-text: #595c5f;
116120
}
117121

118122
/* Hero Section */
@@ -203,6 +207,7 @@ mjx-container > svg {
203207
.jldocstring.custom-block {
204208
border: 1px solid var(--vp-c-gray-2);
205209
color: var(--vp-c-text-1);
210+
overflow: hidden;
206211
}
207212

208213
.jldocstring.custom-block summary {
@@ -214,4 +219,30 @@ mjx-container > svg {
214219
.jldocstring.custom-block summary a {
215220
pointer-events: none;
216221
text-decoration: none;
222+
}
223+
224+
.jldocstring.custom-block .source-link {
225+
border-radius: 4px;
226+
text-decoration: none;
227+
background-color: var(--vp-source-bg);
228+
float: right;
229+
opacity: 0;
230+
visibility: hidden;
231+
transform: translateY(-5px);
232+
transition: all 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
233+
}
234+
235+
.jldocstring.custom-block .source-link a {
236+
text-decoration: none;
237+
color: var(--vp-source-text);
238+
}
239+
240+
.jldocstring.custom-block .source-link a:hover {
241+
text-decoration: underline;
242+
}
243+
244+
.jldocstring.custom-block:hover .source-link {
245+
opacity: 1;
246+
visibility: visible;
247+
transform: translateY(0);
217248
}

src/writer.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,7 @@ function renderdoc(io::IO, mime::MIME"text/plain", node::Documenter.MarkdownAST.
374374
if url !== nothing
375375
# This is how Documenter does it:
376376
# push!(ret.nodes, a[".docs-sourcelink", :target=>"_blank", :href=>url]("source"))
377-
# so clearly we should be inserting some form of HTML tag here,
378-
# and defining its rendering in CSS?
379-
# TODO: switch to Documenter style here
380-
println(io, "\n", "[source]($url)", "\n")
377+
println(io, "\n", """<Badge type="info" class="source-link" text="source"><a href="$url" target="_blank" rel="noreferrer">source</a></Badge>""", "\n")
381378
end
382379
end
383380
end

template/src/.vitepress/theme/style.css

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.VPHero .clip {
22
white-space: pre;
3-
max-width: 500px;
3+
max-width: 600px;
44
}
55

66
/* Fonts */
@@ -52,7 +52,7 @@ pre, code {
5252
--vp-c-brand-dark: #535bf2;
5353
--vp-c-brand-darker: #454ce1;
5454
--vp-c-brand-dimm: #212425;
55-
--vp-tip-bg: rgb(254, 254, 254);
55+
--vp-tip-bg: rgb(224, 223, 223);
5656
/* Greens */
5757
--vp-dark-green: #155f3e; /* Main accent green */
5858
--vp-dark-green-dark: #2b855c;
@@ -69,12 +69,14 @@ pre, code {
6969
/* Text Colors */
7070
--vp-dark-text: #e5e5e5; /* Primary text color */
7171
--vp-dark-subtext: #c1c1c1; /* Subtle text */
72+
--vp-source-text: #e5e5e5;
7273

7374
/* Backgrounds */
7475
--vp-dark-bg: #121212; /* Main background */
7576
--vp-dark-bg-alt: #1a1a1a; /* Alternative background */
7677
--vp-dark-bg-dimm: #101010;
77-
78+
--vp-source-bg: #414040;
79+
7880
/* Borders */
7981
--vp-dark-border: #3b8a65;
8082
/* custom tip */
@@ -90,6 +92,7 @@ pre, code {
9092
}
9193

9294
:root.dark {
95+
--vp-source-bg: var(--vp-tip-bg);
9396
/* custom tip */
9497
--vp-custom-block-tip-border: var(--vp-dark-green-dark);
9598
--vp-custom-block-tip-text: var(--vp-dark-subtext);
@@ -113,6 +116,7 @@ pre, code {
113116
:root.dark {
114117
--vp-dark-link: var(--vp-dark-green-lighter);
115118
--vp-dark-link-hover: var(--vp-dark-green-light);
119+
--vp-source-text: #595c5f;
116120
}
117121

118122
/* Hero Section */
@@ -203,6 +207,7 @@ mjx-container > svg {
203207
.jldocstring.custom-block {
204208
border: 1px solid var(--vp-c-gray-2);
205209
color: var(--vp-c-text-1);
210+
overflow: hidden;
206211
}
207212

208213
.jldocstring.custom-block summary {
@@ -214,4 +219,30 @@ mjx-container > svg {
214219
.jldocstring.custom-block summary a {
215220
pointer-events: none;
216221
text-decoration: none;
222+
}
223+
224+
.jldocstring.custom-block .source-link {
225+
border-radius: 4px;
226+
text-decoration: none;
227+
background-color: var(--vp-source-bg);
228+
float: right;
229+
opacity: 0;
230+
visibility: hidden;
231+
transform: translateY(-5px);
232+
transition: all 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
233+
}
234+
235+
.jldocstring.custom-block .source-link a {
236+
text-decoration: none;
237+
color: var(--vp-source-text);
238+
}
239+
240+
.jldocstring.custom-block .source-link a:hover {
241+
text-decoration: underline;
242+
}
243+
244+
.jldocstring.custom-block:hover .source-link {
245+
opacity: 1;
246+
visibility: visible;
247+
transform: translateY(0);
217248
}

0 commit comments

Comments
 (0)