mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Convert EOL to UNIX-style to render MD properly (#8925)
* Convert EOL to UNIX-style to render MD properly * Update modules/markup/markdown/markdown.go Co-Authored-By: zeripath <art27@cantab.net> * Fix lint optimization * Check for empty content before conversion * Update modules/util/util.go Co-Authored-By: zeripath <art27@cantab.net> * Improved checks and tests * Add paragraph render test * Improve speed even more, improve tests * Small improvement by @gary-kim * Fix test for DOS * More improvements * Restart CI
This commit is contained in:
		
				
					committed by
					
						 Antoine GIRARD
						Antoine GIRARD
					
				
			
			
				
	
			
			
			
						parent
						
							cda8de2004
						
					
				
				
					commit
					7b97e04555
				
			| @@ -157,7 +157,8 @@ func RenderRaw(body []byte, urlPrefix string, wikiMarkdown bool) []byte { | ||||
| 		exts |= blackfriday.HardLineBreak | ||||
| 	} | ||||
|  | ||||
| 	body = blackfriday.Run(body, blackfriday.WithRenderer(renderer), blackfriday.WithExtensions(exts)) | ||||
| 	// Need to normalize EOL to UNIX LF to have consistent results in rendering | ||||
| 	body = blackfriday.Run(util.NormalizeEOL(body), blackfriday.WithRenderer(renderer), blackfriday.WithExtensions(exts)) | ||||
| 	return markup.SanitizeBytes(body) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -294,3 +294,25 @@ func TestTotal_RenderString(t *testing.T) { | ||||
| 		assert.Equal(t, testCases[i+1], line) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestRender_RenderParagraphs(t *testing.T) { | ||||
| 	test := func(t *testing.T, str string, cnt int) { | ||||
| 		unix := []byte(str) | ||||
| 		res := string(RenderRaw(unix, "", false)) | ||||
| 		assert.Equal(t, strings.Count(res, "<p"), cnt) | ||||
|  | ||||
| 		mac := []byte(strings.ReplaceAll(str, "\n", "\r")) | ||||
| 		res = string(RenderRaw(mac, "", false)) | ||||
| 		assert.Equal(t, strings.Count(res, "<p"), cnt) | ||||
|  | ||||
| 		dos := []byte(strings.ReplaceAll(str, "\n", "\r\n")) | ||||
| 		res = string(RenderRaw(dos, "", false)) | ||||
| 		assert.Equal(t, strings.Count(res, "<p"), cnt) | ||||
| 	} | ||||
|  | ||||
| 	test(t, "\nOne\nTwo\nThree", 1) | ||||
| 	test(t, "\n\nOne\nTwo\nThree", 1) | ||||
| 	test(t, "\n\nOne\nTwo\nThree\n\n\n", 1) | ||||
| 	test(t, "A\n\nB\nC\n", 2) | ||||
| 	test(t, "A\n\n\nB\nC\n", 2) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user