Skip to content

Commit b1893ed

Browse files
committed
Hide the copy buttons on code snippets in book
This hides the copy buttons on code snippets, which should make literate code flow a bit better.
1 parent 59cb973 commit b1893ed

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

docs/book/theme/css/general.css

+11
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,14 @@ cite.literate-source > a::before {
456456
font-style: normal;
457457
color: var(--fg);
458458
}
459+
460+
/* hide the annoying "copy to clipboard" buttons */
461+
.literate pre > .buttons {
462+
display: none;
463+
}
464+
465+
/* add a bit of extra padding for readability */
466+
.literate pre code {
467+
padding-top: 0.75em;
468+
padding-bottom: 0.75em;
469+
}

docs/book/utils/litgo/literate.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ func (l Literate) extractContents(contents []byte, pathInfo filePathInfo) (strin
223223

224224
out := new(strings.Builder)
225225

226+
out.WriteString(`<div class="literate">`)
227+
226228
// write the source so that readers can easily find the code
227229
sourcePath := pathInfo.ViewablePath(*l.BaseSourcePath)
228230
prettyPath := pathInfo.chapterRelativePath
@@ -256,19 +258,15 @@ func (l Literate) extractContents(contents []byte, pathInfo filePathInfo) (strin
256258
}
257259
// TODO(directxman12): nice side-by-side sections
258260
}
261+
out.WriteString(`</div>`)
259262

260263
return out.String(), nil
261264
}
262265

263266
// wrapWithNewlines ensures that we begin and end with a newline character.
264267
func wrapWithNewlines(src string) string {
265-
if src[0] != '\n' {
266-
src = "\n" + src
267-
}
268-
if src[len(src)-1] != '\n' {
269-
src = src + "\n"
270-
}
271-
return src
268+
src = strings.Trim(src, "\n") // remove newlines first to avoid too many
269+
return "\n" + src + "\n"
272270
}
273271

274272
func main() {

0 commit comments

Comments
 (0)