gohugoio / hugoDocs

The source for https://gohugo.io/
Apache License 2.0
1.03k stars 1.47k forks source link

plainify doc doesn't say that it transforms chars into entities #2600

Closed willfaught closed 2 months ago

willfaught commented 2 months ago

What I did:

{{ "Things <i>I've</i> done" | markdownify | plainify }}

What I got:

Things I&rsquo;ve done

What I expected:

Things I've done

I have to use htmlUnescape to undo the entity mangling:

{{ "Things <i>I've</i> done" | markdownify | plainify | htmlUnescape }}

Result:

Things I've done

This isn't clear from the plainify doc:

Returns a string with all HTML tags removed. [...]

{{ "<b>BatMan</b>" | plainify }} → BatMan

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.126.1+extended darwin/arm64 BuildDate=2024-05-15T10:42:34Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

jmooring commented 2 months ago

I find it helpful to take Go's html/template package out of the mix by printing to console.

With Hugo's default markdown configuration:

{{ "Things <i>I've</i> done" | warnf "%v" }} → Things <i>I've</i> done
{{ "Things <i>I've</i> done" | plainify | warnf "%v" }} → Things I've done
{{ "Things <i>I've</i> done" | markdownify | warnf "%v" }} → Things <!-- raw HTML omitted -->I&rsquo;ve<!-- raw HTML omitted --> done
{{ "Things <i>I've</i> done" | markdownify | plainify | warnf "%v" }} → Things I&rsquo;ve done

So plainify isn't transforming the character... markdownify is, and that's due to the typographer extension being enabled by default.