Giter Club home page Giter Club logo

vscode-erb-beautify's Introduction

ERB Formatter/Beautify

Test   Release

Most of solution that exist in the internet is tell you to create a task and call it using ctrl-shift-p menu.

This extension basically using htmlbeautifier to format your file using the Formatter API from the vscode, so no need to create a hack using Task, etc.

Features

Demo GIF

Requirements

gem install htmlbeautifier

or

To use the gem with Bundler, add to your Gemfile:

gem 'htmlbeautifier'

NOTE: For you that have a filename with extension .html.erb, your file might be recognized as html file, not as erb file. In that case, add a setting in your settings.json like below:

"[erb]": {
  "editor.defaultFormatter": "aliariff.vscode-erb-beautify",
  "editor.formatOnSave": true
},
"files.associations": {
  "*.html.erb": "erb"
}

Known Issues

  • invalid byte sequence in US-ASCII

    Add below setting. Reference

    "vscode-erb-beautify.customEnvVar": {
      "LC_ALL": "en_US.UTF-8"
    }

Settings

Setting Description Default
vscode-erb-beautify.executePath Path to the htmlbeautifier executable, set this to absolute path when you have different htmlbeautifier location htmlbeautifier
vscode-erb-beautify.useBundler Execute htmlbeautifier using bundler (ie 'bundle exec htmlbeautifier'). If this true, vscode-erb-beautify.executePath is ignored false
vscode-erb-beautify.bundlerPath Path to the bundler executable, set this to absolute path when you have different bundler location bundle
vscode-erb-beautify.tabStops Set number of spaces per indent 2
vscode-erb-beautify.tab Indent using tabs false
vscode-erb-beautify.indentBy Indent the output by NUMBER steps 0
vscode-erb-beautify.stopOnErrors Stop when invalid nesting is encountered in the input false
vscode-erb-beautify.keepBlankLines Set number of consecutive blank lines 0
vscode-erb-beautify.customEnvVar Custom environment variables to pass to the htmlbeautifier {}

References

Issue

Issue

Ref

vscode-erb-beautify's People

Contributors

aliariff avatar dependabot[bot] avatar h-okhs avatar lpender avatar mikebobroski avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-erb-beautify's Issues

Literally does nothing...

I have installed this, and installed htmlbeautifier. I get no warnings but nothing happens when I click 'Format Document'.
How to debug this?

Appears to never end

image

When i hit ctrl+s This pops up and never goes away, the file never saves till i click Cancel. This is a new issue that started today but i could not think of any updates that I have done.

I went back and tried to uninstall/reinstall htmlbeautifier, you extention, apt update/apt upgrade reboot ... All same result.

What and where do i find the log files you may need

WSL2 issue

Hi,

How to set up the extension inside of WSL2?

In C:\Users\Me\AppData\Roaming\Code\User\settings.json, I added

    "vscode-erb-beautify.bundlerPath": "/home/me/.rbenv/shims/bundler",
    "vscode-erb-beautify.executePath": "/home/me/.rbenv/shims/htmlbeautifier"

but it triggers

couldn't run /home/me/.rbenv/shims/htmlbeautifier.bat 'spawn /home/me/.rbenv/shims/htmlbeautifier.bat ENOENT'

plugin forcefully adds final new line (does not respect vscode settings.json)

I would like to have one line of separation when needed in my erb files. I am able to do it with "vscode-erb-beautify.keepBlankLines": 1 setting.
However, I do not want to add a blank line at the end of my file when I formatted the file. Regardless of keepBlankLines setting (it does not matter whether it is 0 (default) or 1), I end up finding my file has 1 blank line at the end of it.

I tried to disable this behavior with "files.insertFinalNewline": true, but it does not work. I think the plugin overrides it. Because I managed to work it only when the plugin is disabled.
I am looking forward to a solution for this behavior, thanks!

Retain line breaks

It would be great if there were an option to retain line breaks that the developer places in the file intentionally to make readability of the partial easier. For instance:

<% page_title! "Project: #{project.name}" %>

<main>
  <header>
...

which currently gets turned into

<% page_title! "Project: #{project.name}" %>
<main>
  <header>
...

can't find htmlbeautifier MACOS

When running format document get this message.

couldn't find htmlbeautifier for formatting (ENOENT)

htmlbeautifier show.html.erb works from command line

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No vsce personal access token specified (set the VSCE_PAT environment variable).

Unfortunately this error doesn't have any additional information. Feel free to kindly ask the author of the semantic-release-vsce plugin to add more helpful information.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Failed when formating UTF8 characters

Hi,

When I try to format a file that has UTF8 characters as á I get this error.

failed with exit code: 1. '/home/bruno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/htmlbeautifier-1.4.2/bin/htmlbeautifier:12:in `rescue in beautify': Error parsing standard input: invalid byte sequence in US-ASCII on line 1 (RuntimeError) from /home/bruno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/htmlbeautifier-1.4.2/bin/htmlbeautifier:9:in `beautify' from /home/bruno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/htmlbeautifier-1.4.2/bin/htmlbeautifier:111:in `<top (required)>' from /home/bruno/.rbenv/versions/3.1.2/bin/htmlbeautifier:25:in `load' from /home/bruno/.rbenv/versions/3.1.2/bin/htmlbeautifier:25:in `<main>' /home/bruno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/htmlbeautifier-1.4.2/lib/htmlbeautifier/parser.rb:37:in `rescue in dispatch': invalid byte sequence in US-ASCII on line 1 (RuntimeError) from /home/bruno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/htmlbeautifier-1.4.2/lib/htmlbeautifier/parser.rb:31:in `dispatch' from /home/bruno/.rbenv/versio...

