Utilize CSScomb in Sublime Text to add comments

A client of mine has requested extensive comments in the code, including within CSS files.

I had the idea to use CSScomb for reorganizing the CSS code and automatically adding comments. It may not be necessary, but why not give it a try?

The concept involves adjusting the configuration file to look like this:

[
    "font",
    "font-family"
],
[
    "padding",
    "margin"
]
...

and having an output that looks like this:

/* FONT STYLE */
font: ....;
font-family: ....;

Any suggestions on how to achieve this?

Answer №1

Customizing Group Commenting

If you want to enhance your coding experience, consider tweaking the sort-order.js file in the CSScomb package.

  1. To begin, with Sublime Text running, go to
    Preferences > Browse Packages…
    ; This action will unveil the Packages directory.
  2. In the Packages folder, locate
    CSScomb/node_modules/csscomb/lib/options/sort-order.js
    .
  3. To ensure a safety net, make a duplicate of this file before making any modifications. I saved my copy under the name of sort-order-original.js.
    Make a replica of this file in an alternate location for future reference if needed. I relocated my duplicate up one level into a fresh folder named
    ../originals/options/sort-order.js
    .
    Note: It's advisable to move it rather than simply rename it within the same directory to avoid unintentional activation by the module.
  4. Open sort-order.js in Sublime Text to start editing.
  5. Examine this comparison for the required amendments.
    Refer to this comparison for the necessary alterations. (This recent version introduces new logic to prevent repetitive group comments when utilizing CSScomb multiple times.)
  6. If you are content with the changes, meticulously substitute the entire contents of sort-order.js with the revised code. Feel free to adapt them further to align with your preferences. Save.
    Note: Essentially, these adjustments involve expanding each sorted object with an extra property that accommodates a CSS comment as specified by you in your User Settings. The upcoming step explains where to introduce the comments.
  7. You're now set to include comments based on groups. In Sublime Text, navigate to
    Preferences > Package Settings > CSScomb > Settings – User
    . If you haven't configured your personal settings yet, replicate the content from Settings – Default to Settings – User to get started.
  8. In the user settings document, search for the "sort-order" attribute. It comprises either a list of property names or nested arrays of property names. By default, CSScomb creates a blank line between nested array groups, but we've adjusted the file accordingly.
  9. You can optionally insert a comment as the first entry in any nested array. The sort-order.js file will recognize this and display it at the beginning of the group. If no comment is specified, a default empty line will appear instead.

Sample User Settings:

"sort-order": [
    [
        "/* LAYOUT */",
        "position",
        "z-index",
        "top",
        "right",
        "bottom",
        "left"
    ],
    [
        "/* DISPLAY */",
        "display",
        …
        "flex-align"
    ],
    [
        "/* TYPOGRAPHY */",
        "font",
        …
        "line-height"
    ],
    [
        …
    ]
]

Prior to CSScomb Execution:

.selector {
    font-family: Arial;
    line-height: 1;
    position: relative;
    display: block;
    background-color: red;
}

After CSScomb Processing:

