[feature] Support markdown format for Account bio/note (#1037)

* [feature] Status format also controls bio format

* test
This commit is contained in:
Michael Manfre 2022-11-19 04:07:51 -05:00 committed by GitHub
commit 67106c9dc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 10 deletions

View file

@ -66,7 +66,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
account.NoteRaw = *form.Note
// Process note to generate a valid HTML representation
note, err := p.processNote(ctx, *form.Note, account.ID)
note, err := p.processNote(ctx, *form.Note, account)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err)
}
@ -241,13 +241,13 @@ func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHead
return processingMedia.LoadAttachment(ctx)
}
func (p *processor) processNote(ctx context.Context, note string, accountID string) (string, error) {
func (p *processor) processNote(ctx context.Context, note string, account *gtsmodel.Account) (string, error) {
if note == "" {
return "", nil
}
tagStrings := util.DeriveHashtagsFromText(note)
tags, err := p.db.TagStringsToTags(ctx, tagStrings, accountID)
tags, err := p.db.TagStringsToTags(ctx, tagStrings, account.ID)
if err != nil {
return "", err
}
@ -255,7 +255,7 @@ func (p *processor) processNote(ctx context.Context, note string, accountID stri
mentionStrings := util.DeriveMentionNamesFromText(note)
mentions := []*gtsmodel.Mention{}
for _, mentionString := range mentionStrings {
mention, err := p.parseMention(ctx, mentionString, accountID, "")
mention, err := p.parseMention(ctx, mentionString, account.ID, "")
if err != nil {
continue
}
@ -266,5 +266,9 @@ func (p *processor) processNote(ctx context.Context, note string, accountID stri
// emojiStrings := util.DeriveEmojisFromText(note)
// emojis, err := p.db.EmojiStringsToEmojis(ctx, emojiStrings)
if account.StatusFormat == "markdown" {
return p.formatter.FromMarkdown(ctx, note, mentions, tags, nil), nil
}
return p.formatter.FromPlain(ctx, note, mentions, tags), nil
}