This is because LC_ALL=en_US.UTF-8 is set in the htmlbeautifier command.

If I run htmlbeautifier with htmlbeautifier file.html.erb file.html.erb it works fine, but if I run it with LC_ALL=en_US.UTF-8 htmlbeautifier file.html.erb file.html.erb it fails with the same error and an additional warning.

bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

Thanks

Document how to format .html.erb files

It took me a while to figure out why it wasn't working on my .html.erb files, and I discovered I just had to add this to my settings.json:

"files.associations": {
  "*.erb": "erb"
}

Otherwise it was counting them not as erb files, but html.erb files - it would be helpful to note this in the installation/config requirements.

Cannot read properties of undefined (reading 'apply')

Have recently been getting this error and autoformat no longer works... Any ideas? Originally, I thought it was the new version of the VSCode plugin, but I don't think it is.

Screenshot 2024-04-01 at 2 02 17 PM

Currently using htmlbeautifier 1.4.3. Also, when I manually run htmlbeautifier via the command line, it works.

Problem when I launch the command "Format Document"

Hi,

When I run the command Format Document while I am in a .html.erb file, nothing happens, there is just a file that is created. For example, if I run the command in a file called _small_panels.html.erb, a file will be created called _small_panels.html.erb.tmp and that's it.

Capture d’écran 2019-09-11 à 11 15 29

my settings.json

{
    "workbench.colorTheme": "Gruvbox Dark Medium",
    "workbench.iconTheme": "material-icon-theme",
    "editor.fontSize": 15,
    "emmet.includeLanguages": { "erb": "html" },
    "files.associations": {
        "*.erb": "erb"
    }
}

Thank !

Not working with non ascii on MacOSX

I found the issue with the files that contain non-ASCII characters.
When I try to format them, nothing happens.
After investigated, I found a way to fix it. You need "LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8" before run htmlbeautifier.
const beautify = cp.spawn(``LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 htmlbeautifier${ext}``, [ ...options, document.uri.fsPath ], { shell: true });

Customize htmlbeautifier execution arguments

Hello and thanks for this plugin!

Do you have any plans to support custom execution arguments?

E.g. a settings option to edit the htmlbeautifier command line options, say, htmlbeautifier -b 4

Ty!

Empty file after formatting / save

I'm using VSCODE Version: 1.85.2 (Universal) on Mac with latest plugin version.

I don't know how to debug my problem because there are no faulty logs in vscode console, but after saving some erb files I can see that the whole content disappear and I can only get an empty file, and then file is saved empty losing the erb totally.

How can I debug this issue and solve ?
Thanks
Max

The gif on the README does not render

linking to a google drive gif is a bad idea

I've recorded a gif, placed it in the root directory and updated the README.

I'd be happy to open a PR

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid vsce personal access token. Additional information:

Error: Command failed with exit code 1: vsce verify-pat
::error::Can not read the publisher's name. Either supply it as an argument or run vsce from the extension folder. Additional information:%0A%0AError: @types/vscode ^1.86.0 greater than engines.vscode ^1.74.0. Consider upgrade engines.vscode or use an older @types/vscode version

Unfortunately this error doesn't have any additional information. Feel free to kindly ask the author of the semantic-release-vsce plugin to add more helpful information.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Ctrl + / does not add comment block

When editing a .html.erb file, pressing keys Ctrl + / adds # which is not helpful. It should add <!-- --> instead which is appropriate because we are writing in HTML.

Self closing tags

Hi, this is a great plugin - I have one small issue - if the tag is self closing (<img ... / >) is screws up the formatting (It's fine if I do this <img ...>)

Error parsing standard input: invalid byte sequence in US-ASCII

image

example:

<h1>工作项列表</h1>
<button class="btn btn-primary" type="button">Primary</button>
<table>
  <thead>
    <tr>
      <th scope="col">Table header 1</th>
      <th scope="col">Table header 2</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td>Table footer 1</td>
      <td>Table footer 2</td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>Table data 1</td>
      <td>Table data 2</td>
    </tr>
  </tbody>
</table>

Format .js.erb

And about the .js.erb files?
I guess this extension is specific to html.erb.
Someone has some suggestion for .js.erb?

Support older VS Code versions

I noticed that this extension only supports versions greater than 1.86.0.

 "vscode": "^1.86.0"

Is there a reason for this? It would be great to support slightly older versions, even just 1.80.0

Couldn't run htmlbeautifier 'spawn htmlbeautifier ENOENT'

Hi - when I edit the settings.json in VSC with the following:

"[erb]": {
"editor.defaultFormatter": "aliariff.vscode-erb-beautify",
"editor.formatOnSave": true
},
"files.associations": {
"*.html.erb": "erb"
}

and subsequently try to save/format the document, I get the following error(s):

"Couldn't run htmlbeautifier 'spawn htmlbeautifier ENOENT'" &
"Error occurred while formatting: spawn htmlbeautifier ENOENT"

Any ideas on what causes this?

BR Nicklas

unicode characters turns ���

I tried to try to format a file that has UTF8 characters, such as Japanese letters, but it gets like this sometimes ���
if I run htmlbeautifier directly (without vscode-erb-beautify) it seems fine.

Can this be fixed by setting?

Support for vscode Format Selection

It would be great if there was support for formating a selection of code as opposed to formating the whole document. Would be a useful addition if there is scope to add your extension - or have I missed something in my configuration?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.