Skip to content

Commit

Permalink
Add parser option to skip HTML to Text down conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdv committed May 3, 2024
1 parent 5139f90 commit 6578c9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (p Parser) EnvelopeFromPart(root *Part) (*Envelope, error) {
}

// Down-convert HTML to text if necessary
if e.Text == "" && e.HTML != "" {
if e.Text == "" && e.HTML != "" && !p.skipHTML2TextDownConversion {
// We always warn when this happens
e.Root.addWarning(
ErrorPlainTextFromHTML,
Expand Down
12 changes: 12 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ func (o stripMediaTypeInvalidCharactersOption) apply(p *Parser) {
func StripMediaTypeInvalidCharacters(stripMediaTypeInvalidCharacters bool) Option {
return stripMediaTypeInvalidCharactersOption(stripMediaTypeInvalidCharacters)
}

type skipHTML2TextDownConversionOption bool

func (o skipHTML2TextDownConversionOption) apply(p *Parser) {
p.skipHTML2TextDownConversion = bool(o)
}

// SkipHTML2TextDownConversion sets skipHTML2TextDownConversion option. If true, there will be no automatic down conversion
// of HTML 2 Text.
func SkipHTML2TextDownConversion(skipHTML2TextDownConversion bool) Option {
return skipHTML2TextDownConversionOption(skipHTML2TextDownConversion)
}
1 change: 1 addition & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Parser struct {
rawContent bool
customParseMediaType CustomParseMediaType
stripMediaTypeInvalidCharacters bool
skipHTML2TextDownConversion bool
}

// defaultParser is a Parser with default configuration.
Expand Down

0 comments on commit 6578c9b

Please sign in to comment.