back interdiff of round #3 and #2

improve code blocks in markdown (syntax highlighting and copy-to-clipboard button) #145

closed
opened by gwen.works targeting master from gwen.works/core: copycodeblocks

right now the button's text gets added without the around it. can't figure out why. am i missing sth obvious ?

ERROR
go.mod

Failed to calculate interdiff for this file.

ERROR
go.sum

Failed to calculate interdiff for this file.

ERROR
appview/pages/funcmap.go

Failed to calculate interdiff for this file.

ERROR
appview/pages/pages.go

Failed to calculate interdiff for this file.

ERROR
input.css

Failed to calculate interdiff for this file.

REVERTED
appview/pages/markup/markdown.go
··· 20 20 "github.com/yuin/goldmark/text" 21 21 "github.com/yuin/goldmark/util" 22 22 htmlparse "golang.org/x/net/html" 23 - "golang.org/x/net/html/atom" 24 23 25 24 "tangled.sh/tangled.sh/core/appview/pages/repoinfo" 26 25 ) ··· 154 153 } 155 154 } 156 155 157 - if node.Data == "pre" { 158 - // TODO only show when :hover or :focus on the pre element 159 - button := &htmlparse.Node{ 160 - Type: htmlparse.ElementNode, 161 - DataAtom: atom.Button, 162 - Data: "button", 163 - Attr: []htmlparse.Attribute{ 164 - { 165 - Key: "class", 166 - Val: "absolute top-2 right-2 btn", 167 - }, 168 - { 169 - Key: "style", 170 - // FIXME .#watch-tailwind doesnt seem to catch top-2 and right-2, probably cuz it's not used anywhere inside of templates/ ? 171 - Val: "top: 0.5rem; right: 0.5rem;", 172 - }, 173 - { 174 - Key: "onclick", 175 - Val: ` 176 - navigator.clipboard.writeText(this.closest('pre').querySelector('code').innerText); 177 - this.innerText = 'Copied!'; 178 - setTimeout(() => { this.innerText = 'Copy' }, 1500); 179 - `, 180 - }, 181 - { 182 - Key: "onload", 183 - Val: "this.removeAttribute('aria-hidden')", 184 - }, 185 - { 186 - Key: "aria-hidden", 187 - Val: "true", 188 - }, 189 - { 190 - Key: "title", 191 - Val: "Copy to clipboard", 192 - }, 193 - }, 194 - } 195 - 196 - // TODO 197 - // if copyIcon, err := icons.IconNode("copy", "h-4", "w-4"); err != nil { 198 - // button.AppendChild(copyIcon) 199 - // } else { 200 - button.AppendChild(&htmlparse.Node{ 201 - Type: htmlparse.TextNode, 202 - Data: "Copy", 203 - }) 204 - 205 - var classWasSetOnNode bool 206 - for i, attr := range node.Attr { 207 - if attr.Key == "class" { 208 - node.Attr[i].Val += " relative" 209 - classWasSetOnNode = true 210 - break 211 - } 212 - } 213 - 214 - if !classWasSetOnNode { 215 - node.Attr = append(node.Attr, htmlparse.Attribute{ 216 - Key: "class", 217 - Val: "relative", 218 - }) 219 - } 220 - 221 - node.AppendChild(button) 222 - } 223 - 224 156 for n := node.FirstChild; n != nil; n = n.NextSibling { 225 157 visitNode(ctx, n) 226 158 }