MCPcopy
hub / github.com/syncthing/syncthing / parseCopyrightNotices

Function parseCopyrightNotices

script/copyrights.go:324–377  ·  view source on GitHub ↗
(input string)

Source from the content-addressed store, hash-verified

322}
323
324func parseCopyrightNotices(input string) []CopyrightNotice {
325 doc, err := html.Parse(strings.NewReader("<ul>" + input + "</ul>"))
326 if err != nil {
327 log.Fatal(err)
328 }
329
330 var notices []CopyrightNotice
331
332 typ := TypeJS
333
334 var f func(*html.Node)
335 f = func(n *html.Node) {
336 if n.Type == html.ElementNode && n.Data == "li" {
337 var notice CopyrightNotice
338 var aFound bool
339
340 for c := n.FirstChild; c != nil; c = c.NextSibling {
341 if c.Type == html.ElementNode && c.Data == "a" {
342 aFound = true
343 for _, attr := range c.Attr {
344 if attr.Key == "href" {
345 notice.URL = attr.Val
346 }
347 }
348 if c.FirstChild != nil && c.FirstChild.Type == html.TextNode {
349 notice.Name = strings.TrimSpace(c.FirstChild.Data)
350 }
351 } else if c.Type == html.TextNode && aFound {
352 // Anything after <a> is considered the copyright
353 notice.Copyright = strings.TrimSpace(html.UnescapeString(c.Data))
354 notice.Copyright = strings.Trim(notice.Copyright, "., ")
355 }
356 if typ == TypeJS && strings.Contains(notice.URL, "AudriusButkevicius") {
357 typ = TypeKeep
358 }
359 notice.Type = typ
360 var buf strings.Builder
361 _ = html.Render(&buf, n)
362 notice.HTML = buf.String()
363 }
364
365 notice.Copyright = strings.ReplaceAll(notice.Copyright, "©", "&copy;")
366 notice.HTML = strings.ReplaceAll(notice.HTML, "©", "&copy;")
367 notices = append(notices, notice)
368 }
369 for c := n.FirstChild; c != nil; c = c.NextSibling {
370 f(c)
371 }
372 }
373
374 f(doc)
375
376 return notices
377}
378
379func parseGitHubURL(u string) (string, string) {
380 parsed, err := url.Parse(u)

Callers 1

mainFunction · 0.85

Calls 4

ParseMethod · 0.80
FatalMethod · 0.80
ContainsMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected