summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-24 05:57:33 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-25 08:56:46 +0200
commit288c39643906b4194a0a6acfbaf87cb0fbdeb361 (patch)
tree15587fe16af04ccc881c7dbccce2800da3c7d9ea /hugolib/shortcode.go
parent44e47478d035e835ea7a7ac57217557baeac8c5b (diff)
hugolib: Fix some shortcode vs .Content corner cases
This is a follow-up to #4632. There were some assumptions in that implementation that did not hold water in all situations. This commit simplifies the content lazy initalization making it more robust. Fixes #4664
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r--hugolib/shortcode.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 4792b7f61..8afbfb645 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -366,7 +366,12 @@ func (s *shortcodeHandler) updateDelta() bool {
s.contentShortcodes = createShortcodeRenderers(s.shortcodes, s.p.withoutContent())
})
- contentShortcodes := s.contentShortcodesForOutputFormat(s.p.s.rc.Format)
+ if !s.p.shouldRenderTo(s.p.s.rc.Format) {
+ // TODO(bep) add test for this re translations
+ return false
+ }
+ of := s.p.s.rc.Format
+ contentShortcodes := s.contentShortcodesForOutputFormat(of)
if s.contentShortcodesDelta == nil || s.contentShortcodesDelta.Len() == 0 {
s.contentShortcodesDelta = contentShortcodes
@@ -387,13 +392,19 @@ func (s *shortcodeHandler) updateDelta() bool {
return delta.Len() > 0
}
+func (s *shortcodeHandler) clearDelta() {
+ if s == nil {
+ return
+ }
+ s.contentShortcodesDelta = newOrderedMap()
+}
+
func (s *shortcodeHandler) contentShortcodesForOutputFormat(f output.Format) *orderedMap {
contentShortcodesForOuputFormat := newOrderedMap()
lang := s.p.Lang()
for _, key := range s.shortcodes.Keys() {
shortcodePlaceholder := key.(string)
- // shortcodePlaceholder := s.shortcodes.getShortcode(key)
key := newScKeyFromLangAndOutputFormat(lang, f, shortcodePlaceholder)
renderFn, found := s.contentShortcodes.Get(key)