mdless icon indicating copy to clipboard operation
mdless copied to clipboard

headers broken after newline and EOF

Open NCarson opened this issue 5 years ago • 1 comments

Given two commands, the first ending in newline and the second with more text; only the the second will print a header.

$ echo '#h1
' | ./mdless -P ; echo '#h1
hello' | ./mdless -P

gives (extra blank lines removed):

#h1 

h1 ======================================================================================================================
hello

I do not know if this intentional but in my mind markdown tags stand alone without context. And Github seems to agree with me (see very last line showing same idea).

In any case when this line https://github.com/ttscoff/mdless/blob/develop/lib/mdless/converter.rb#L190:

headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?\s*|(\S.+)\n([=-]+))$/i)

is changed to:

headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?[ \t]*|(\S.+)\n([=-]+))$/i)

(last \s changed to [ ^t]) fixes my test case.

Although I dont know if that causes any other repercussions.

Github rendering of # test\nEOF:

test

NCarson avatar Feb 05 '20 20:02 NCarson

I'm honestly not sure why this fix works, but you're correct that it produces the expected behavior. Can you make a pull request?

-Brett

On 5 Feb 2020, at 14:45, NCarson wrote:

Given two commands, the first ending in newline and the second with more text; only the the second will print a header.

$ echo '#h1
' | ./mdless -P ; echo '#h1
hello' | ./mdless -P

gives (extra blank lines removed):

#h1

h1 
======================================================================================================================
hello

I do not know if this intentional but in my mind markdown tags stand alone without context. And Github seems to agree with me (see very last line showing same idea).

In any case when this line https://github.com/ttscoff/mdless/blob/develop/lib/mdless/converter.rb#L190:

headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: 
#+)?\s*|(\S.+)\n([=-]+))$/i)

is changed to:

headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?[ 
\t]*|(\S.+)\n([=-]+))$/i)

(last \s changed to [ ^t]) fixes my test case.

Although I dont know if that causes any other repercussions.

Github rendering of # test\nEOF:

test

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/ttscoff/mdless/issues/45

ttscoff avatar Feb 06 '20 12:02 ttscoff