-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Customisable initial indent levels #11
Comments
that sounds like the |
If the proposal seems to be decent, I can implement the solution. This would be the major version bump as the options interface changes. I don't see an option for extending the current interface, as the negative indent would not be accounted for. |
Let me elaborate with examples.
|
You just want no indents? Why? That doesn’t seem very pretty? |
From one perspective, I agree. It does not look pretty when you write complete HTML. In contrast, I like writing code heavily omitting tags. When I start with the following template: <!doctype html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>Hello 👋</title>
<h1>Blog Title</h1>
<main>
<!-- imagine patching this with plugins -->
</main> After processing and reformatting, I get the result like below: <!doctype html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>Hello 👋</title>
</head>
<body>
<h1>Blog Title</h1>
<main><!-- processed code --></main> Relevant
|
What doesn’t look proper? How would it look proper? Why do you write pretty markup, format it, and then not use optional tags? Fine to write without them, as I do too, but why do you want to read formatted-but-no-optional-tags on a terminal?
Making things small or large are both formatting. |
I can make up a linting case for this. Imagine, you want to write HTML, then have some minor data patching like automatic wrapping dates following the ISO format into a My case is almost like that. Similarly to your personal website, I generate HTML pages from different sources using custom plugins and templates. Yet, I want the final result to look like it was written by hand: be concise and readable (not minified) and be easy to validate manually.
To make myself sound more accurate, I can use prettified instead. |
AST transforms and formatters are not for small changes. If you want to lint and do small changes, such as that example, write your own plugins, using the positional info on nodes, and splice the original source document. If that is your goal, these tools will never be what you want. Never indenting elements will not help you in that direction. With a more relaxed goal, concise and readable could mean to include the default of
I still wonder how you’d prefer a document to look |
Sorry, I missed to answer the question about the look. I expect it to remain in the same way as it was before processing: Input (copied from above)<!doctype html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>Hello 👋</title>
<h1>Blog Title</h1>
<main>
<!-- imagine patching this with plugins -->
</main> Output<!doctype html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>Hello 👋</title>
<h1>Blog Title</h1>
<main><!-- processed code --></main> (comment indentation is out of scope for this example and is only illustrative) |
In my case, the changes are not small. I cannot go without the formatter. For example, let's take a photo gallery page. It is generated by listing every file from a directory, ordered by date of update from git history. Every image entry is generated using To make the processing output look pretty, I need a formatter. Yet, it does not achieve 100% of the desired look. |
Right, your actual use case needs a code generator. That other use case where you only change some attributes of some elements, doesn’t need those.
There are two different projects:
The output you want cannot be made.
As I mentioned before, you can access the AST, and use its positional info. |
What you suggest, does make sense. I will look into ways to reformat only particular elements. As far as I am aware, there is no Would it be useful to have How do you feel about |
You don’t need utilities to do that. unified, and this plugin, run on fragments too. Not only on whole documents. You’re using It should work. If not let me know. A
I don’t see a good reason for someone to use this but never indent anything. Or to pass Your root question, to format “pretty” but omit optional tags, still seems vague. It is not clear to me how it would work. It would be a different API than |
Hi @wooorm @viktor-yakubiv , I also have a need for 0 indent everywhere. My use case is that Shopify rich text editor has 0 indent for some reason and I need to load their generated html into my own editor in a separate app running lexical.dev. If my own editor reformats it with anything other than 0 indent, it will be already dirty on load. Here’s an example of what Shopify editor outputs (you can see that even ol/li aren’t indented): <p>As the owner of Cool Barber Supplies, I've seen firsthand the importance of having the right tools and equipment in a barbershop. Running a successful barbershop is no easy feat, and having the right barber supplies can make all the difference. In this blog post, I'll share with you the 5 must-have barber supplies that every barbershop should have.</p>
<h1>1. High-Quality Clippers and Trimmers</h1>
<p>The backbone of any barbershop is the clippers and trimmers.</p>
<ol>
<li>These tools are used for everything from precision fades</li>
<li>to clean-up trims, and they need to be reliable</li>
<li>powerful, and easy to use.</li>
</ol> Thanks for all the great work! |
@Nedomas, as @wooorm already recommended to me, the best way might be to directly adjust the position after formatting. I assume, this should be something as straightforwars in your case as: const positionFixPlugin = () => (tree) => {
visit(tree, node => {
position.start.column = 0
position.end.column = 0
})
} I have not checked the code. You may need to add a simple test to adjust only (specific) elements (like For the reference, have a look at Also, you may consider removing any kind of position at all, and receive a generated HTML output, with no spacing at all, or apply |
This sounds like an XY problem. You use two tools. Both tools format many things differently. One thing is indent. If you “solve” indent, you will still have 100s of other things that are formatted differently. You have some root problem that isn’t about |
Related-to: rehypejs/rehype-format#11.
Closing as what the OP wants—no indent ever—can be done now. By passing I don’t think it’s a good idea, to support what was asked here ( In this thread, there was also sometimes a discussion about a “root question“ for “no changed at all”. There was also a side question about |
This comment has been minimized.
This comment has been minimized.
@wooorm thank you very much! |
Initial checklist
Problem
I want to align all children of head and body at 0-indent-level. Currently, there in an option only to indent it at the first level.
Solution
Replace
indentInitial
withinitialindentLevel
that makes aninitialIndent
by multiplying to theindent
option.Roughly speaking:
The default
initialIndentLevel
is1
for backward compatibility.For
indentInitial: false
, it would be0
;and
-1
for my case.Alternatives
Can be solved on the level of text roughly with the following command:
The text was updated successfully, but these errors were encountered: