GitHub - Markdown language in text file - Amount of Lines

122 views Asked by At

This is my first post on stackoverflow. I recently joined the data science course on Coursera. As a student on Coursera, I had to mark a few assignments which included a question on markdown. The assignment asked everyone to create a text file, which could be viewed in a repo on GitHub. The file had to be formatted as a secondary heading (##), which had the following content 'This is a markdown file'. On most people's files, the following was displayed '2 lines, 27 bytes'.

However on 2 assignments I saw the following: '1 line, n bytes' (n being various bytes). I understand that the bytes changed because not everyone had put 'This is a markdown file' - someone had omitted the 'a' etc. However why should the amount of lines change? I checked the raw data file and they all contained the same. I'm quite new to the field of data science (old school stats background), so if it is a simple answer, then apologies for asking.

1

There are 1 answers

0
Waylan On BEST ANSWER

This almost certainly has to do with line endings.

Most people have likely included a line ending at the end of the first line. Therefore the file contains a second blank line. A few users did not add a line ending (using the [enter] or [return] key). Therefore, their file contains one line.

Generally it is considered good form to include a line ending at the end of the last line of a plain text file. In fact, many text editors will automatically add one for you, which is probably why most of the files contain two lines. That said, any decent Markdown parser should be able to properly parse a Markdown file missing a line ending on the last line.

As for the difference in file size (when there are no typos), this is also likely due to line endings. On Windows (DOS), the system default is to use two (hidden) characters to represent a line ending (usually represented as \r\n). Whereas all other systems (Mac OS, Linux, Unix, etc) only use a single character (\n). Again, any decent Markdown parser should be able to handle either. But, each gives a different character count and therefore a different file size.