mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-17 20:58:08 +02:00
parent
c4bec47e7d
commit
e27f19c12f
@ -77,56 +77,55 @@ func (d *httpBodyContentTyper) Tokenise(options *TokeniseOptions, text string) (
|
||||
}
|
||||
|
||||
return func() Token {
|
||||
for token := it(); token != EOF; token = it() {
|
||||
switch {
|
||||
case token.Type == Name && strings.ToLower(token.Value) == "content-type":
|
||||
{
|
||||
isContentType = true
|
||||
}
|
||||
case token.Type == Literal && isContentType:
|
||||
{
|
||||
isContentType = false
|
||||
contentType = strings.TrimSpace(token.Value)
|
||||
pos := strings.Index(contentType, ";")
|
||||
if pos > 0 {
|
||||
contentType = strings.TrimSpace(contentType[:pos])
|
||||
}
|
||||
}
|
||||
case token.Type == Generic && contentType != "":
|
||||
{
|
||||
lexer := internal.MatchMimeType(contentType)
|
||||
|
||||
// application/calendar+xml can be treated as application/xml
|
||||
// if there's not a better match.
|
||||
if lexer == nil && strings.Contains(contentType, "+") {
|
||||
slashPos := strings.Index(contentType, "/")
|
||||
plusPos := strings.LastIndex(contentType, "+")
|
||||
contentType = contentType[:slashPos+1] + contentType[plusPos+1:]
|
||||
lexer = internal.MatchMimeType(contentType)
|
||||
}
|
||||
|
||||
if lexer == nil {
|
||||
token.Type = Text
|
||||
} else {
|
||||
subIterator, err = lexer.Tokenise(nil, token.Value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return EOF
|
||||
}
|
||||
}
|
||||
token := it()
|
||||
|
||||
if token == EOF {
|
||||
if subIterator != nil {
|
||||
return subIterator()
|
||||
}
|
||||
|
||||
return token
|
||||
return EOF
|
||||
}
|
||||
|
||||
if subIterator != nil {
|
||||
for token := subIterator(); token != EOF; token = subIterator() {
|
||||
return token
|
||||
switch {
|
||||
case token.Type == Name && strings.ToLower(token.Value) == "content-type":
|
||||
{
|
||||
isContentType = true
|
||||
}
|
||||
case token.Type == Literal && isContentType:
|
||||
{
|
||||
isContentType = false
|
||||
contentType = strings.TrimSpace(token.Value)
|
||||
pos := strings.Index(contentType, ";")
|
||||
if pos > 0 {
|
||||
contentType = strings.TrimSpace(contentType[:pos])
|
||||
}
|
||||
}
|
||||
case token.Type == Generic && contentType != "":
|
||||
{
|
||||
lexer := internal.MatchMimeType(contentType)
|
||||
|
||||
// application/calendar+xml can be treated as application/xml
|
||||
// if there's not a better match.
|
||||
if lexer == nil && strings.Contains(contentType, "+") {
|
||||
slashPos := strings.Index(contentType, "/")
|
||||
plusPos := strings.LastIndex(contentType, "+")
|
||||
contentType = contentType[:slashPos+1] + contentType[plusPos+1:]
|
||||
lexer = internal.MatchMimeType(contentType)
|
||||
}
|
||||
|
||||
if lexer == nil {
|
||||
token.Type = Text
|
||||
} else {
|
||||
subIterator, err = lexer.Tokenise(nil, token.Value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return EOF
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return EOF
|
||||
return token
|
||||
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user