|
7 | 7 | "bufio"
|
8 | 8 | "html"
|
9 | 9 | "io"
|
| 10 | + "net/url" |
10 | 11 | "regexp"
|
11 | 12 | "strconv"
|
12 | 13 |
|
@@ -39,8 +40,6 @@ func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
|
39 | 40 | {Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`data-table`)},
|
40 | 41 | {Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
|
41 | 42 | {Element: "td", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
|
42 |
| - {Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(`tw-flex tw-justify-center tw-items-center tw-py-4 tw-text-14`)}, |
43 |
| - {Element: "a", AllowAttr: "href", Regexp: regexp.MustCompile(``)}, |
44 | 43 | }
|
45 | 44 | }
|
46 | 45 |
|
@@ -134,10 +133,19 @@ func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.W
|
134 | 133 |
|
135 | 134 | // Check if maxRows or maxSize is reached, and if true, warn.
|
136 | 135 | if (row >= maxRows && maxRows != 0) || (rd.InputOffset() >= maxSize && maxSize != 0) {
|
137 |
| - locale := ctx.Ctx.Value(translation.ContextKey).(translation.Locale) |
| 136 | + warn := `<table class="data-table"><tr><td>` |
| 137 | + raw_link := ` <a href="` + ctx.Links.RawLink() + `/` + url.PathEscape(ctx.RelativePath) + `">` |
| 138 | + |
| 139 | + // Try to get the user translation |
| 140 | + if locale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale); ok { |
| 141 | + warn += locale.TrString("repo.file_too_large") |
| 142 | + raw_link += locale.TrString("repo.file_view_raw") |
| 143 | + } else { |
| 144 | + warn += "The file is too large to be shown." |
| 145 | + raw_link += "View Raw" |
| 146 | + } |
138 | 147 |
|
139 |
| - // Construct the HTML string |
140 |
| - warn := `<div class="tw-flex tw-justify-center tw-items-center tw-py-4 tw-text-14"><div>` + locale.TrString("repo.file_too_large") + ` <a class="source" href="` + ctx.Links.RawLink() + `/` + ctx.RelativePath + `">` + locale.TrString("repo.file_view_raw") + `</a></div></div>` |
| 148 | + warn += raw_link + `</a></td></tr></table>` |
141 | 149 |
|
142 | 150 | // Write the HTML string to the output
|
143 | 151 | if _, err := tmpBlock.WriteString(warn); err != nil {
|
|
0 commit comments