mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	Improve markup determination logic
Sets Page.markup earlier (as early as possible, when the page is loaded). Sets it once and only once, removing many redundant calls to determineMarkupType(). This kills a sleeping bug that was avoided by the parts of the code depending on this value making those redundant calls.
This commit is contained in:
		
				
					committed by
					
						 Bjørn Erik Pedersen
						Bjørn Erik Pedersen
					
				
			
			
				
	
			
			
			
						parent
						
							00e36a4164
						
					
				
				
					commit
					2fb9af59c1
				
			| @@ -728,8 +728,7 @@ func replaceDivider(content, from, to []byte) ([]byte, bool) { | ||||
| // rendering engines. | ||||
| func (p *Page) replaceDivider(content []byte) []byte { | ||||
| 	summaryDivider := helpers.SummaryDivider | ||||
| 	// TODO(bep) handle better. | ||||
| 	if p.Ext() == "org" || p.Markup == "org" { | ||||
| 	if p.Markup == "org" { | ||||
| 		summaryDivider = []byte("# more") | ||||
| 	} | ||||
|  | ||||
| @@ -863,7 +862,7 @@ func (p *Page) setAutoSummary() error { | ||||
|  | ||||
| func (p *Page) renderContent(content []byte) []byte { | ||||
| 	return p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{ | ||||
| 		Content: content, RenderTOC: true, PageFmt: p.determineMarkupType(), | ||||
| 		Content: content, RenderTOC: true, PageFmt: p.Markup, | ||||
| 		Cfg:        p.Language(), | ||||
| 		DocumentID: p.UniqueID(), DocumentName: p.Path(), | ||||
| 		Config: p.getRenderingConfig()}) | ||||
| @@ -1486,6 +1485,13 @@ func (p *Page) update(frontmatter map[string]interface{}) error { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Try markup explicitly set in the frontmatter | ||||
| 	p.Markup = helpers.GuessType(p.Markup) | ||||
| 	if p.Markup == "unknown" { | ||||
| 		// Fall back to file extension (might also return "unknown") | ||||
| 		p.Markup = helpers.GuessType(p.Source.Ext()) | ||||
| 	} | ||||
|  | ||||
| 	if draft != nil && published != nil { | ||||
| 		p.Draft = *draft | ||||
| 		p.s.Log.ERROR.Printf("page %s has both draft and published settings in its frontmatter. Using draft.", p.File.Path()) | ||||
| @@ -1725,17 +1731,6 @@ func (p *Page) shouldRenderTo(f output.Format) bool { | ||||
| 	return found | ||||
| } | ||||
|  | ||||
| func (p *Page) determineMarkupType() string { | ||||
| 	// Try markup explicitly set in the frontmatter | ||||
| 	p.Markup = helpers.GuessType(p.Markup) | ||||
| 	if p.Markup == "unknown" { | ||||
| 		// Fall back to file extension (might also return "unknown") | ||||
| 		p.Markup = helpers.GuessType(p.Source.Ext()) | ||||
| 	} | ||||
|  | ||||
| 	return p.Markup | ||||
| } | ||||
|  | ||||
| func (p *Page) parse(reader io.Reader) error { | ||||
| 	psr, err := parser.ReadFrom(reader) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -314,7 +314,8 @@ func renderShortcode( | ||||
|  | ||||
| 		if sc.doMarkup { | ||||
| 			newInner := p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{ | ||||
| 				Content: []byte(inner), PageFmt: p.determineMarkupType(), | ||||
| 				Content:      []byte(inner), | ||||
| 				PageFmt:      p.Markup, | ||||
| 				Cfg:          p.Language(), | ||||
| 				DocumentID:   p.UniqueID(), | ||||
| 				DocumentName: p.Path(), | ||||
| @@ -333,7 +334,7 @@ func renderShortcode( | ||||
| 			//     substitutions in <div>HUGOSHORTCODE-1</div> which prevents the | ||||
| 			//     generation, but means that you can’t use shortcodes inside of | ||||
| 			//     markdown structures itself (e.g., `[foo]({{% ref foo.md %}})`). | ||||
| 			switch p.determineMarkupType() { | ||||
| 			switch p.Markup { | ||||
| 			case "unknown", "markdown": | ||||
| 				if match, _ := regexp.MatchString(innerNewlineRegexp, inner); !match { | ||||
| 					cleaner, err := regexp.Compile(innerCleanupRegexp) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user