Skip to content

Commit cbb2ea9

Browse files
committed
Preserve spaces when copying.
1 parent 62f0983 commit cbb2ea9

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

internal/explore/render.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
cosignPointee = `application/vnd.dev.ggcr.magic/cosign-thing+json`
2626
emptyDigest = "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
2727
hcsshim = `https://github.com/microsoft/hcsshim/blob/main/osversion/windowsbuilds.go`
28+
indent = "\u00a0\u00a0" // non-breaking spaces for copyable indentation
2829
)
2930

3031
type jsonOutputter struct {
@@ -168,7 +169,7 @@ func (w *jsonOutputter) EndMap() {
168169
}
169170
w.pop()
170171
w.newline()
171-
w.Print(w.tabs() + "}")
172+
w.Printf("<span class=\"cp\">%s</span>}", w.tabs())
172173
w.key = false
173174
w.name = ""
174175
w.unfresh()
@@ -188,7 +189,7 @@ func (w *jsonOutputter) EndArray() {
188189
}
189190
w.pop()
190191
w.newline()
191-
w.Print(w.tabs() + "]")
192+
w.Printf("<span class=\"cp\">%s</span>]", w.tabs())
192193
w.key = false
193194
w.unfresh()
194195
}
@@ -223,14 +224,13 @@ func (w *jsonOutputter) Fresh() bool {
223224
}
224225

225226
func (w *jsonOutputter) push() {
226-
w.Print(w.tabs() + `<div class="indent">` + "\n")
227+
w.Print(`<div class="indent">` + "\n")
227228
w.fresh = append(w.fresh, true)
228229
}
229230

230231
func (w *jsonOutputter) pop() {
231232
w.fresh = w.fresh[:len(w.fresh)-1]
232233
w.newline()
233-
w.Print(w.tabs())
234234
w.undiv()
235235
}
236236

@@ -280,15 +280,15 @@ func (w *jsonOutputter) maybeMap(k string) string {
280280
}
281281

282282
func (w *jsonOutputter) tabs() string {
283-
return strings.Repeat(" ", len(w.fresh))
283+
return strings.Repeat(indent, len(w.fresh))
284284
}
285285

286286
func (w *jsonOutputter) newline() {
287287
w.Print("\n")
288288
}
289289

290290
func (w *jsonOutputter) div() {
291-
w.Print(w.tabs() + "<div>")
291+
w.Print("<div><span class=\"cp\">" + w.tabs() + "</span>")
292292
}
293293

294294
func (w *jsonOutputter) undiv() {

internal/explore/templates.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ pre {
249249
margin-left: 2em;
250250
}
251251
252+
.cp {
253+
font-size: 0;
254+
}
255+
252256
.noselect {
253257
user-select: none;
254258
-webkit-user-select: none;

0 commit comments

Comments
 (0)