Skip to content

.Plain not stripping HTML tags correctly #9909

@acalvo

Description

@acalvo

The .Plain page variable, is supposed to return the Page content stripped of HTML tags and presented as a string. I detected one case in which it does not correctly:

I have a heading render hook with the following content:

<h{{ .Level }} id="{{ .Anchor | safeURL }}">
  {{ .Text | safeHTML }}
  {{ if .Level | eq 2 }}
  <button type="button" class="anchor tooltip"
    onmouseover="this.dataset.description = 'Copy link to this section'"
    onclick="navigator.clipboard.writeText(location.href.replace(location.hash, '') + '#{{ .Anchor | safeURL }}').then(() => this.dataset.description = 'Copied to clipboard')">
    {{ partial "svg/link.svg" . }}
  </button>
  {{ end }}
</h{{ .Level }}>

When I write in a MD:

## Overview

Blah blah.

Then .Plain returns the following string: Overview this.dataset.description = 'Copied to clipboard')\" Blah blah.

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

$ hugo version
hugo v0.99.1-d524067382e60ce2a2248c3133a1b3af206b6ef1+extended darwin/arm64 BuildDate=2022-05-18T11:18:14Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions