Skip to content

Commit

Permalink
Add sanitize for md
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo-Hafsaoui committed Sep 14, 2024
1 parent 787c1c5 commit 80d0c84
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
30 changes: 23 additions & 7 deletions internal/markup_languages/latex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package markuplanguages

import (
"errors"
"regexp"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -71,6 +72,9 @@ func ApplyToSection(section Section, section_type string, output_path string)(st
if len(path_name) == 1 {
return template,errors.New("Trying to save outside of output file, at "+output_path)
}
if err != nil{
return "",err
}
err = writeTemplate(path_name[0],template,path_name[1])
return template,err
}
Expand All @@ -82,7 +86,7 @@ func replace_param(template string, nb_params int, replacements []string)string{
template = strings.Replace(template,
position, replacements[i], 1)
}
return template
return sanitize(template)
}

func replace_items(template string, section_items []string)string{
Expand All @@ -92,11 +96,23 @@ func replace_items(template string, section_items []string)string{
}
template = strings.Replace(template,
"%ITEMS%", items, 1)
return template
return sanitize(template)
}

//Clean from %anchor% and sanitize the special charactere
//inside the latex doc in the output directory
//func clean_and_sanitize()error{
// return nil
//}
//Sanitize the special charactere
func sanitize(template string)(string){
replacements := []struct {
pattern string
replacement string
}{
{`[0-9]\%`, `\\%`},
{`\*\*(.*?)\*\*`, `\textbf{$1}`},
{`\*(.*?)\*`, `\emph{$1}`},
//{`\[(.*?)\]\((.*?)\)`, `\href{$2}{$1}`},
}
for _, r := range replacements {
re := regexp.MustCompile(r.pattern)
template = re.ReplaceAllString(template, r.replacement)
}
return template
}

0 comments on commit 80d0c84

Please sign in to comment.