Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code formatting break Jekyll YAML front matter directives in VS code

Auto code formatting (action editor.action.format) breaks Jekyll (aka Github Pages) pages YAML front matter.

index.html before auto formatting:

--- 
layout: default 
title: Awesome page
bodyClass: homepage 
permalink: /
---
(rest of the content)

index.html after autoformatting:

--- layout: default title: Awesome page bodyClass: homepage permalink: / ---
(rest of the content is formatted ok, regular html syntax)

How can I tune up the VS code formatting rules?

like image 532
MatFiz Avatar asked Oct 13 '16 08:10

MatFiz


People also ask

How do I Auto beautify code in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

How do you prettify a code?

Step 1 — Using the Format Document Command To open the command palette, you can use COMMAND + SHIFT + P on macOS or CTRL + SHIFT + P on Windows. In the command palette, search for format and then choose Format Document. Then choose Prettier - Code Formatter.


1 Answers

To resolve this, you have two options:

  1. Turned off formatting of HTML files in settings.json file:

    "html.format.enable": false
    

    This turns off formatting off for HTML files. Not ideal, but gets the job done. There's a GitHub Issue for this, but it looks to have been closed.

  2. Consider installing the Liquid Languages Support extension then adding this to your settings.json:

    "files.associations": {
        "*.html": "liquid"
    }
    

This has resolved the issue for me.

like image 134
Chris Brown Avatar answered Sep 22 '22 14:09

Chris Brown