Improve location displays
This commit is contained in:
@@ -37,14 +37,32 @@ Examples:
|
|||||||
if pageSection != "" {
|
if pageSection != "" {
|
||||||
idx := wiki.FindSectionIndex(page.Sections, pageSection)
|
idx := wiki.FindSectionIndex(page.Sections, pageSection)
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
|
needle := strings.ToLower(pageSection)
|
||||||
|
// Case-insensitive exact match
|
||||||
for _, s := range page.Sections {
|
for _, s := range page.Sections {
|
||||||
if strings.EqualFold(s.Line, pageSection) {
|
if strings.ToLower(s.Line) == needle {
|
||||||
i := 0
|
fmt.Sscanf(s.Index, "%d", &idx)
|
||||||
fmt.Sscanf(s.Index, "%d", &i)
|
|
||||||
idx = i
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Case-insensitive prefix match (e.g. "Location" → "Locations")
|
||||||
|
if idx == -1 {
|
||||||
|
for _, s := range page.Sections {
|
||||||
|
if strings.HasPrefix(strings.ToLower(s.Line), needle) {
|
||||||
|
fmt.Sscanf(s.Index, "%d", &idx)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Case-insensitive contains match
|
||||||
|
if idx == -1 {
|
||||||
|
for _, s := range page.Sections {
|
||||||
|
if strings.Contains(strings.ToLower(s.Line), needle) {
|
||||||
|
fmt.Sscanf(s.Index, "%d", &idx)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
return fmt.Errorf("section %q not found. Available sections: %s",
|
return fmt.Errorf("section %q not found. Available sections: %s",
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ func CleanWikitext(s string) string {
|
|||||||
// ExtractPlainText strips all wikitext markup to produce plain text.
|
// ExtractPlainText strips all wikitext markup to produce plain text.
|
||||||
func ExtractPlainText(wikitext string) string {
|
func ExtractPlainText(wikitext string) string {
|
||||||
s := wikitext
|
s := wikitext
|
||||||
// Remove templates (simplified — just removes {{ ... }} at depth 0)
|
s = expandKnownTemplates(s)
|
||||||
s = removeTemplates(s)
|
s = removeTemplates(s)
|
||||||
s = cleanWikiLinks(s)
|
s = cleanWikiLinks(s)
|
||||||
s = strings.ReplaceAll(s, "'''", "")
|
s = strings.ReplaceAll(s, "'''", "")
|
||||||
@@ -322,6 +322,51 @@ func tryExpandTemplate(inner string) (string, bool) {
|
|||||||
if len(parts) >= 2 {
|
if len(parts) >= 2 {
|
||||||
return strings.TrimSpace(parts[1]) + " coins", true
|
return strings.TrimSpace(parts[1]) + " coins", true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "loctablehead", "loctablebottom":
|
||||||
|
return "", true
|
||||||
|
|
||||||
|
case "locline":
|
||||||
|
paramMap := map[string]string{}
|
||||||
|
for _, p := range parts[1:] {
|
||||||
|
if idx := strings.Index(p, "="); idx > 0 {
|
||||||
|
k := strings.ToLower(strings.TrimSpace(p[:idx]))
|
||||||
|
v := cleanWikiLinks(strings.TrimSpace(p[idx+1:]))
|
||||||
|
paramMap[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Support both OSRS (location/levels/members) and RS3 (loc/lvls/mem) param names
|
||||||
|
locVal := paramMap["location"]
|
||||||
|
if locVal == "" {
|
||||||
|
locVal = paramMap["loc"]
|
||||||
|
}
|
||||||
|
lvlVal := paramMap["levels"]
|
||||||
|
if lvlVal == "" {
|
||||||
|
lvlVal = paramMap["lvls"]
|
||||||
|
}
|
||||||
|
memVal := paramMap["members"]
|
||||||
|
if memVal == "" {
|
||||||
|
memVal = paramMap["mem"]
|
||||||
|
}
|
||||||
|
|
||||||
|
var segments []string
|
||||||
|
if locVal != "" {
|
||||||
|
segments = append(segments, locVal)
|
||||||
|
}
|
||||||
|
if lvlVal != "" {
|
||||||
|
segments = append(segments, "level "+lvlVal)
|
||||||
|
}
|
||||||
|
if memVal != "" {
|
||||||
|
if strings.EqualFold(memVal, "yes") {
|
||||||
|
segments = append(segments, "members only")
|
||||||
|
} else {
|
||||||
|
segments = append(segments, "F2P")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(segments) == 0 {
|
||||||
|
return "", true
|
||||||
|
}
|
||||||
|
return "\n- " + strings.Join(segments, ", "), true
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
@@ -477,15 +522,23 @@ func removeFileRefs(s string) string {
|
|||||||
func collapseWhitespace(s string) string {
|
func collapseWhitespace(s string) string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
prevSpace := false
|
prevSpace := false
|
||||||
|
prevNewline := false
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
if unicode.IsSpace(r) {
|
if r == '\n' {
|
||||||
if !prevSpace {
|
if !prevNewline {
|
||||||
|
b.WriteRune('\n')
|
||||||
|
}
|
||||||
|
prevNewline = true
|
||||||
|
prevSpace = false
|
||||||
|
} else if unicode.IsSpace(r) {
|
||||||
|
if !prevSpace && !prevNewline {
|
||||||
b.WriteRune(' ')
|
b.WriteRune(' ')
|
||||||
}
|
}
|
||||||
prevSpace = true
|
prevSpace = true
|
||||||
} else {
|
} else {
|
||||||
b.WriteRune(r)
|
b.WriteRune(r)
|
||||||
prevSpace = false
|
prevSpace = false
|
||||||
|
prevNewline = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b.String()
|
return b.String()
|
||||||
|
|||||||
Reference in New Issue
Block a user