How to force prettier html formatting to format tags in one line? - html

I use prettier in my VSC, so how to force prettier HTML formatting to format tags in one line, not multiple lines?
I want to format something like this all in one line
<v-navigation-drawer :clipped="$vuetify.breakpoint.lgAndUp" v-model="drawer" fixed app>
Does exist any config for prettier HTML formatter?

Prettier has the option printWidth. If you set that option to a high number, it will break fewer lines.
In your .prettierrc.json file, you can override this option for your HTML files:
{
// Other options...
"overrides": [
{
// change .html with .vue if you are using Vue files instead of HTML
"files": "src/**/*.html",
"options": {
"printWidth": 140
}
}
]
}
Is not recommendable to use a line-lenght higher than 140. Prettier is opitionated, so it should be used without too many customizations.

First check if you have a filename .prettierrc in the root. If no, create it and then put these values in it.
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"printWidth": 3000,
"bracketSpacing": true
}
Set printWidth to something large value and toggle wrapping text with your editor whenever you want; for example, in VS Code: Alt+Z.

I know this topic is old but maybe others still have this issue. In the Prettier setting you can adjust the width of the Print Width. 120 width does the job for me.

It depends on your IDE settings but as documentation states, you should have a config file where you should look for the html.format.wrapLineLength property and apply the line length value which satisfy you. This will prevent Prettier to break your lines until assigned line length to the property is reached. This will only apply for HTML.
For overall purposes you should use prettier.printWidth property which
Fit code within this line limit
Mind that tabulation / indention spaces also count in the line length.
Unfortunately when code line exceed the above numbers it will be spited to multi-lines, each property per line. So far I did not find solution to just wrap to extra line, without spiting to multi.
UPDATE
Mentioned and desired by me behavior it is not affordable with Prettier, but the line length trick still can do the job ... partially.

Related

htmlclean grunt task to not supress spaces separated by tags

