mirror of
				https://github.com/SphericalKat/medium.rip.git
				synced 2025-11-04 04:25:56 +00:00 
			
		
		
		
	fix(markup): enable handling of utf-8
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
		
							parent
							
								
									7b6e7d7edb
								
							
						
					
					
						commit
						665d33d9d3
					
				@ -36,7 +36,7 @@ func ranges(text string, markups []entities.Markup) []RangeWithMarkup {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// include the start and end indexes of the text
 | 
						// include the start and end indexes of the text
 | 
				
			||||||
	markupBoundaries = append([]int{0}, markupBoundaries...)
 | 
						markupBoundaries = append([]int{0}, markupBoundaries...)
 | 
				
			||||||
	markupBoundaries = append(markupBoundaries, len(text))
 | 
						markupBoundaries = append(markupBoundaries, len([]rune(text)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// remove duplicates
 | 
						// remove duplicates
 | 
				
			||||||
	markupBoundaries = unique(markupBoundaries)
 | 
						markupBoundaries = unique(markupBoundaries)
 | 
				
			||||||
@ -72,7 +72,8 @@ func ranges(text string, markups []entities.Markup) []RangeWithMarkup {
 | 
				
			|||||||
func ConvertMarkup(text string, markups []entities.Markup) string {
 | 
					func ConvertMarkup(text string, markups []entities.Markup) string {
 | 
				
			||||||
	var markedUp strings.Builder
 | 
						var markedUp strings.Builder
 | 
				
			||||||
	for _, r := range ranges(text, markups) {
 | 
						for _, r := range ranges(text, markups) {
 | 
				
			||||||
		textToWrap := string(text[r.Range[0]:r.Range[1]])
 | 
							runeText := []rune(text) // very important otherwise we can't handle UTF-8
 | 
				
			||||||
 | 
							textToWrap := string(runeText[r.Range[0]:r.Range[1]])
 | 
				
			||||||
		markedUp.WriteString(wrapInMarkups(textToWrap, r.Markups))
 | 
							markedUp.WriteString(wrapInMarkups(textToWrap, r.Markups))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user