-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Is there a way to control space around WebC components? #200
Comments
Does your |
Yes, it does. My My |
I tested it and the space before the period is gone without the blank line (with your code). The complete code doesn't have a blank line at the end but after the |
Thanks, @rothsandro, for looking into it. But, I was looking for a more generic solution. You know, when working with projects configured with Prettier and EditorConfig, especially when many people are contributing, it is difficult to keep a file or two without a newline at the end. I know this a rare problem, though I have encountered a handful of times in the past, and Nunjucks's whitespace control came handy. At this time, I'm using with Eleventy Transforms to go around this issue. Probably an over-engineered solution. 😄 // eleventy.config.js
eleventyConfig.addTransform("trim-whitespace", function (content) {
const trimCommentsRegex =
/\s*<!---*\s*trim-whitespace(?:="(?<count>\d+)")?\s*-*-->\s*/gim;
return content.replaceAll(trimCommentsRegex, function (_match, countStr) {
const count = +countStr;
if (!isNaN(count)) {
return " ".repeat(count);
}
return "";
});
}); Then, in places where I want to trim white spaces, I can insert an HTML comment, <!-- sample.webc -->
<p>
Last updated on
<time :@date="metadata.now"></time>
<!-- trim-whitespace -->.
</p> <!-- Output HTML file -->
<p>
Last updated on
<time datetime="2024-02-21T14:16:56.311Z" title="21/02/2024, 19:46:56">21/02/2024, 19:46:56</time>.
</p> |
Here is a case where I don't want extra space.
I'm using the
<time>
component in another file:The compiled output is:
i.e.
Last updated on 07/02/2024, 14:45:18 .
, with a space before the period.Though I use the whitespace control when using Nunjucks, I'm not expecting such a feature in WebC.
What would be a workaround for such scenarios?
The text was updated successfully, but these errors were encountered: