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

Is there a "Format Selection As ..." command? #131814

Open
michaelgwelch opened this issue Aug 27, 2021 · 7 comments
Open

Is there a "Format Selection As ..." command? #131814

michaelgwelch opened this issue Aug 27, 2021 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality formatting Source formatter issues
Milestone

Comments

@michaelgwelch
Copy link

I spend a lot of time writing Markdown with lots of JSON examples. Often my sources of JSON don't do a good job of formatting the JSON, or I manually write the JSON but make some mistakes in formatting. Would love to be able to select everything within the Markdown code block and say "Format Selection As ... " and choose JSON.

Or better yet, have the command detect the format option from the fenced code block (```json in this case).

Current work around is to copy/paste to a JSON doc. Format Document. Copy/Paste back to markdown doc.

@mjbvz mjbvz assigned jrieken and unassigned mjbvz Aug 27, 2021
@jrieken jrieken added feature-request Request for new features or functionality formatting Source formatter issues labels Aug 30, 2021
@jrieken jrieken added this to the Backlog milestone Aug 30, 2021
@jrieken jrieken modified the milestones: Backlog, Backlog Candidates Oct 15, 2021
@bkmeneguello

This comment was marked as spam.

@ADTC
Copy link

ADTC commented Aug 18, 2022

I'm glad this issue is in the backlog, and I hope there can be some progress made on it. I wish to have this feature too.

In my current case, I work with Shopify themes which can have several different formats in the same file: CSS, JavaScript, JSON, HTML, Liquid, etc. So it will be useful to highlight parts of the file, issue a "Format Selection As" command and choose a certain language to format that selection alone.

Noting here also that this was asked before #27073 but was closed in the issue grooming exercise then.

@michaelgwelch another workaround: You can temporarily rename the markdown file extension to .md.json, format your JSON code blocks, then rename it back to .md 🙂

@oghaki
Copy link

oghaki commented Dec 28, 2022

. I'd really like to see this implemented as well. Similar to what others have mentioned here and in #27073, I'm not interested in syntax-highlighting which requires VSCode to programmatically conjecture the parsing, and final language designation, selected from a set of more than one language, to each element of the result, i.e. any functionality which enhances or generalizes VSCode's ability to highlight syntax of all correctly-formatted¹ code in a file, where language value, used to verify and highlight syntax, is not atomic² nor provided as a parameter (or functionally equivalent)³ to the process highlighting syntax.⁴ Instead, I'm only looking for the ability to manually designate a substring within the file to be parsed using a specified language, after which existing syntax highlighting procedures would be applied, using already installed language extensions, would operate similarly, but, instead of a language being associated with a file, it would be associated with some substring object. The substring object could be defined in multiple ways. The worst-case scenario would be an assignment which is purely static relative to position in the file (e.g., start and end positions defined by constant row and column coordinates), but, ideally, it would be dynamic—I envisioned something that functions like 𝘙𝘢𝘯𝘨𝘦 objects in Wᴏʀᴅ, relying on procedures weighing multiple parameters to evaluate bounds dynamically, to provide acceptable tolerance of common, foreseeable edits⁵, to adjust 𝘙𝘢𝘯𝘨𝘦 bounds in a manner consistent with reasonable user-expectations (forcing language designation of a 𝘙𝘢𝘯𝘨𝘦 at creation should make a robust function for tracking bounds relatively feasible). Finally, some kind of graphical indicator would dramatically improve usability, e.g. an outline enclosing the range, revealed on mouse-over or when the cursor position is within the range, with resize handles at the bounds (adjustment using these would resemble highlighting text with a mouse), and possibly on the top and bottom edges (which would increment or decrement entire rows from the range), and using different outline colors for each range, or for each set of ranges with the same language designation.

────────────────────────────────────────────────────────────

  1. VSCode must be able to validate formatting, which excepts from this requirement, any code written in a language which 𝘩𝘢𝘴 𝘯𝘰𝘵 been installed.
  2. 𝘢𝘵𝘰𝘮𝘪𝘤, here, is used reference a type which is a single value, in contrast with 𝘤𝘰𝘮𝘱𝘰𝘴𝘪𝘵𝘦 types, which contain multiple values (e.g., an 𝘢𝘳𝘳𝘢𝘺, 𝘭𝘪𝘴𝘵 or 𝘤𝘰𝘭𝘭𝘦𝘤𝘵𝘪𝘰𝘯).
  3. Here, 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘢𝘭𝘭𝘺 𝘦𝘲𝘶𝘪𝘷𝘢𝘭𝘦𝘯𝘵 is meant to include any states where language, as used for the syntax-highlighting procedure, is atomic and initialized when the syntax-highlighting procedure is called.
  4. An example of a request like this, which references automated language assignment on files which contain both PHP and HTML, can be found here: #14447.
  5. E.g., to dynamically (𝑎) grow or shrink the 𝘙𝘢𝘯𝘨𝘦's upper bound to accord with insertions or deletions made, therein, or (𝑏) advance or retreat the 𝘙𝘢𝘯𝘨𝘦's lower bound in response to changes in the length of text preceding it.

────────────────────────────────────────────────────────────

. Also, I just wanted to note that @bkmeneguello's comment from May 16ᵗʰ doesn't seem like spam. I'm not sure if it was automatically flagged for some reason, but I may also be missing something.

@starball5
Copy link

Related on Stack Overflow: Formatting contents of a Markdown code fences in VS Code (or other embedded language code). For that question, #14447 was also related.

@cjbarth
Copy link

cjbarth commented May 25, 2023

Here is another related item (#183466), this time referring to JavaScript and a missing "Format Selection With..." command, which would also solve this problem, and is apparently available in other contexts within VS Code.

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 formatting Source formatter issues
Projects
None yet
Development

No branches or pull requests

9 participants