censorbib/src/decode.go
Philipp Winter 4be5f7bfb2 Add new build tool.
bibliogra.py requires Python 2, which is a pain to deal with.  This
commit adds a Go tool that compiles CensorBib from BibTeX to HTML.  The
tool does the bare minimum and is quite strict in the BibTeX format it
expects.
2024-03-10 12:08:10 -05:00

55 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"log"
"strings"
)
type conversion struct {
from string
to string
}
func decodeTitle(title string) string {
for _, convert := range []conversion{
{`\#`, "#"},
{`--`, ``},
{"``", "“"},
{"''", "”"},
{"'", ""}, // U+2019
{`$\cdot$`, `·`}, // U+00B7.
} {
title = strings.Replace(title, convert.from, convert.to, -1)
}
// Get rid of all curly brackets. We're displaying titles without changing
// their casing.
title = strings.ReplaceAll(title, "{", "")
title = strings.ReplaceAll(title, "}", "")
return title
}
func decodeAuthors(authors string) string {
for _, convert := range []conversion{
{"'", ""},
} {
authors = strings.Replace(authors, convert.from, convert.to, -1)
}
// For simplicity, we expect authors to be formatted as "John Doe" instead
// of "Doe, John".
if strings.Contains(authors, ",") {
log.Fatalf("author %q contains a comma", authors)
}
authorSlice := strings.Split(authors, " and ")
return strings.Join(authorSlice, ", ")
}
func decodeProceedings(proceedings string) string {
for _, convert := range []conversion{
{`\&`, "&"},
} {
proceedings = strings.Replace(proceedings, convert.from, convert.to, -1)
}
return proceedings
}