Repository navigation
Add a JSON formatter, the reverse of %json - #12
Merged
Merged
Conversation
--json and %formatter/json write a list of attributes as an object, any other list as an array, and true, false and null as themselves. %json and %yaml now read unquoted numbers, booleans and null as numbers and symbols instead of strings, so JSON read in is written back the same. Raw text inside a <script> is written as is, so JSON can be given to a script, and the blog sample gains a JSON Feed.
Writing JavaScript as seam source is fragile, since ; starts a comment, and strings were written back with Rust's escapes. A script that is a single string is now written as it is, as with style, and otherwise strings in a script are written as JavaScript strings. JSON is best given to scripts as a data block, which is what the docs now show.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds JSON output, with
--jsonand(%formatter/json ...).:key valueattributes is written as an object, and any other list as an array. A list mixing the two is an error, pointing at the first odd item.0x10→16). The symbolstrue,falseandnullare themselves, and other symbols are strings.%formatter/jsonis compact unless given:document true.</in strings is written<\/, so JSON can't close a<script>it is embedded in.%json/%yamlkeep types. Unquoted numbers,true/falseandnullused to be read as strings ((:a "1")). They are now numbers and symbols, so reading JSON in and writing it back out gives the same JSON. Quoted values stay strings. This also changes YAML frontmatter:draft: trueis now the symboltrue. The blog sample's output is byte-for-byte identical.Scripts. Writing JavaScript as seam source is fragile:
;starts a comment, and strings were written back with Rust's escapes. So now:<script>whose only content is a string (e.g."""...""") is written as is, like<style>already was.samples/tests/html-test-2.sexrenders the same.(script :type application/json :id posts (%formatter/json %posts)), read withJSON.parse.Blog. Adds
feed.json.sex, a JSON Feed written as s-expressions. It's built bybuild.sexand linked from every page.Tests cover the formatter, round-tripping
%json, typed YAML scalars and JSON inside a script.Note
Medium Risk
Changes affect HTML script emission and YAML/JSON parsing semantics site-wide; existing templates relying on string-typed booleans or old script quoting could behave differently.
Overview
Adds JSON output via
--jsonand(%formatter/json ...), mapping s-expressions back to JSON (attribute lists → objects, other lists → arrays) with compact output by default and pretty printing when:document true. String escaping includes<\/after<so JSON embedded in<script>tags cannot break out.%jsonand%yamlnow preserve scalar types (numbers,true/false/null) instead of treating unquoted values as strings, enabling round-trip JSON and changing how YAML frontmatter booleans behave (e.g.draft: trueis the symboltrue).HTML
<script>generation is updated: a single string child is emitted verbatim; structured script content keeps seam syntax but escapes string nodes as JavaScript/JSON string literals via the sharedwrite_stringhelper.The blog sample gains a JSON Feed (
feed.json.sex), build step, andapplication/feed+jsonalternate link. Docs and tests cover the formatter, round-trips, typed YAML, and JSON-in-script cases.Reviewed by Cursor Bugbot for commit a93c4ce. Bugbot is set up for automated code reviews on this repo. Configure here.