.selector {

    /* LAYOUT */
    position: relative;

    /* DISPLAY */
    display: block;

    /* TYPOGRAPHY */
    font-family: Arial;
    line-height: 1;

    background-color: red;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it feasible to switch the classList of a form element that also has an event listener attached to it?

While I don't have a specific code snippet to share, I did have an idea and attempted to implement it. Unfortunately, it didn't yield the desired results. const validateEmailAddress = function (e) { const regex = /^[a-zA-Z0-9.!#$%&&apos ...

Tips for resizing user-uploaded images to fit the required dimensions outlined in the design draft using CSS or JavaScript

Hey everyone! I'm facing an issue but my English isn't great. I'll do my best to explain it thoroughly, and if anything is unclear, please feel free to let me know! So here's the problem: today there's a block for users to upload p ...

What is the best way to design a white arrow with a subtle touch of grey outlining?

Question: I am interested in creating a left-pointing arrow with a grey border. Currently, I have only managed to create a grey arrow without a border. Is there any way I can achieve this? Attached is a picture to illustrate what I'm looking for. An ...

Unlimited height dialog overlay exclusive to Facebook

It seems like a crucial matter that needs attention. My dialog has an overlay with specific width settings as shown below: .ui-widget-overlay { width: 518px !important; } The height of the overlay will vary based on the page size controlled by JavaS ...

Is it possible to create a dynamic input form that appears within a textarea using jquery?

I've designed a unique form using a textarea to display messages from users, rather than the traditional ul list. Additionally, I have included an input form where users can type their messages. My goal is to make this input form visible on the textar ...

What is the best way to display a Bootstrap v4 modal box within a container div?

Exploring the capabilities of Bootstrap v4.0.0-alpha has been an exciting experience, but I have a specific requirement in mind: I want to place a modal box inside a container div instead of it covering the entire screen. https://i.sstatic.net/xyZ8X.jpg I ...

What could be causing the disappearance of the search icon while using jQuery Mobile?

The label, text field, and search icon should all be displayed horizontally, but currently the search icon is not showing up in that layout. Check out my fiddle here: http://jsfiddle.net/yCUY7/ <div data-role="content"> <label class="searchL ...

Baffling Visibility Issue: iframe's Transparency Lost in Chrome and IE, Only Visible in Firefox

I have encountered a puzzling issue: http://jsfiddle.net/akosk/t2KvE/8/ HTML <div id='base'> <iframe id="myFrame" src="about:blank" frameborder="0" allowTransparency="true"></iframe> </div> <script id="conte ...

Is there a way to ensure a Javascript alert appears just one time and never again?

I struggle with Javascript, but I have a specific task that needs to be completed. I am participating in a school competition and need an alert to appear only once throughout the entire project, not just once per browsing session. The alert will inform ...

The hover effect generates a flickering sensation

I am having trouble displaying options on an image when hovering over it, as the displayed options keep flickering. $('a').hover(function(event) { var href = $(this).attr('href'); var top = $(this).next().css("bot ...

The carousel image slider seamlessly transitioning from the second image

I'm having an issue with the Carousel slider where it is overlapping the image from the second slide onwards. The first image loads properly, but subsequent images are not displaying correctly. Here's a reference image: https://i.sstatic.net/pyY ...

Ensure that the elements are properly arranged inside divs that have been stretched

My goal is to create divs that are all the same size, while aligning some content within each div differently due to varying lengths. The objective is to keep the icon and text in a consistent position within all divs, but allow the divs to expand at the ...

Aligning layers of images within a bootstrap column

Attempting to achieve something similar: Check out this Overlaying Image Example The challenge lies in the fact that these are absolutely positioned images, allowing them to overlap. I aim to center these overlapping images within a Bootstrap column as s ...

What could be causing the malfunction of the ::after selector in my code?

I am currently utilizing bootstrap 4 in my code and have implemented the following ::after styling for certain elements: .navbar-light .navbar-nav > li >a::after{ content: " "; height: 50px; width: 10%; background-image: linear-gradi ...

Participant joins in the game table and reacts

I am looking to set up a table where players can join and have their usernames displayed at the bottom of the screen just like in other games. How can I achieve this? export const GameStart = (props) => { const params = useParams(); const gameID = p ...

Positioning Elements at the Bottom with CSS

Here's the CSS code I have: .cmon { background-repeat: repeat-x; background-image: url("line2.png"); position:absolute; bottom:0px; } The goal is to have the image (a line in this case) placed at the bottom of the page and re ...

Adding margin padding to a Material UI Navbar: Step-by-step guide

Hey there, I've added buttons to my Navbar from Mui. However, I'm running into an issue where the margin and padding won't change no matter what I do. I'm trying to create some space between them. Please see the code below: import { use ...

Move the button to the following line and center it. Ensure that the background image remains at full size

.home{ background-image:url("https://cdn.pixabay.com/photo/2016/12/27/21/03/lone-tree-1934897_960_720.jpg"); background-repeat: no-repeat; height: 100vh; display: flex; align-items: center; justify-content: center; } .hero-text{ fon ...

Dynamically adjust the size of an image with CSS3 in relation to the width of its container, ensuring it does not surpass its original dimensions

I've been working on creating a Tribute page on CodePen.io and have successfully completed 9 out of the 10 tests as per the user stories. However, I am facing difficulties in resizing the image using CSS3. Despite trying various solutions found throug ...

What is the method for dividing a card image in half using bootstrap/css?

I'm attempting to divide this image in half and display the designed area on a card. Here is a screenshot for reference, but I'm unsure of how to achieve it: https://i.sstatic.net/7nNO4.png Below is the code I have so far: <div class="card ...