mirror of
https://github.com/NullHypothesis/censorbib.git
synced 2025-07-22 14:10:55 -04:00

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.
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
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
|
||
}
|