Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Added possibility to specify End of Line character in output #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Added possibility to specify End of Line character in output #9

wants to merge 4 commits into from

Conversation

mlewand
Copy link

@mlewand mlewand commented May 17, 2014

What's the issue?

Currently node-pygmentize-bundled adds OS-specific line endings to output, even if input source code has diffrent line endings. I've faced this issue while working with grunt plugin which is using this project.

Since Windows by default uses \r\n as its EOL, it started to result with files having both \n and \r\n mixed in.

I've started to dig it a little bit, and tested Pygments itself, but it was managing EOLs as expected.

Because of this issue node-pygmentize-bundled tests were failing too at Win.

Design concept:

I didn't change the defalut behaviour, lines will be changes only when the options.eol property will be set - this way it will keep backward compatibility.

I've added a note to options list in README.md.

What I've done here?

index.js modifications:

Changes went to both fromString and fromStream functions.

  • Added a osEolRegExp variable, which will store a RegExp for OS EOL.
  • I've added extra parameter, options. Options allows us to check desired EOL markers.
  • Logic, which will handle a case, when options.eol was explicitly specified:
    • if expected EOL is the same as current OS, we don't need to do any extra steps.
    • if OS EOL differs from expected, we need to replace all the OS specific markers.

test.js modifications:

  • I've added options.eol = "\n" in each TC, since this is the case that we want to work with.
  • I've created extra TC to make sure that fix is working.

Extra thoughts

I didn't test this solution on Mac, so it might be a good idea to check it there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant