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

XML/HTML: place several children on separate lines when splitting #147

Open
kiryph opened this issue Nov 16, 2018 · 2 comments
Open

XML/HTML: place several children on separate lines when splitting #147

kiryph opened this issue Nov 16, 2018 · 2 comments

Comments

@kiryph
Copy link

kiryph commented Nov 16, 2018

Example xml file:

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4"> <data key="d1">1.1</data> <data key="d2">1.1</data> </edge>
</graph>

Place cursor on second line and press gS.

Expected output

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4">
        <data key="d1">1.1</data>
        <data key="d2">1.1</data> 
    </edge>
</graph>

Current Output:

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4">
        <data key="d1">1.1</data> <data key="d2">1.1</data> 
    </edge>
</graph>

The other direction works. But I would like to have a space between all tags:

Expected Output on Join:

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4"><data key="d1">1.1</data> <data key="d2">1.1</data></edge>
</graph>

Current Output on Join:

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4"><data key="d1">1.1</data> <data key="d2">1.1</data></edge>
</graph>
@AndrewRadev
Copy link
Owner

AndrewRadev commented Dec 15, 2018

I can see this making sense, but it's not something that would work in all cases. I have an implementation locally (for splitting, at least) that I haven't pushed yet. It splits the above example like this:

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4"> <data key="d1">1.1</data> <data key="d2">1.1</data> </edge>
</graph>

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4">
        <data key="d1">1.1</data>
        <data key="d2">1.1</data>
    </edge>
</graph>

But what do we do about text nodes?

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4"> Foo <data key="d1">1.1</data> Bar <data key="d2">1.1</data> Baz </edge>
</graph>

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4">
        Foo <data key="d1">1.1</data>
        Bar <data key="d2">1.1</data>
        Baz 
    </edge>
</graph>

This doesn't look terrible, but what about common HTML patterns like embedded links:

<p>Some text <a href="http://example.com">with a link</a> and <strong>text</strong> for emphasis</p>

<p>
  Some text <a href="http://example.com">with a link</a>
  and <strong>text</strong>
  for emphasis
</p>

This doesn't look that good, because there's no particular reason to split the text nodes like this, other than trying to get all the end nodes to break a line (which is the literal implementation of the feature).

I could hide it behind a setting (and I currently have, in my local implementation), but this seems like something that makes sense on a case-by-case basis, rather than globally. Do you think it would make sense to only do this if there's no text nodes (although I have no idea how I'd implement it -- I just use Vim's built in "select inner tag" functionality, not an XML parser)? Do you think it'd make sense to implement it this way in XML, but not in HTML (the setting can be applied per-filetype, so that would be flexible)? If you can come up with some sensible, consistent handling of text nodes, that would be ideal, but I can't imagine a one-size-fits-all solution.

As for joining, I don't actually see a difference between the "current" and "expected" output, maybe you accidentally pasted the same thing? But maybe you mean you expect something like this?

<edge id="e6" source="n5" target="n4"> <data key="d1">1.1</data> <data key="d2">1.1</data> </edge>

This is what you'd get from applying the normal-mode mapping vatJ, but for consistency's sake, I can make an option for joining to just do that. But if it's something more complicated, I'll have to consider it.

@MuhammadSawalhy
Copy link

MuhammadSawalhy commented Aug 11, 2021

This doesn't look that good, because there's no particular reason to split the text nodes like this

In some cases which contains text with tags such as the case you provided, IMHO it will be reasonable to make the text wrap with a specific width that can be configured with let g:splitjoin_wrap_width = 80

<p>Some text that is some how long enough, <strong>stronged</strong><em>emphasised</em>, <a href="http://example.com">with a link that
  has a link text as well</a>,Some other text is here</p>

<p>
  Some text that is some how long enough, <strong>stronged</strong> 
  <em>emphasised</em>, <a href="http://example.com">with a link that
  has a link text as well</a>, Some other text is here
</p>

Or just we can disable splitjoin in cases like this using let g:splitjoin_edge_cases = 1, and just split and join in cases like the first case only:

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4"> <data key="d1">1.1</data> <data key="d2">1.1</data> </edge>
</graph>

<graph id="G" edgedefault="undirected">
    <edge id="e6" source="n5" target="n4">
        <data key="d1">1.1</data>
        <data key="d2">1.1</data>
    </edge>
</graph>

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

No branches or pull requests

3 participants