From 93ca7c9e958e34469a337e4efcc7c75774ec50fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 5 Feb 2017 10:20:06 +0700 Subject: all: Refactor to nonglobal Viper, i18n etc. This is a final rewrite that removes all the global state in Hugo, which also enables the use if `t.Parallel` in tests. Updates #2701 Fixes #3016 --- hugolib/shortcode.go | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'hugolib/shortcode.go') diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index afee1884f..4ce6df7e9 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -149,31 +149,6 @@ func (sc shortcode) String() string { return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner) } -// HandleShortcodes does all in one go: extract, render and replace -// only used for testing -func HandleShortcodes(stringToParse string, page *Page) (string, error) { - tmpContent, tmpShortcodes, err := extractAndRenderShortcodes(stringToParse, page) - - if err != nil { - return "", err - } - - if len(tmpShortcodes) > 0 { - shortcodes, err := executeShortcodeFuncMap(tmpShortcodes) - if err != nil { - return "", err - } - tmpContentWithTokensReplaced, err := replaceShortcodeTokens([]byte(tmpContent), shortcodePlaceholderPrefix, shortcodes) - - if err != nil { - return "", fmt.Errorf("Failed to replace shortcode tokens in %s:\n%s", page.BaseFileName(), err.Error()) - } - return string(tmpContentWithTokensReplaced), nil - } - - return tmpContent, nil -} - var isInnerShortcodeCache = struct { sync.RWMutex m map[string]bool @@ -239,12 +214,12 @@ func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page) string { } if sc.doMarkup { - newInner := helpers.RenderBytes(&helpers.RenderingContext{ + newInner := p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{ Content: []byte(inner), PageFmt: p.determineMarkupType(), - ConfigProvider: p.Language(), - DocumentID: p.UniqueID(), - DocumentName: p.Path(), - Config: p.getRenderingConfig()}) + Cfg: p.Language(), + DocumentID: p.UniqueID(), + DocumentName: p.Path(), + Config: p.getRenderingConfig()}) // If the type is “unknown” or “markdown”, we assume the markdown // generation has been performed. Given the input: `a line`, markdown -- cgit v1.2.3