Skip to content

Commit

Permalink
simple escape markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rostrovsky committed Mar 23, 2024
1 parent e2fe7f3 commit b266a3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func run(cmd *cobra.Command, args []string) {
slog.Debug("Processing done")

if oFlag != "" {
slog.Debug("Saving", "output file", oFlag)
slog.Debug("Saving output", "file", oFlag)
err := writeToFile(oFlag, []byte(sb.String()))
if err != nil {
logErrAndExit(err)
Expand Down
14 changes: 12 additions & 2 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func isBinary(filename string) (bool, error) {
return !utf8.ValidString(string(buf)), nil
}

func isMarkdown(filename string) bool {
return strings.HasSuffix(strings.ToLower(filename), ".md")
}

func processPath(path string, prefixToRemove string, include *regexp.Regexp, exclude *regexp.Regexp, stringBuilder *strings.Builder) error {
return filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
Expand Down Expand Up @@ -92,10 +96,16 @@ func processPath(path string, prefixToRemove string, include *regexp.Regexp, exc
filePath = trimmedPath
}

fences := "```"

if isMarkdown(filePath) {
fences = "````"
}

stringBuilder.WriteString("`" + filePath + "`\n\n")
stringBuilder.WriteString("```" + "\n")
stringBuilder.WriteString(fences + "\n")
stringBuilder.Write(content)
stringBuilder.WriteString("```" + "\n\n")
stringBuilder.WriteString(fences + "\n\n")

return nil
})
Expand Down

0 comments on commit b266a3b

Please sign in to comment.