-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed markdown parser to as markdown didnt match gitlab. #721
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
package daemon | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/yuin/goldmark/renderer/html" | ||
|
||
pb "github.com/aau-network-security/haaukins/daemon/proto" | ||
eproto "github.com/aau-network-security/haaukins/exercise/ex-proto" | ||
"github.com/aau-network-security/haaukins/store" | ||
storeProto "github.com/aau-network-security/haaukins/store/proto" | ||
"github.com/golang/protobuf/jsonpb" | ||
"github.com/golang/protobuf/proto" | ||
"github.com/gomarkdown/markdown" | ||
"github.com/gomarkdown/markdown/parser" | ||
"github.com/microcosm-cc/bluemonday" | ||
"github.com/rs/zerolog/log" | ||
"github.com/yuin/goldmark" | ||
) | ||
|
||
func (d *daemon) ListCategories(ctx context.Context, req *pb.Empty) (*pb.ListCategoriesResponse, error) { | ||
|
@@ -45,11 +47,16 @@ func (d *daemon) ListCategories(ctx context.Context, req *pb.Empty) (*pb.ListCat | |
|
||
for _, c := range cats { | ||
// Render markdown from orgdescription to html | ||
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.HardLineBreak | ||
parser := parser.NewWithExtensions(extensions) | ||
|
||
md := []byte(c.CatDescription) | ||
unsafeHtml := markdown.ToHTML(md, parser, nil) | ||
var buf bytes.Buffer | ||
renderer := goldmark.New( | ||
goldmark.WithRendererOptions(html.WithUnsafe()), | ||
) | ||
if err := renderer.Convert(md, &buf); err != nil { | ||
log.Error().Msgf("Error converting to commonmark: %s", err) | ||
} | ||
unsafeHtml := buf.Bytes() | ||
Comment on lines
+52
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's make this part as function and just call it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha im so stupid, i'll do that as soon i get time! :D |
||
|
||
//Sanitizing unsafe HTML with bluemonday | ||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafeHtml) | ||
|
@@ -121,11 +128,15 @@ func (d *daemon) ListExercises(ctx context.Context, req *pb.Empty) (*pb.ListExer | |
} | ||
|
||
// Render markdown from orgdescription to html | ||
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.HardLineBreak | ||
parser := parser.NewWithExtensions(extensions) | ||
|
||
md := []byte(e.OrgDescription) | ||
unsafeHtml := markdown.ToHTML(md, parser, nil) | ||
var buf bytes.Buffer | ||
renderer := goldmark.New( | ||
goldmark.WithRendererOptions(html.WithUnsafe()), | ||
) | ||
if err := renderer.Convert(md, &buf); err != nil { | ||
log.Error().Msgf("Error converting to commonmark: %s", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comments |
||
} | ||
unsafeHtml := buf.Bytes() | ||
|
||
//Sanitizing unsafe HTML with bluemonday | ||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafeHtml) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package amigo | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"sort" | ||
"time" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/yuin/goldmark" | ||
"github.com/yuin/goldmark/renderer/html" | ||
|
||
"github.com/aau-network-security/haaukins/store" | ||
"github.com/gomarkdown/markdown" | ||
"github.com/gomarkdown/markdown/parser" | ||
"github.com/microcosm-cc/bluemonday" | ||
) | ||
|
||
|
@@ -184,11 +187,15 @@ func (fd *FrontendData) initChallenges(teamId string) []byte { | |
} | ||
|
||
//Render markdown to HTML | ||
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.HardLineBreak | ||
parser := parser.NewWithExtensions(extensions) | ||
|
||
md := []byte(r.ChalInfo.TeamDescription) | ||
unsafeHtml := markdown.ToHTML(md, parser, nil) | ||
var buf bytes.Buffer | ||
renderer := goldmark.New( | ||
goldmark.WithRendererOptions(html.WithUnsafe()), | ||
) | ||
if err := renderer.Convert(md, &buf); err != nil { | ||
log.Error().Msgf("Error converting to commonmark: %s", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again log and errors shouldn't start with error |
||
} | ||
unsafeHtml := buf.Bytes() | ||
|
||
//Sanitizing unsafe HTML with bluemonday | ||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafeHtml) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the fields of the log package, might be nice if decided to do central logging for the distributed version later on as it makes it nicer to filter logs