Skip to content

Commit e4b01e5

Browse files
Merge branch 'main' into pacman-packages
2 parents 381fa6b + 3bd87fb commit e4b01e5

File tree

16 files changed

+265
-18
lines changed

16 files changed

+265
-18
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ generate-gitignore:
969969

970970
.PHONY: generate-images
971971
generate-images: | node_modules
972-
npm install --no-save fabric@6.0.0-beta20 imagemin-zopfli@7
972+
npm install --no-save fabric@6 imagemin-zopfli@7
973973
node tools/generate-images.js $(TAGS)
974974

975975
.PHONY: generate-manpage

models/auth/webauthn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func DeleteCredential(ctx context.Context, id, userID int64) (bool, error) {
181181
return had > 0, err
182182
}
183183

184-
// WebAuthnCredentials implementns the webauthn.User interface
184+
// WebAuthnCredentials implements the webauthn.User interface
185185
func WebAuthnCredentials(ctx context.Context, userID int64) ([]webauthn.Credential, error) {
186186
dbCreds, err := GetWebAuthnCredentialsByUID(ctx, userID)
187187
if err != nil {

modules/auth/webauthn/webauthn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Init() {
3131
RPID: setting.Domain,
3232
RPOrigins: []string{appURL},
3333
AuthenticatorSelection: protocol.AuthenticatorSelection{
34-
UserVerification: "discouraged",
34+
UserVerification: protocol.VerificationDiscouraged,
3535
},
3636
AttestationPreference: protocol.PreferDirectAttestation,
3737
},
@@ -66,7 +66,7 @@ func (u *User) WebAuthnIcon() string {
6666
return (*user_model.User)(u).AvatarLink(db.DefaultContext)
6767
}
6868

69-
// WebAuthnCredentials implementns the webauthn.User interface
69+
// WebAuthnCredentials implements the webauthn.User interface
7070
func (u *User) WebAuthnCredentials() []webauthn.Credential {
7171
dbCreds, err := auth.GetWebAuthnCredentialsByUID(db.DefaultContext, u.ID)
7272
if err != nil {

modules/markup/markdown/markdown_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ func TestMathBlock(t *testing.T) {
555555
"$a$ ($b$) [$c$] {$d$}",
556556
`<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [$c$] {$d$}</p>` + nl,
557557
},
558+
{
559+
"$$a$$ test",
560+
`<p><code class="language-math display is-loading">a</code> test</p>` + nl,
561+
},
562+
{
563+
"test $$a$$",
564+
`<p>test <code class="language-math display is-loading">a</code></p>` + nl,
565+
},
558566
}
559567

560568
for _, test := range testcases {

modules/markup/markdown/math/block_parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func (b *blockParser) Open(parent ast.Node, reader text.Reader, pc parser.Contex
5353
}
5454
idx := bytes.Index(line[pos+2:], endBytes)
5555
if idx >= 0 {
56+
// for case $$ ... $$ any other text
57+
for i := pos + idx + 4; i < len(line); i++ {
58+
if line[i] != ' ' && line[i] != '\n' {
59+
return nil, parser.NoChildren
60+
}
61+
}
5662
segment.Stop = segment.Start + idx + 2
5763
reader.Advance(segment.Len() - 1)
5864
segment.Start += 2
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package math
5+
6+
import (
7+
"github.com/yuin/goldmark/ast"
8+
)
9+
10+
// InlineBlock represents inline math e.g. $$...$$
11+
type InlineBlock struct {
12+
Inline
13+
}
14+
15+
// InlineBlock implements InlineBlock.
16+
func (n *InlineBlock) InlineBlock() {}
17+
18+
// KindInlineBlock is the kind for math inline block
19+
var KindInlineBlock = ast.NewNodeKind("MathInlineBlock")
20+
21+
// Kind returns KindInlineBlock
22+
func (n *InlineBlock) Kind() ast.NodeKind {
23+
return KindInlineBlock
24+
}
25+
26+
// NewInlineBlock creates a new ast math inline block node
27+
func NewInlineBlock() *InlineBlock {
28+
return &InlineBlock{
29+
Inline{},
30+
}
31+
}

modules/markup/markdown/math/inline_parser.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ var defaultInlineDollarParser = &inlineParser{
2121
end: []byte{'$'},
2222
}
2323

24+
var defaultDualDollarParser = &inlineParser{
25+
start: []byte{'$', '$'},
26+
end: []byte{'$', '$'},
27+
}
28+
2429
// NewInlineDollarParser returns a new inline parser
2530
func NewInlineDollarParser() parser.InlineParser {
2631
return defaultInlineDollarParser
2732
}
2833

34+
func NewInlineDualDollarParser() parser.InlineParser {
35+
return defaultDualDollarParser
36+
}
37+
2938
var defaultInlineBracketParser = &inlineParser{
3039
start: []byte{'\\', '('},
3140
end: []byte{'\\', ')'},
@@ -38,7 +47,7 @@ func NewInlineBracketParser() parser.InlineParser {
3847

3948
// Trigger triggers this parser on $ or \
4049
func (parser *inlineParser) Trigger() []byte {
41-
return parser.start[0:1]
50+
return parser.start
4251
}
4352

4453
func isPunctuation(b byte) bool {
@@ -88,7 +97,11 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
8897
break
8998
}
9099
suceedingCharacter := line[pos]
91-
if !isPunctuation(suceedingCharacter) && !(suceedingCharacter == ' ') && !isBracket(suceedingCharacter) {
100+
// check valid ending character
101+
if !isPunctuation(suceedingCharacter) &&
102+
!(suceedingCharacter == ' ') &&
103+
!(suceedingCharacter == '\n') &&
104+
!isBracket(suceedingCharacter) {
92105
return nil
93106
}
94107
if line[ender-1] != '\\' {
@@ -101,12 +114,21 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
101114

102115
block.Advance(opener)
103116
_, pos := block.Position()
104-
node := NewInline()
117+
var node ast.Node
118+
if parser == defaultDualDollarParser {
119+
node = NewInlineBlock()
120+
} else {
121+
node = NewInline()
122+
}
105123
segment := pos.WithStop(pos.Start + ender - opener)
106124
node.AppendChild(node, ast.NewRawTextSegment(segment))
107125
block.Advance(ender - opener + len(parser.end))
108126

109-
trimBlock(node, block)
127+
if parser == defaultDualDollarParser {
128+
trimBlock(&(node.(*InlineBlock)).Inline, block)
129+
} else {
130+
trimBlock(node.(*Inline), block)
131+
}
110132
return node
111133
}
112134

modules/markup/markdown/math/inline_renderer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ func NewInlineRenderer() renderer.NodeRenderer {
2121

2222
func (r *InlineRenderer) renderInline(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
2323
if entering {
24-
_, _ = w.WriteString(`<code class="language-math is-loading">`)
24+
extraClass := ""
25+
if _, ok := n.(*InlineBlock); ok {
26+
extraClass = "display "
27+
}
28+
_, _ = w.WriteString(`<code class="language-math ` + extraClass + `is-loading">`)
2529
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
2630
segment := c.(*ast.Text).Segment
2731
value := util.EscapeHTML(segment.Value(source))
@@ -43,4 +47,5 @@ func (r *InlineRenderer) renderInline(w util.BufWriter, source []byte, n ast.Nod
4347
// RegisterFuncs registers the renderer for inline math nodes
4448
func (r *InlineRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
4549
reg.Register(KindInline, r.renderInline)
50+
reg.Register(KindInlineBlock, r.renderInline)
4651
}

modules/markup/markdown/math/math.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ func (e *Extension) Extend(m goldmark.Markdown) {
9696
util.Prioritized(NewInlineBracketParser(), 501),
9797
}
9898
if e.parseDollarInline {
99-
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(), 501))
99+
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(), 503),
100+
util.Prioritized(NewInlineDualDollarParser(), 502))
100101
}
101102
m.Parser().AddOptions(parser.WithInlineParsers(inlines...))
102103

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ sspi_auth_failed = SSPI authentication failed
458458
password_pwned = The password you chose is on a <a target="_blank" rel="noopener noreferrer" href="https://haveibeenpwned.com/Passwords">list of stolen passwords</a> previously exposed in public data breaches. Please try again with a different password and consider changing this password elsewhere too.
459459
password_pwned_err = Could not complete request to HaveIBeenPwned
460460
last_admin = You cannot remove the last admin. There must be at least one admin.
461+
signin_passkey = Sign in with a passkey
461462
462463
[mail]
463464
view_it_on = View it on %s

0 commit comments

Comments
 (0)