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

I am looking for a workaround to use Hugo to create a .json file for a sorta quasi site-index. I’ll be using gulp to take the content/search/index.html file and move/rename it to search-index.json and move it to the static assets folder.

Right now, adding {"body":"{{ .Content }}"} creates a slew of HTML in the value. Does anyone have any ideas of how I might be able to emulate a filter similar to {% .content | jsonify %} in Jekyll/Liquid? I’m putting together a starter pack and would like to include lunr.js as well as the additional defaults I’m putting together. Any help would be greatly appreciated. Thanks!

A wild stab, but since Go templates Jsonifies script content:

Create a shortcode jsonify.html (or whatever):

<script>{{ .Inner }}</script>

… maybe …

Thanks @bep. I will look into this tomorrow. Are filters like '| jsonify ’ on the roadmap? Rather, are they especially difficult to implement? I appreciate the hack regardless.

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 }}
    {{ 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!

Have you tried wrapping the entire “.” in a


This is probably not something you want int the output, but that should be easier to remove than getting the stuff right the hard way.

Yeah, not the outcome I wanted, but nevertheless, I learned something more about Go templates and the way Hugo renders this stuff, so it was worth a shot. Right now, .plainWords actually works well enough to get lunr.js to work and work well. Thanks again for all your help.

Hugo should get a better story on this, it will not be hard, but we should get a solution that works for all content types (json, xml, xcal etc.)