Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Wrap orphaned text #274

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants

Added an option to wrap orphaned text in paragraph elements.

This currently does not immediately reflect the change in the design editor - I welcome suggestions for superior alternatives that do provide immediate update without (for example) nuking the user's cursor position or otherwise messing with work in progress.

Take this block for example:

Test1
<div>
    Test2
    <ul>
        <li>Test3</li>
    </ul>
    Test4
</div>
<div>
    Test5
</div>
<span>Test6</span>
<div>
    Test7
    <span>Test8</span>
</div>
Test9

In this example, I would consider the following to be "orphaned":

  • Test1, 2, 4, 7, 9

So essentially, any text that is not the exclusive content of the tag that wraps it, or any text that is not wrapped in a tag at all.

This could also be up for debate: would everyone consider all of these scenarios to truly be "orphaned"? To me in my use case it is, but I don't know if everyone would agree. It is possible that this needs to allow for more flexible options.

unknown Added a "wrapOrphanText" option, to allow those who want it to have a…
…ny orphaned text wrapped in paragraph elements.

This currently does not immediately reflect the change in the design editor - I welcome suggestions for superior alternatives that do provide immediate update without (for example) nuking the user's cursor position or otherwise messing with work in progress.
efc3e74
Contributor

Tudmotu commented Jan 25, 2012

ok, first of all, thanks (:
second, i really like regexp, but the issue with them is that its very difficult to test them.
And since i was not here for a long time, i think it's best that akzhan confirms this...

Yotam,

n/p, hopefully it is useful for people!

Yeah, I totally know where you're coming from on regexp. I always end up holding my nose whenever I have to write a regular expression. I'm sure that somewhere out there some crazy person can read that stuff like English, but it sure isn't me... and it's definitely rough to test for all possible scenarios.

Contributor

Tudmotu commented Jan 26, 2012

Some suggestions:

  1. Your code only wraps in <p> tags. What if i want orphand text to be inside a div? More over, what if i want that div to have a certain class? At the very least we should enable to choose between div/p/span.
  2. I think there's a better way to achieve this, without using regexp. Regexp are powerful and efficient, no doubt, but as i said before - very hard to debug.. And on every fix we need to do a new debug cycle. I would suggest using jQuery in order to obtain the orphan text objects:
    http://forum.jquery.com/topic/jquery-wrap-tagless-text-fragments
    Though it might be a lot trickier than what's described ^there.

Yotam.

Very true, we could definitely add #1 easily... and I could definitely see the benefit of that.

As far as a better way to achieve the result without regexp - good find on that tagless text fragments post! I did some searching online to see how others handle this issue, and I was coming up with nothing.

I'll take a closer look at that and see if I can get it to resolve the scenarios we need... and see if potentially if there's a way to intercept the changes in design mode instead of at save time. I really would like to see the end result of this solution immediately reflect the alterations in design mode, and perhaps a solution using jQuery selectors and injection might not nuke the state of the user's current cursor position like my regexp approach does when I try to apply it to the design panel.

I'll iterate on this again given this find, and add the configurability you mentioned in suggestion #1... and see if it does the trick. I'm not certain if I'll be able to get back to it today, but I'll try to get on it this weekend if I can't find time today.

Contributor

Tudmotu commented Feb 1, 2012

Hey,
Sorry for the late reply, i'm having issues with my comp so it's hard to follow on github :)
Anyway, once i'll get my comp up and running again i'll also take a look at this feature.

Yotam.

Owner

akzhan commented Feb 7, 2012

@Tudmotu, feel free to review and merge it. I have no time yet.

Hey guys, sorry I've been away on this for a bit. Indeed, I can make changes as you recommend - I just need to find some free time with which to modify it, which has been in short supply lately.

Owner

akzhan commented Mar 13, 2012

Will wait for.

Contributor

stianlik commented Jan 16, 2013

Before seeing this, I created something similar for Firefox and created a pull request: #353

Is this an issue in other browsers that Firefox? I did not experience any orphaned text in Chrome.

Owner

akzhan commented Jul 26, 2016

Closed due to #353.

@akzhan akzhan closed this Jul 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment