donpark / html2jade

Converts HTML to Jade template. Not perfect but useful enough for non-daily conversions.
MIT License
1.18k stars 156 forks source link

Option to skip the auto trim #106

Closed ferdinando-ferreira closed 6 years ago

ferdinando-ferreira commented 8 years ago

Greetings and thanks for the excellent software.

In the same spirit of the issue #76 the white spaces are getting removed in certain cases where they could be meaningful in the final render.

Taking advantage of the example given in the issue mentioned above, with the sole addition of a leading space before the word "Hey"

<p> Hey there, <a href="#">html2jade</a> <strong>is awesome</strong></p>

In the current version it becomes:

html
  body
    p
      | Hey there, 
      a(href='#') html2jade
      |  
      strong is awesome

trimming the space before "Hey".

My request is that there should exist an option to indicate that whitespaces should not be auto trimmed, so the result of that same conversion could be

html
  body
    p
      |  Hey there, 
      a(href='#') html2jade
      |  
      strong is awesome

keeping the extra space before "Hey".

To allow for this behaviour to be optional my suggestion is the creation of a new option: skipautotrim.

The changes are simple, sorry for not making that a Pull request, not entirely familiarized with git yet.

html2jade.coffee, line 64

    @noEmptyPipe = options.noemptypipe ? false

becomes

    @noEmptyPipe = options.noemptypipe ? false
    @noAutoTrim = options.noautotrim ? false

html2jade.coffee, line 152

    line = line.trimLeft() unless node?.previousSibling?.nodeType is 1
    line = line.trimRight() unless node?.nextSibling?.nodeType is 1

becomes

    if @noAutoTrim
      line = line.trimLeft() unless node?.previousSibling?.nodeType is 1
      line = line.trimRight() unless node?.nextSibling?.nodeType is 1

That would be very helpful because in certain cases the trailing and leading whitespace adds to the total width of the element, font icons, for instance. Making the change this way is back compatible and optional.

Best regards

donpark commented 8 years ago

looks like a reasonable feature. can't promise when though. if you need this in a hurry, please fork.

ferdinando-ferreira commented 8 years ago

Thanks for the response.

No hurry, considering this is only a dev dependency of a private project I already changed what I needed locally.

If you prefer I can (learn how to and) send the change as a Pull Request. The change should be very similar to the one in the 693186f1bb1667a89f7612721744745b8acf5d4e commit.

donpark commented 8 years ago

@ferdinando-ferreira yes, PR would be wonderful. thx

ferdinando-ferreira commented 6 years ago

Closing for lack of interest