refactor(exporters): replace deprecated strings.Title with cases.Title

The `strings.Title` function is deprecated because it does not handle Unicode punctuation correctly.

This change replaces its usage in the DOCX, HTML, and Markdown exporters with the recommended `golang.org/x/text/cases` package. This ensures more robust and accurate title-casing for item headings.
This commit is contained in:
2025-11-06 03:55:07 +01:00
parent 59f2de9d22
commit 6317ce268b
5 changed files with 18 additions and 4 deletions

View File

@ -12,6 +12,8 @@ import (
"github.com/kjanat/articulate-parser/internal/interfaces"
"github.com/kjanat/articulate-parser/internal/models"
"github.com/kjanat/articulate-parser/internal/services"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// HTMLExporter implements the Exporter interface for HTML format.
@ -441,7 +443,8 @@ func (e *HTMLExporter) processDividerItem(buf *bytes.Buffer) {
func (e *HTMLExporter) processUnknownItem(buf *bytes.Buffer, item models.Item) {
if len(item.Items) > 0 {
buf.WriteString(" <div class=\"item unknown-item\">\n")
buf.WriteString(fmt.Sprintf(" <h4>%s Content</h4>\n", strings.Title(item.Type)))
caser := cases.Title(language.English)
buf.WriteString(fmt.Sprintf(" <h4>%s Content</h4>\n", caser.String(item.Type)))
for _, subItem := range item.Items {
e.processGenericSubItem(buf, subItem)
}