Fix escaping of data-* attributes [closes #1075]

When objects are used as values for `data-` attributes,
the stringified JSON is delimited by single quotes,
so these must be replaced with HTML character entity references.