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

A vertical bar | is not handled properly. #61

Open
shinnkondo opened this issue Jul 29, 2015 · 0 comments
Open

A vertical bar | is not handled properly. #61

shinnkondo opened this issue Jul 29, 2015 · 0 comments

Comments

@shinnkondo
Copy link

html2haml does not treat | well when it appears as the last character of an element.

Problem

Let's say I have the following html.

<span>|</span>

It is converted to

%span |

in haml, which is rendered back to

<span></span>

in html. As you can see, the | is missing because it at the end of line is treated as a line separator.

Solution

One solution is to print the following as a haml:

%span 
  |

Using ruby works, too.

%span= "|"

But don't know if converting a plain text to ruby is a good thing to do.

When this happens?

I had this case when I was to print links in a loop, with | as separator(Just imagine a category sub-header like "Ruby | Haml" for an article ).

It might be the case that I can avoid the problem by the way I write html, but it would be nice if conversion works for any html.

So what I want?

I am guessing that https://github.com/haml/html2haml/blob/master/lib/html2haml/html.rb#L389 (where it checks if text can be in the same line as a parent element) would be a good place to check |;(Code and and after is what I added)

if !child.to_s.include?("\n") and !uninterp(child.to_s).end_with?(Haml::Parser::MULTILINE_CHAR_VALUE)

It passed the tests, and works fine with my case.

If that looks OK, I would write a pull request, or someone can integrate this.
If not, any suggestion, comment, advice, or fix would be appreciated.

@shinnkondo shinnkondo changed the title a vertical bar (|) is not handled properly. A vertical bar (|) is not handled properly. Jul 29, 2015
@shinnkondo shinnkondo changed the title A vertical bar (|) is not handled properly. A vertical bar | is not handled properly. Jul 29, 2015
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

1 participant