tenseleyflow/shithub / a3db03d

Browse files

S25: refactor S17/S21/S22/S23/S24 callers onto canonical pipeline; drop interim internal/repos/markdown

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
a3db03d033b6963b66c4de0469e7aa31d6db762b
Parents
be5f355
Tree
abdab08

7 changed files

StatusFile+-
M internal/issues/issues.go 1 1
M internal/pulls/pulls.go 1 1
M internal/pulls/review/comment.go 1 1
M internal/pulls/review/submit.go 1 1
D internal/repos/markdown/render.go 0 67
M internal/web/handlers/repo/code.go 1 1
M internal/web/handlers/repo/pulls.go 1 1
internal/issues/issues.gomodified
@@ -23,7 +23,7 @@ import (
2323
 
2424
 	"github.com/tenseleyFlow/shithub/internal/auth/throttle"
2525
 	issuesdb "github.com/tenseleyFlow/shithub/internal/issues/sqlc"
26
-	mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown"
26
+	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
2727
 )
2828
 
2929
 // Deps wires this package against the rest of the runtime. Pool is
internal/pulls/pulls.gomodified
@@ -34,7 +34,7 @@ import (
3434
 	"github.com/tenseleyFlow/shithub/internal/pulls/review"
3535
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
3636
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
37
-	mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown"
37
+	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
3838
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
3939
 )
4040
 
internal/pulls/review/comment.gomodified
@@ -12,7 +12,7 @@ import (
1212
 	"github.com/jackc/pgx/v5/pgtype"
1313
 
1414
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
15
-	mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown"
15
+	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
1616
 )
1717
 
1818
 // CommentParams describes a single inline comment on a PR. When
internal/pulls/review/submit.gomodified
@@ -13,7 +13,7 @@ import (
1313
 
1414
 	issuesdb "github.com/tenseleyFlow/shithub/internal/issues/sqlc"
1515
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
16
-	mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown"
16
+	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
1717
 )
1818
 
1919
 // SubmitParams describes the submit-a-review action.
internal/repos/markdown/render.godeleted
@@ -1,67 +0,0 @@
1
-// SPDX-License-Identifier: AGPL-3.0-or-later
2
-
3
-// Package markdown wraps Goldmark + bluemonday for safe README
4
-// rendering. S25 will broaden this with auto-mention, issue-ref
5
-// linking, and cross-repo extensions; S17 ships only what's needed
6
-// for tree-page README rendering.
7
-package markdown
8
-
9
-import (
10
-	"bytes"
11
-
12
-	"github.com/microcosm-cc/bluemonday"
13
-	"github.com/yuin/goldmark"
14
-	"github.com/yuin/goldmark/extension"
15
-	"github.com/yuin/goldmark/parser"
16
-	"github.com/yuin/goldmark/renderer/html"
17
-)
18
-
19
-// gm is the shared Goldmark instance. CommonMark + GFM (tables,
20
-// strikethrough, autolinks, task-list) + auto-heading-id for in-page
21
-// anchors. We deliberately do NOT enable HTML passthrough; raw HTML
22
-// in user content is escaped.
23
-var gm = goldmark.New(
24
-	goldmark.WithExtensions(
25
-		extension.GFM,
26
-		extension.Footnote,
27
-	),
28
-	goldmark.WithParserOptions(parser.WithAutoHeadingID()),
29
-	goldmark.WithRendererOptions(
30
-		html.WithHardWraps(),
31
-		html.WithXHTML(),
32
-	),
33
-)
34
-
35
-// sanitizer is bluemonday's UGC policy with two adjustments:
36
-//   - allow class attributes on `<code>` (Goldmark emits language-foo)
37
-//   - allow `id` on headings so anchor links work
38
-//
39
-// Anything Goldmark emits passes through; anything user-injected via
40
-// raw HTML in markdown gets stripped because Goldmark didn't enable
41
-// HTML rendering in the first place. Defense in depth.
42
-var sanitizer = func() *bluemonday.Policy {
43
-	p := bluemonday.UGCPolicy()
44
-	p.AllowAttrs("class").Matching(bluemonday.SpaceSeparatedTokens).OnElements("code", "pre", "span")
45
-	p.AllowAttrs("id").OnElements("h1", "h2", "h3", "h4", "h5", "h6")
46
-	// Disallow remote images outright; readme images normally live in
47
-	// the same repo and resolve to /raw/ which we control. Users who
48
-	// want external images can paste links instead.
49
-	p.AllowImages()
50
-	return p
51
-}()
52
-
53
-// RenderHTML returns sanitized HTML for the given markdown bytes.
54
-// Empty input returns an empty string. The output is suitable for
55
-// inserting into a template via `{{ . | safeHTML }}` — every byte has
56
-// passed bluemonday.
57
-func RenderHTML(src []byte) (string, error) {
58
-	if len(src) == 0 {
59
-		return "", nil
60
-	}
61
-	var buf bytes.Buffer
62
-	if err := gm.Convert(src, &buf); err != nil {
63
-		return "", err
64
-	}
65
-	clean := sanitizer.SanitizeBytes(buf.Bytes())
66
-	return string(clean), nil
67
-}
internal/web/handlers/repo/code.gomodified
@@ -18,7 +18,7 @@ import (
1818
 	"github.com/tenseleyFlow/shithub/internal/repos/finder"
1919
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
2020
 	"github.com/tenseleyFlow/shithub/internal/repos/highlight"
21
-	mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown"
21
+	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
2222
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
2323
 	"github.com/tenseleyFlow/shithub/internal/web/middleware"
2424
 )
internal/web/handlers/repo/pulls.gomodified
@@ -21,7 +21,7 @@ import (
2121
 	"github.com/tenseleyFlow/shithub/internal/pulls"
2222
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
2323
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
24
-	mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown"
24
+	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
2525
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
2626
 	"github.com/tenseleyFlow/shithub/internal/web/middleware"
2727
 	"github.com/tenseleyFlow/shithub/internal/worker"