Created
June 16, 2024 11:21
-
-
Save wjkoh/c84d6996145bcc9e1556e69d5babd01c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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