mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	[GITEA] Fix media description render for orgmode
- In org mode you can specify an description for media via the following syntax `[[description][media link]]`. The description is then used as title or alt. - This patch fixes the rendering of the description by seperating the description and non-description cases and using `org.String()`. - Added unit tests. - Inspired by6eb20dbda9/org/html_writer.go (L406-L427)- Resolves https://codeberg.org/Codeberg/Community/issues/848 (cherry picked from commitef2456e1b1) (cherry picked from commitb6559b4825) (cherry picked from commitd6dcc34492)
This commit is contained in:
		
					parent
					
						
							
								82c930152c
							
						
					
				
			
			
				commit
				
					
						8b8aab8311
					
				
			
		
					 2 changed files with 33 additions and 9 deletions
				
			
		|  | @ -153,18 +153,30 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) { | |||
| 		link = []byte(util.URLJoin(r.URLPrefix, lnk)) | ||||
| 	} | ||||
| 
 | ||||
| 	description := string(link) | ||||
| 	if l.Description != nil { | ||||
| 		description = r.WriteNodesAsString(l.Description...) | ||||
| 	} | ||||
| 	switch l.Kind() { | ||||
| 	case "image": | ||||
| 		imageSrc := getMediaURL(link) | ||||
| 		fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, description, description) | ||||
| 		if l.Description == nil { | ||||
| 			imageSrc := getMediaURL(link) | ||||
| 			fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, link, link) | ||||
| 		} else { | ||||
| 			description := strings.TrimPrefix(org.String(l.Description...), "file:") | ||||
| 			imageSrc := getMediaURL([]byte(description)) | ||||
| 			fmt.Fprintf(r, `<a href="%s"><img src="%s" alt="%s" /></a>`, link, imageSrc, imageSrc) | ||||
| 		} | ||||
| 	case "video": | ||||
| 		videoSrc := getMediaURL(link) | ||||
| 		fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, videoSrc, description, description) | ||||
| 		if l.Description == nil { | ||||
| 			imageSrc := getMediaURL(link) | ||||
| 			fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, imageSrc, link, link) | ||||
| 		} else { | ||||
| 			description := strings.TrimPrefix(org.String(l.Description...), "file:") | ||||
| 			videoSrc := getMediaURL([]byte(description)) | ||||
| 			fmt.Fprintf(r, `<a href="%s"><video src="%s" title="%s"></video></a>`, link, videoSrc, videoSrc) | ||||
| 		} | ||||
| 	default: | ||||
| 		description := string(link) | ||||
| 		if l.Description != nil { | ||||
| 			description = r.WriteNodesAsString(l.Description...) | ||||
| 		} | ||||
| 		fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description) | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue