11ty / 11ty/webc

Is there a way to control space around WebC components?

Open
#200 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.4k
Forks
46
Avg merge
10m
Merged PRs (30d)
2

Description

Here is a case where I don't want extra space.

<!-- time.webc -->
<script webc:setup>
  function dateToAttribute(date) {
    return new Date(date).toISOString();
  }
  function readableDate(date, locale) {
    return new Date(date).toLocaleString(locale || "en-GB");
  }
</script>
<time
  :datetime="dateToAttribute(date)"
  :title="readableDate(date)"
  @text="readableDate(date)"
></time>

I'm using the <time> component in another file:

<!-- ... -->

<p>Last updated on <time :@date="metadata.now"></time>.</p>

<!-- ... -->

The compiled output is:

<!-- ... -->

<p>Last updated on 
<time datetime="2024-02-07T09:15:18.399Z" title="07/02/2024, 14:45:18">07/02/2024, 14:45:18</time>
.</p>

<!-- ... -->

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names WebC component templates and shows compiled HTML, but it names no source file, entry point, or test. Start by tracing how component output is inserted around surrounding inline text and compare the generated whitespace with the expected punctuation; done means establishing and verifying a supported way to avoid the extra space.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.