Skip to content

Instantly share code, notes, and snippets.

@wjkoh
Created June 16, 2024 11:21
Show Gist options
  • Save wjkoh/c84d6996145bcc9e1556e69d5babd01c to your computer and use it in GitHub Desktop.
Save wjkoh/c84d6996145bcc9e1556e69d5babd01c to your computer and use it in GitHub Desktop.
package main
import(
"regexp"
)
var(
pageRe *regexp.Regexp = regexp.MustCompile(`\bp.\s*(\d+)\b`)
pagesRe *regexp.Regexp = regexp.MustCompile(`\bpp.\s*(\d+)-(\d+)\b`)
)
func linkPageNumbers(input string, pdfUrl string) string {
link := fmt.Sprintf("[${0}](%s#page=${1})", pdfUrl)
return pagesRe.ReplaceAllString(
pageRe.ReplaceAllString(input, link),
link,
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment