nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

Add eol --newline option for text content in nbconvert.writers.files

Open thisiswhereitype opened this issue 1 year ago • 6 comments

closes #1062

Now users can specify the newline string to be passed to open for string data. This PR concerns writing.

This is fiddly requiring --newline $'\r\n' on Bash to force windows newline.

However --use-<crlf|lf>-newline make this easier.

The default, None, is to fall back onto os.linesep as currently used.

I didn't look closely at tests but wanted to see what the CI makes of this.

thisiswhereitype avatar May 03 '24 13:05 thisiswhereitype

This is a great feature.

However, as your example shows, it might require complex shell escaping (windows is truly trash at that).

Perhaps in addition to the explicit alias which accepts any-old-thing, add two flags:

    --unix-line-endings
        Write text files with UNIX LF line endings:      \n
    --windows-line-endings  
        Write text files with Windows CRLF line endings: \r\n

bollwyvl avatar May 03 '24 13:05 bollwyvl

In addition to reading, being able to force writing with a newline variant would be fantastic.

bollwyvl avatar May 03 '24 14:05 bollwyvl

In addition to reading, being able to force writing with a newline variant would be fantastic.

Thanks for the feedback - open as linked above handles reading and writing depending on the file pointer mode arg. The docs provide a bullet point for the treatment under r/w. This arugment is illegal in mode='b' (binary).

The --newline is only passed to the output via the Writer class so as of writing this PR only affects writing.

Reading text is universal mode where all line endings are normalised to \n by default. This line appears to be reading is done.

We might expose an input flag so users can work with systems which have alternative EOL characters which aren't by default normalised, but I don't see that requested anywhere.

NB: some comments in the issue thread point out the current behaviour "use-system eol" differs from the ecosystem.

The default behaviours need deprecating in favour of use LF to satisfy the discussion, this has been adopted by VScode Jupyter .

thisiswhereitype avatar May 04 '24 20:05 thisiswhereitype

The interface is not using repr as the docs are rendering newlines:

--use-crlf-newline
    Implies CLRF newline.
    Equivalent to: [--NbConvertApp.newline=
    ]
--use-lf-newline
    Implies LF newline.
    Equivalent to: [--NbConvertApp.newline=
    ]

thisiswhereitype avatar May 12 '24 14:05 thisiswhereitype

Reset bad author on commits

thisiswhereitype avatar May 15 '24 19:05 thisiswhereitype