chrisweb/rehype-github-alerts

remarkBreaks

calumk opened this issue ยท 13 comments

calumk commented

Thanks for this repo!

It Might be worth updating the readme to specify /why/ you need remarkBreaks.... because otherwise it wont work unless you put two spaces.

I Spent some time (10 mins) trying to debug this, downloading and testing the example repo, assuming the parser wasnt working properly before I went back and understood exactly why your test code has 2 spaces in it.

Thank you for your feedback :)

hmmmm I have this section in the readme: https://github.com/chrisweb/rehype-github-alerts?tab=readme-ov-file#about-soft-line-breaks-support

I'm not sure how I can make it better, did you see that section and it still wasn't clear?

If it is a visibility thing I could move it up, or maybe link to that section from within a section that is more at top, like adding a tip just below the installation guide

If it is more a wording thing, so if it would be good to clarify the matter better, then maybe I can try to think of a more "useful" explanation, but I'm not really sure how, do you have a suggestion how I could explain this better?

Regarding line breaks, just a side note about something I noticed a few days ago:

I'm currently using the github alerts extensivly in a project and I came accross a problem where I wanted to add multiple paragraphs of text to an alert, but the result was not what I expected, (I have a bit of trouble finding the right words to explain this right now), but what I try to say is that the text was too "compact", I expected it have "more breathing space". Even though there are 2 spaces at the end of paragraph one it still only produces a line break:

> [!TIP]  
> very long sentence / paragraph one  
> very long sentence / paragraph two  

gets rendered like this:

Tip

very long sentence / paragraph one
very long sentence / paragraph two

So I actually installed remark breaks, to see what impact it would have on double spaces inside of a blockquote / alert, but it did not make any difference, with or without it the text was still just one big chunk.

If I write text outside of a blockquote, every double space at the end of a line of text will result in the next line to be in a seperate paragraph element when transformed to html, this is not the case inside of blockquotes

I have added this to my todo list as I need to investigate the causes and also verify what the results are on github and then I need to think of how to solve it

So if you want a space between the two paragraphs then you need to format the alert like this (no remark breaks installed):

> [!TIP]
> very long sentence / paragraph one
>
> very long sentence / paragraph two

gets rendered like this:

Tip

very long sentence / paragraph one

very long sentence / paragraph two

I also faced the same issue.
Had to install line break plugin and it added BR everywhere then again had to change the styling to make br display none;

Yeah the line break plugin in great in some situations to turn soft breaks into hard breaks, but it does not help for text inside of blockquotes / alerts

The only solution with this plugin is to add a "empty line" like so:

> [!TIP]
> very long sentence / paragraph one
>
> very long sentence / paragraph two

which then renders like this:

Tip

very long sentence / paragraph one

very long sentence / paragraph two

this is how github does it and the result when using the plugin is the same

@chrisweb in my case the below example didn't work without the line break plugin

> [!TIP]
> very long sentence / paragraph one
> very long sentence / paragraph two

Yes I understand what you mean... It only works without the remark-breaks if you add 2 spaces after each line, including the first line> [!TIP]

I realize that the confusion comes from the fact that on GitHub you don't need to add two spaces, however if you use rehype-github-alerts you need the two spaces, this is because github by default turns soft line breaks into hard line breaks, which is something the remark-breaks plugin does, but now everyone uses (installs) it

Hmmm, I will try to improve the Readme of this plugin tomorrow to make it more clear that 2 spaces are required or that the alternative is to install remark-breaks

@calumk @ShivamJoker I have published a new beta https://www.npmjs.com/package/rehype-github-alerts/v/3.0.0-beta.1 that should improve the DX of this package, it can be installed using the beta tag:

npm i rehype-github-alerts@beta

This new version will read the alert title and ignore if it ends with a hard line break or not, meaning you don't need to add double spaces after the [!NOTE] alert type anymore for it to work (and also don't need the optional remark-breaks package)

I released a beta for now, so that the new behavior can be tested and to verify that this does not introduce new bug(s), I will wait a few days and if after that there are no bug reports I will publish the new version

please let me know if this version works better for you ๐Ÿคž

calumk commented

I am no longer actively using this plugin, as I switched away from remark for unrelated reasons, but it seems like a good idea to update as you have

Thanks for continuing to work on this

@chrisweb If I add two spaces after ![NOTE] it works but without it, it only shows only one paragraph with newline above paragraph.

> [!WARNING]
> For now, LLRT is an **experimental** package.
> It is subject to change and intended only for testing purposes.

Is there something we can do in the library to make it work without putting two empty spaces?
image

@ShivamJoker thank you for testing the beta.1, there was indeed a bug when the line after the type does not only contain text, I fixed it and released a new 3.0.0-beta.2

HI @chrisweb it works now.
Thanks a ton.

There is can be one more improve of not adding newline in the beginning of the paragraph.

<div class="markdown-alert markdown-alert-tip">
<p class="markdown-alert-title"><svg/>Tip</p><p> <-- This paragraph should be with text below
If you want to change your Lambda file and function name you can update it in the handler.</p>
</div>

@ShivamJoker I'm glad it works now ๐Ÿ™‚ and thank you again for taking the time to test it

Ah yes I see what you mean, good catch, indeed I could probably fix the placement of the first paragraph element, I will look into this

EDIT: done ... 3.0.0-beta.3 is published, this should fix the line break, now I wait a few more days and then if nothing new comes up I will release it as stable

v3 is out https://www.npmjs.com/package/rehype-github-alerts/v/3.0.0

I'm closing this, but if you still have problems or similar problems, then please open a new ticket

Thanks @chrisweb