Possible to get markdown escaped as just plain text if not JSON?

Per #1915, hoping to improve the following logic, which I’m using in conjunction with a bash script for deploying and creating a search index using lunr.js:

[{{ range $index, $page := .Site.Pages }}
{{ if ne $page.Type "json" }}
{{ if and $index (gt $index 1) }},{{ end }}
{
    "url": "{{ $page.Permalink }}",
    "title": "{{ $page.Title }}",
    <!--Add content subtitle to index only if set, otherwise set to empty since subtitle is *still* added to lunr.js index.-->
    {{ if $page.Params.subtitle }}
		"subtitle": "{{ $page.Params.subtitle }}",
		{{ else }}
		"subtitle":"",
    {{ end }}
    "section": "{{ .Section }}",
    "tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag }}"{{ end }}],
    "description": "{{.Description}}",
    "content": "{{$page.PlainWords}}"
}{{ end }}{{ end }}]

When substituting "{{$page.PlainWords}}" with <script>{{$page.PlainWords}}</script> or <script>{{$page.PlainWords}}</script> or even just <script>{{$page.Content}}</script> I am not getting the sorta | jsonify behavior I was hoping for per your mention in the above pull request.

That said, the content does have all the html stripped, so at this point, I’m satisfied with the solution but would definitely like to remove the special characters from the content if possible. Thanks!