I am using the htmlclean grunt task ( https://github.com/anseki/grunt-htmlclean ), it is doing job correctly. However the removal of some spaces has caused display issues, for example:
<span>
to <a></a>
</span>
Gets cleaned to:
<span>to<a></a></span>
The spaces before and after the word 'to' is very important. I've had a look at the options of the task however I cannot see how to configure the task to respect such spaces.
The htmlclean task allows using the protect option to prevent stripping whitespace from matching strings. You can set a regex that matches a word followed by an opening tag, e.g.
grunt.initConfig({
htmlclean: {
options: {
protect: /\w(\s+)</g
}
}
});
See https://github.com/anseki/grunt-htmlclean#overview for the options.

quick formatting shortcut sublime text

I was wondering if someone had the sequence of steps to accomplish this task, inline, without copy and pasting.
Imagine you have a block of code where things are not cleanly justified
{
foo: "foo value",
bar: "bar value",
reallylongvariable: "reallylongvariable value",
shortname: "shortname value"
}
is there a very quick way to transform it in this, justifying the spaces and ragged spacing to a unified formatting
{
foo: "foo value",
bar: "bar value",
reallylongvariable: "reallylongvariable value",
shortname: "shortname value"
}
I know about option selection. Generally, I follow these steps
option select a column,
paste it on a new set of lines,
reselect pasted content
use command + [ to remove indention,
option reselect column of unindented content
past back in place in the original column.
But this process feels very manual, and was wonder if there was way to clean up the indentation inline, without copy and paste. Perhaps a helper utility that can do this automatically within a highlighted selection.
Hopefully my question makes sense.
There are multiple plugins for this task, for example:
https://github.com/wbond/sublime_alignment
https://github.com/randy3k/AlignTab
Here you can search for all of them: https://sublime.wbond.net/search/align
I personally recommend the AlignTab. It may seem complex, but if you know how to use regular expressions it is the most powerful you will find. It may do some crazy magic if you get used to it.

Sublime Text 2: soft wrap lines -> reverse indentation?

I've started using Sublime Text 2, and its community of plugins, as my Dreamweaver replacement (thank the Gods). I love Sublime and clearly won't realize many of its features for months or years to come, but there's a simple setting I've had trouble figuring out.
I've used BBedit lots in the past. One feature I'm very attached to is the ability to "reverse" indent lines when soft-wrapped, such that line wrapping looks like this:
Text text blah blah blah blah long enough to wrap
to a new line blah whenever soft wrap happens it
reverse-indents like this.
Here's a new line with no indent.
Maybe I shouldn't be so married to a seemingly minor feature, but I find it much easier to read code when it's not possible to confuse the beginning of a line with "tailings" of a long line. Does anyone know how to do this in Sublime?
After further use, I think I've figured this out. Apparently Sublime's default (and only) behavior is to reverse-indent code lines, but leave html lines flush. So when I'm editing a PHP/HTML document, my wrapped lines will reverse-indent about half the time, depending on whether I'm in an tag or in a fragment at that line break.
The effect on my code is something like this:
<!-- Wrapped HTML doesn't reverse indent -->
<a href='long_link_that_causes_lines_to_wrap' other_attribute='
jquery_thing_that_makes_lines_wrap'>something</a>
...
<!-- Wrapped PHP snippets do reverse indent -->
<? echo date('M jS', strtotime('some_interpolated_formatting_string',
$some_variable_expression)); ?>
Sublime uses JSON files to store your preferences. The default file lists the settings that it uses by default, and you can override them by adding them to your user file.
The preference that controls hanging indent is word_wrap:
// Disables horizontal scrolling if enabled.
// May be set to true, false, or "auto", where it will be disabled for
// source code, and otherwise enabled.
"word_wrap": "auto",
As shown above, the default value is auto which only wraps lines that are not considered source code. To get hanging indent on all lines in a file, you need to set it to true in your user preferences file:
"word_wrap": true,

Flex4.6 StyleableTextField ignores <br> and <p> tags

I've got a StyleableTextField in my mobile project, which gets filled with html text using the .htmlText property.
The tag is working fine for me, but simple line breaks or paragraphs are simply ignored. What can I do about that?
Basically, the simplest HTML will just be displayed as a single line:
textField.htmlText = "<p>this should be the first line</p><p>this the second one</p>";
Again, the output is a single line.
The Flex 3 doc states that those tags are definitely supported, so I reckon they simply removed it in the newer versions (which is kinda ridiculous!).
I don't want to use the stagewebview, so what other ways to I have to properly format HTML using the StyleableTextField, or is there a simple replacement for the aforementioned tags?
Thank you very much guys!
Make sure that multiline is set to true, otherwise it will treat it as a single line of text, effectively ignoring the formatting.

How to modify how TinyMCE format text

TinyMCE color formating is putting in to span tag,
now I need when ever user change color for a text add
one extra character
(for those who may wonder way I need this, read this: Inserting HTML tag in the middle of Arabic word breaks word connection (cursive))
so this is how TinyMCE normaly format text:
<p><span style="color: #ff6600;">forma</span>tings</p>
this is how I need to be:
<p>X<span style="color: #ff6600;">forma</span>tings</p>
so before any span I need to add one extra character.
I was searching throug TinyMCE source but I couldn't find where it assembly this.
I totaly understand your need for a word-joiner.
Depending on the browser you might be able to insert this character using a css-pseudo element - in this case before: http://www.w3schools.com/cssref/sel_before.asp
Your tinymce content css (use the tinymce init setting content_css) should contain the following:
body span:before {
content:'\2060'; // use '\00b6' to get something visible for testing
}
UPDATE: Approch2:
You can do this check to enter your word joiners:
var ed = tinymce.get('content') || tinymce.editors[0];
var span = $(ed.getBody()).find('span:not(.has_word_joiner)').each(function(index) {
ed.selection.select(this);
ed.execCommand('mceInsertContent', false, '\u2060<span class="has_word_joiner">'+this.innerHTML+'</span>'); // you might want to add the formerspan attributes too, but that is a minor issue
});
You might need to call this using an own plugin on special events.