This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use blackfriday LaTeX export for all values inserted in LaTeX.
- Loading branch information
Carl Kittelberger
committed
Feb 20, 2017
1 parent
340b6f2
commit 9a1ae64
Showing
10 changed files
with
110 additions
and
36 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package stringutil | ||
|
||
type converter interface { | ||
type Converter interface { | ||
Process(text string) string | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package stringutil | ||
|
||
import ( | ||
"strings" | ||
|
||
"git.dekart811.net/icedream/workreportmgr/internal/util" | ||
"github.com/russross/blackfriday" | ||
) | ||
|
||
const ( | ||
enabledExtensions = 0 | | ||
blackfriday.EXTENSION_NO_INTRA_EMPHASIS | | ||
blackfriday.EXTENSION_TABLES | | ||
blackfriday.EXTENSION_FENCED_CODE | | ||
blackfriday.EXTENSION_AUTOLINK | | ||
blackfriday.EXTENSION_STRIKETHROUGH | | ||
blackfriday.EXTENSION_SPACE_HEADERS | | ||
blackfriday.EXTENSION_HEADER_IDS | | ||
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK | | ||
blackfriday.EXTENSION_DEFINITION_LISTS | ||
) | ||
|
||
var additionalTexReplacements = []Converter{ | ||
// NewStringConverter("{", "\\{"), | ||
// NewStringConverter("}", "\\}"), | ||
// NewStringConverter("\\", "\\textbackslash{}"), | ||
// | ||
// NewStringConverter("&", "\\&"), | ||
// NewStringConverter("%", "\\%"), | ||
// NewStringConverter("$", "\\$"), | ||
// NewStringConverter("#", "\\#"), | ||
// NewStringConverter("_", "\\_"), | ||
// NewStringConverter("~", "\\textasciitilde{}"), | ||
// NewStringConverter("^", "\\textasciicircum{}"), | ||
// NewStringConverter("ß", "\\ss{}"), | ||
|
||
NewSimpleRegexConverter(`"([^"]+)"`, `\enquote{$1}`), | ||
// NewSimpleRegexConverter("`([^`]+)`", "\\verb`$1`"), | ||
} | ||
|
||
/* | ||
Latexize takes an input text as parsed from the value of any field in a project | ||
file and turns it into LaTeX code. | ||
*/ | ||
func Latexize(input string) string { | ||
renderer := util.DocumentlessRenderer{Renderer: blackfriday.LatexRenderer(0)} | ||
renderedString := string(blackfriday.Markdown([]byte(input), renderer, enabledExtensions)) | ||
renderedString = CustomEscape(renderedString, additionalTexReplacements...) | ||
renderedString = strings.TrimSpace(renderedString) | ||
return renderedString | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/russross/blackfriday" | ||
) | ||
|
||
/* | ||
DocumentlessRenderer wraps an actual renderer and suppresses full-document | ||
output. | ||
*/ | ||
type DocumentlessRenderer struct { | ||
blackfriday.Renderer | ||
} | ||
|
||
/* | ||
DocumentHeader does nothing as it is a bogus implementation to avoid full- | ||
document output. | ||
*/ | ||
func (r DocumentlessRenderer) DocumentHeader(out *bytes.Buffer) { | ||
} | ||
|
||
/* | ||
DocumentFooter does nothing as it is a bogus implementation to avoid full- | ||
document output. | ||
*/ | ||
func (r DocumentlessRenderer) DocumentFooter(out *bytes.Buffer) { | ||
} |