gulp-html-replace icon indicating copy to clipboard operation
gulp-html-replace copied to clipboard

Added 'useCRLF' option

Open evergreen-lee-campbell opened this issue 9 years ago • 6 comments
trafficstars

Added a 'useCRLF' option to prevent a new linefeed appearing every time the gulp task is run on Windows machines.

Resolves #42

evergreen-lee-campbell avatar Jul 08 '16 16:07 evergreen-lee-campbell

Coverage Status

Coverage decreased (-0.6%) to 97.484% when pulling fab0d057fc8ff7819b42b23ac3868be3ab83fceb on evergreen-lee-campbell:master into 38e66fd157e8d243e70e099b89382b3dc321a99a on VFK:master.

coveralls avatar Jul 08 '16 16:07 coveralls

@evergreen-lee-campbell Thank you for your contribution. I really can't reproduce #42 I created test files with Windows Notepad and Sublime Text with "windows line endings" options and no matter how many times i run this plugin i don't see additional linefeeds. Maybe i'm doing something wrong though so i guess we can do something like your PR. But i have some questions:

  1. If the whole difference is that one \r in regex, could something like this:
/(\r?\n?)([ \t]*)(<!--\s*build:(\w+(?:-\w+)*)\s*-->)\n?([\s\S]*?)\n?(<!--\s*endbuild\s*-->)\n?/ig

or

/(\n?|\r\n?)([ \t]*)(<!--\s*build:(\w+(?:-\w+)*)\s*-->)\n?([\s\S]*?)\n?(<!--\s*endbuild\s*-->)\n?/ig

just work without any new config options? Could you test it please? 2. Could you change tabs to 4 spaces please? Formatting is pretty broken.

VFK avatar Jul 10 '16 07:07 VFK

I like this option. And I already use @evergreen-lee-campbell 's repository in my package.json.

UncleBill avatar Nov 30 '16 03:11 UncleBill

Notepad and sublime aren't attempting to do line endings normalization and basically ok with mixed LF and CRLF in one file. But if one using Visual Studio or there is a git autocrlf then there is an extra lines problem.

Regexp that solved problem for me: var regex = /(\n|\r\n)?([ \t]*)(<!--\s*build:(\w+(?:-\w+)*)\s*-->)([\s\S]*?)(<!--\s*endbuild\s*-->)(\n|\r\n)?/ig;

aschekatihin avatar Mar 15 '17 08:03 aschekatihin

I have tried, modified my local dependent version as what @evergreen-lee-campbell committed. it works fine! why @VFK doesn't merge it to master and release it?

chaijunkun avatar Jan 31 '19 08:01 chaijunkun

I wrote a test case project as below: https://github.com/chaijunkun/gulp_test

  1. npm install 2.npm test

template file is from src/index.html, and output file is dist/index.html. in macOS, there will be two 0x0a (s) between the two tags:

endbuild build:seg_2

but in Windows, the character 0x0a presents 3 times between the two tags.

chaijunkun avatar Jan 31 '19 09:01 chaijunkun