From 7e351a08ef3b426fe4d46fb5718d7b271e6c59da Mon Sep 17 00:00:00 2001 From: Tom Johnson Date: Mon, 5 Oct 2015 14:24:02 -0700 Subject: [PATCH] fix to search.json to strip out tab characters from search.son these tab characters can make your json invalid --- doc_search_configuration.md | 6 ++++-- search.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc_search_configuration.md b/doc_search_configuration.md index f64e79f..68e2e1e 100644 --- a/doc_search_configuration.md +++ b/doc_search_configuration.md @@ -32,11 +32,13 @@ The search.json file already tries to strip out content that would otherwise mak ```json {% raw %} - "body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"' }}", + "body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"' | replace: '^t', ' ' }}", {% endraw %} ``` -However, it's possible that the formatting may not account for all the scenarios that would invalidate the JSON. (Sometimes it's an extra comma after the last item that makes it invalid.) +Note that the last replace, `| replace: '^t', ' ' `, looks for any tab character and replaces it with four spaces. Yes, an innocent little tab character invalidates JSON. Geez. If you run into other problematic formatting, you can use regex expressions to find and replace the content. See [Regular Expressions](http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/regular_expressions.html) for details on finding and replacing code. + +It's possible that the formatting may not account for all the scenarios that would invalidate the JSON. (Sometimes it's an extra comma after the last item that makes it invalid.) {% if site.audience == "designers" %} ## Customizing search results diff --git a/search.json b/search.json index e40e460..e29daae 100644 --- a/search.json +++ b/search.json @@ -12,7 +12,7 @@ search: exclude "keywords": "{{page.keywords}}", "url": "{{ page.url | replace: '/','' }}", "summary": "{{page.summary}}", -"body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"' }}" +"body": "{{ page.content | strip_html | strip_newlines | replace: '\', '\\\\' | replace: '"', '\\"'| replace: '^t', ' ' }}" }, {% endunless %}