Convert to inline json
Bash 📄 html-to-json.sh
Collapse all whitespace/newlines into single spaces
Convert to inline json
#!/usr/bin/env bash
# Usage: ./html-to-json.sh input.html
# Prints a JSON-escaped, single-line string (with quotes) suitable
# for pasting as a value into a JSON localization file.
#
# Requires: jq
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <input.html>" >&2
exit 1
fi
input_file="$1"
if [[ ! -f "$input_file" ]]; then
echo "File not found: $input_file" >&2
exit 1
fi
# Collapse all whitespace/newlines into single spaces (matches the
# single-line style already used in Localization.*.json), then JSON-encode.
tr '\n' ' ' < "$input_file" | tr -s '[:space:]' ' ' | sed -e 's/^ *//' -e 's/ *$//' | jq -Rs .Gist information
ID:#23
Language:Bash
File:html-to-json.sh
Created:
Likes:0