Skip to content
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

fix: strip extraneous linebreaks in pretty dom #45

Merged
merged 3 commits into from Jan 14, 2023

Conversation

KonnorRogers
Copy link
Owner

@CreativeTechGuy I think you'll like this much more!!

Heres an example three shadow roots deep:

Before
<body>
  <div>
    <triple-shadow-roots>
      <ShadowRoot>


        <nested-shadow-roots>
          <ShadowRoot>


            <duplicate-buttons>
              <ShadowRoot>


                <slot
                  name="start"
                />


                <button>
                  Button One
                </button>


                <br />


                <slot />


                <br />


                <button>
                  Button Two
                </button>


                <slot
                  name="end"
                />


              </ShadowRoot>
            </duplicate-buttons>


          </ShadowRoot>


        </nested-shadow-roots>


      </ShadowRoot>
    </triple-shadow-roots>
  </div>
</body>
After
<body>
  <div>
    <triple-shadow-roots>
      <ShadowRoot>
        <nested-shadow-roots>
          <ShadowRoot>
            <duplicate-buttons>
              <ShadowRoot>
                <slot
                  name="start"
                />
                <button>
                  Button One
                </button>
                <br />
                <slot />
                <br />
                <button>
                  Button Two
                </button>
                <slot
                  name="end"
                />
              </ShadowRoot>
            </duplicate-buttons>
          </ShadowRoot>
        </nested-shadow-roots>
      </ShadowRoot>
    </triple-shadow-roots>
  </div>
</body>

No, I have no idea why these extra spaces popup...since it only affects shadow roots I'm kind of confused...perhaps something in serialization? Idk. But it works now.

@KonnorRogers KonnorRogers force-pushed the konnorrogers/fix-whitespace-in-pretty-dom branch from 4df77ad to 9970a57 Compare January 14, 2023 21:38
@KonnorRogers KonnorRogers force-pushed the konnorrogers/fix-whitespace-in-pretty-dom branch from 9970a57 to 0abad42 Compare January 14, 2023 21:49
@KonnorRogers KonnorRogers merged commit 863475c into main Jan 14, 2023
@KonnorRogers KonnorRogers deleted the konnorrogers/fix-whitespace-in-pretty-dom branch January 14, 2023 21:52

function removeDuplicateNewLines(str: string) {
let final = str.replace(
new RegExp(`${findWhiteSpace}.*${findWhiteSpace}{2,}`, "g"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this mess with a string like abc ? (<space>abc<space><space>)? The .* part is what raised red flags in my head.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s testing against line breaks + empty space first, in testing with template literals it doesn’t seem to affect it.

@CreativeTechGuy
Copy link

Awesome thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants