jsonresume/themes/tex/tex.go

153 lines
3.4 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.

/*
* Copyright (c) 2018 Arnaud Ysmal. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package tex
import (
"jsonresume/model"
"jsonresume/themes"
"path"
"strings"
"text/template"
)
const (
packageDirectory = "themes/tex"
fileTemplate = "resume_template.tex"
)
var Theme = themes.Theme{
Name: "tex",
Directory: packageDirectory,
Functions: template.FuncMap{"md2tex": md2tex},
}
func init() {
t, _ := Asset(path.Join(packageDirectory, fileTemplate))
Theme.Template = string(t)
(&Theme).Register()
}
type replacement struct {
o string
n string
}
var latexAccents = []replacement{
{"\\", "\\\\"},
{"{", "\\{"},
{"}", "\\}"},
{"à", "\\`a"},
{"è", "\\`e"},
{"ì", "\\`\\i"},
{"ò", "\\`o"},
{"ù", "\\`u"},
{"ỳ", "\\`y"},
{"À", "\\`A"},
{"È", "\\`E"},
{"Ì", "\\`\\I"},
{"Ò", "\\`O"},
{"Ù", "\\`U"},
{"Ỳ", "\\`Y"},
{"á", "\\'a"},
{"é", "\\'e"},
{"í", "\\'\\i"},
{"ó", "\\'o"},
{"ú", "\\'u"},
{"ý", "\\'y"},
{"Á", "\\'A"},
{"É", "\\'E"},
{"Í", "\\'\\I"},
{"Ó", "\\'O"},
{"Ú", "\\'U"},
{"Ý", "\\'Y"},
{"â", "\\^a"},
{"ê", "\\^e"},
{"î", "\\^\\i"},
{"ô", "\\^o"},
{"û", "\\^u"},
{"ŷ", "\\^y"},
{"Â", "\\^A"},
{"Ê", "\\^E"},
{"Î", "\\^\\I"},
{"Ô", "\\^O"},
{"Û", "\\^U"},
{"Ŷ", "\\^Y"},
{"ä", "\\\"a"},
{"ë", "\\\"e"},
{"ï", "\\\"\\i"},
{"ö", "\\\"o"},
{"ü", "\\\"u"},
{"ÿ", "\\\"y"},
{"Ä", "\\\"A"},
{"Ë", "\\\"E"},
{"Ï", "\\\"\\I"},
{"Ö", "\\\"O"},
{"Ü", "\\\"U"},
{"Ÿ", "\\\"Y"},
{"ç", "\\c{c}"},
{"Ç", "\\c{C}"},
{"œ", "\\oe{}"},
{"Œ", "{\\OE}"},
{"æ", "{\\ae}"},
{"Æ", "{\\AE}"},
{"å", "{\\aa}"},
{"Å", "{\\AA}"},
{"", "--"},
{"—", "---"},
{"ø", "{\\o}"},
{"Ø", "{\\O}"},
{"ß", "{\\ss}"},
{"¡", "{!`}"},
{"¿", "{?`}"},
{"~", "\\~"},
{"&", "\\&"},
{"$", "\\$"},
{"%", "\\%"},
{"#", "\\#"},
{"_", "\\_"},
{"≥", "$\\ge$"},
{"≤", "$\\le$"},
{"≠", "$\\neq$"},
{"ı", "{\\i}"},
{"µ", "$\\mu$"},
{"°", "$\\deg$"},
{"", "`"},
{"", "'"},
{"“", "``"},
{"”", "''"},
{"", ","},
{"„", ",,"},
}
func md2tex(s string) string {
for _, r := range latexAccents {
s = strings.Replace(s, r.o, r.n, -1)
}
return model.MarkdownURLRegexp.ReplaceAllString(s, `\href{$2}{$1}`)
}