diff --git a/modules/markup/csv/csv.go b/modules/markup/csv/csv.go index 077947e77442..1e3acc9b47e2 100644 --- a/modules/markup/csv/csv.go +++ b/modules/markup/csv/csv.go @@ -9,12 +9,18 @@ import ( "encoding/csv" "html" "io" + "regexp" + "strings" "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/util" ) +var quoteRegexp = regexp.MustCompile(`["'][\s\S]+?["']`) + func init() { markup.RegisterParser(Parser{}) + } // Parser implements markup.Parser for orgmode @@ -28,12 +34,13 @@ func (Parser) Name() string { // Extensions implements markup.Parser func (Parser) Extensions() []string { - return []string{".csv"} + return []string{".csv", ".tsv"} } // Render implements markup.Parser -func (Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte { +func (p Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte { rd := csv.NewReader(bytes.NewReader(rawBytes)) + rd.Comma = p.bestDelimiter(rawBytes) var tmpBlock bytes.Buffer tmpBlock.WriteString(`
a |
1 | 2 |
<br/> |
a |
1 | 2 |
1 | 2 |
1 | 2 |
1 | 2 |
1,2,3 | 4,5,6 | 7,8,9 |
a | b | c |
1,2,3,4 | a\nb |
c | d |
<br/> |