package textmeasure

import (
	
	

	
	
)

func ( string,  map[string]string) string {
	 := []byte()
	 := text.NewReader()
	 := markdownRenderer.Parser().Parse()

	type  struct {
		  int
		   int
		 string
	}
	var  []

	ast.Walk(, func( ast.Node,  bool) (ast.WalkStatus, error) {
		if ! {
			return ast.WalkContinue, nil
		}

		if isCodeNode() {
			return ast.WalkSkipChildren, nil
		}

		if ,  := .(*ast.Text);  {
			 := .Segment
			 := string(.Value())
			 := replaceVariables(, )

			if  !=  {
				 = append(, {
					:  .Start,
					:   .Stop,
					: ,
				})
			}
		}
		return ast.WalkContinue, nil
	})

	if len() == 0 {
		return 
	}

	sort.Slice(, func(,  int) bool {
		return []. > [].
	})

	 := string()
	for ,  := range  {
		 = [:.] + . + [.:]
	}

	return 
}

func isCodeNode( ast.Node) bool {
	switch .Kind() {
	case ast.KindCodeBlock, ast.KindFencedCodeBlock, ast.KindCodeSpan:
		return true
	}
	return false
}

func replaceVariables( string,  map[string]string) string {
	for ,  := range  {
		 = strings.ReplaceAll(, "${"++"}", )
	}
	return 
}