Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html] JSON edit support inside HTML document / script tag with type="application/json" #36280

Open
bahrus opened this issue Oct 14, 2017 · 14 comments · May be fixed by #171547
Open

[html] JSON edit support inside HTML document / script tag with type="application/json" #36280

bahrus opened this issue Oct 14, 2017 · 14 comments · May be fixed by #171547
Assignees
Labels
feature-request Request for new features or functionality html HTML support issues
Milestone

Comments

@bahrus
Copy link

bahrus commented Oct 14, 2017

There are scenarios where it is useful to embed JSON inside an html document, such as for the amp-bind element:

<amp-state id="myAnimals">
  <script type="application/json">
    {
      "dog": {
        "imageUrl": "/img/dog.jpg",
        "style": "greenBackground"
      },
      "cat": {
        "imageUrl": "/img/cat.jpg",
        "style": "redBackground"
      }
    }
  </script>
</amp-state>

Providing syntax coloring / error checking would be very beneficial in these cases.

@vscodebot vscodebot bot added the html HTML support issues label Oct 14, 2017
@aeschli aeschli added the feature-request Request for new features or functionality label Oct 16, 2017
@aeschli aeschli added this to the Backlog milestone Oct 16, 2017
@aeschli aeschli changed the title Provide JSON edit support inside HTML document / script tag with type="application/json" [html] JSON edit support inside HTML document / script tag with type="application/json" Oct 16, 2017
@aeschli
Copy link
Contributor

aeschli commented Oct 16, 2017

Requires updates to the html grammar as well as the language server. Currently not planned, unless more users have the same request.

@Buslowicz
Copy link

+1 from me :).

@jleclanche
Copy link

Requesting that if application/json be added, also recognize application/ld+json as json as well.

@mdrideout
Copy link

I want this as well. Very common for editing pages using Google's json-ld structured data format.

@garyballantyne
Copy link

+1

@bahrus
Copy link
Author

bahrus commented Apr 30, 2019

Note that import maps will also make it quite useful to provide json editing support within an html page.

@ccapndave
Copy link

+1

@panoply
Copy link

panoply commented Jul 30, 2019

Should be easy enough to write a quick grammar injection to support both application/json and application/ld+json and then offer it as an extension. A simple capture like:

(<)(script)\\b(?=[^>]*type=('application/json'|\"application/json\"))(?![^/>]*/>\\s*$)

Would suffice. I'll give it a go.

@panoply
Copy link

panoply commented Jul 30, 2019

Here: vscode-json-script-tag

Leverages grammar injection, injects support into the HTML language. I included ld+json support too. Hope it helps.

@bahrus
Copy link
Author

bahrus commented Aug 2, 2019

Works great, thank you!

@wasi-master
Copy link

So what happened to this?

@bahrus
Copy link
Author

bahrus commented Nov 28, 2021

Microsoft's reluctance to implement this seems to be a reflection of the monocultural community vscode targets (and which it in turn perpetuates). If vscode is interested in expanding the community it targets, and demonstrate a commitment to a broader vision for the web, it might be interested in knowing that the percent of websites using ld+json is quite high. I guess 40% of websites doesn't count for much? The percent of websites using React is much smaller, for example. The percent of sites using AMP and import maps is admittedly small, but both are climbing.

I actually enhanced the nice extension @panoply created, and added support for import maps as well.

In addition, web components often use JSON in the attributes, so I added support for that also. I would amend this issue to include support for JSON attributes, that would be fantastic (especially if support for schemas could be baked in as well).

The nice thing is both of these extensions didn't require a single line of code to be written, and they work in the web-based versions of vscode.

It seems like the ratio between usefulness over the effort required is quite large for this request, especially with @panoply's efforts, so it is disappointing to see it languish for so long.

On the other hand, I do commend vscode for making itself extensible enough that support could be added in this way.

@aeschli
Copy link
Contributor

aeschli commented Nov 29, 2021

Definitely thanks to @panoply to provide this with an extension. Maybe this prevented this issue from getting many votes. Right now it's at 13 which very little

To get this started:
The HTML grammar we use for syntax highlighting is maintained at https://github.com/textmate/html.tmbundle. The issue there is textmate/html.tmbundle#103
Maybe start with a PR there?

@panoply
Copy link

panoply commented Nov 29, 2021

@aeschli Can we extend this further and potentially bring the JSON Language Service? I assume users would like to hook into $schema fields directly. Might involve some minor refactors to the HTML Language Service itself.

I am free in December and am fairly familiar with the HTML scanner/parser approach you employed in the HTML language service. Coupling this to understand attributed script tags and from here passing contents to the JSON language service to facilitate intellisense capabilities would be a great feature for many (I would assume).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality html HTML support issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants