Skip to content

Commit

Permalink
Hide the copy buttons on code snippets in book
Browse files Browse the repository at this point in the history
This hides the copy buttons on code snippets, which should make literate
code flow a bit better.
  • Loading branch information
DirectXMan12 committed Aug 9, 2019
1 parent 59cb973 commit b1893ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 11 additions & 0 deletions docs/book/theme/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,14 @@ cite.literate-source > a::before {
font-style: normal;
color: var(--fg);
}

/* hide the annoying "copy to clipboard" buttons */
.literate pre > .buttons {
display: none;
}

/* add a bit of extra padding for readability */
.literate pre code {
padding-top: 0.75em;
padding-bottom: 0.75em;
}
12 changes: 5 additions & 7 deletions docs/book/utils/litgo/literate.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func (l Literate) extractContents(contents []byte, pathInfo filePathInfo) (strin

out := new(strings.Builder)

out.WriteString(`<div class="literate">`)

// write the source so that readers can easily find the code
sourcePath := pathInfo.ViewablePath(*l.BaseSourcePath)
prettyPath := pathInfo.chapterRelativePath
Expand Down Expand Up @@ -256,19 +258,15 @@ func (l Literate) extractContents(contents []byte, pathInfo filePathInfo) (strin
}
// TODO(directxman12): nice side-by-side sections
}
out.WriteString(`</div>`)

return out.String(), nil
}

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

func main() {
Expand Down

0 comments on commit b1893ed

Please sign in to comment.