mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
Code block not adding new lines or pretty formatting #241
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @martinkearn on GitHub (Nov 13, 2018).
I have this markdown representing a C# code sample:
I'm using this code to convert it to HTML
It is producing HTML with no new lines in it as follows
<pre><code class="language-c#"> if (env.IsDevelopment()) { builder.AddUserSecrets<Startup>(false); }</code></pre>Is there an extension or some other solution to produce HTML code blocks that are nicely formatted?
@MihaZupan commented on GitHub (Nov 13, 2018):
Copy-pasting your sample generates html with correct new lines for me
@Kryptos-FR commented on GitHub (Nov 14, 2018):
How are your line endings in your C# code? Have a look at the
ConfigureNewLineextension.@martinkearn commented on GitHub (Nov 14, 2018):
@MihaZupan please try the contents of this file: https://raw.githubusercontent.com/martinkearn/Content/master/Blogs/Test.md which contains some simple Markdown with a code block to see if you can repro the problem there. I get this HTML from this file:
@Kryptos-FR My code now looks like this but makes no difference
You can see my full Azure Function code here: https://github.com/martinkearn/MartinK-Me/blob/GitHubCMS/Functions/Functions/ConvertToHtmlWithMetadata.cs
Thanks all
@Kryptos-FR commented on GitHub (Nov 14, 2018):
Looks like something is wrong on your end: all the line endings are removed. Are you sure you don't have some other post-processing?
Looking at https://babelmark.github.io/?text=%60%60%60c%23%0Aforeach+(var+thing+in+things)%0A%7B%0A++var+thisThing+%3D+thing%3B%0A%7D%0A%60%60%60 the result with markdig seems correct.
@martinkearn commented on GitHub (Nov 14, 2018):
OK, thanks, it could be how I'm getting the raw Markdown. I'll investigate and post back here when I've figured it out
@martinkearn commented on GitHub (Nov 14, 2018):
OK, I've resolved this now … it was nothing to do with MarkDig but the way I was getting my Markdown string (thanks @Kryptos-FR for the hint). The Markdown is on GitHub and I was getting the raw file using a GET request to https://raw.githubusercontent.com/martinkearn/Content/master/Blogs/Test.md. I'm now using the GitHub API to get the File object (GET request to https://api.github.com/repos/martinkearn/Content/contents/Blogs/Test.md) which includes a Base64 encoded version of its content. Once I've Base64Decoded that string and passed to MarkDig it all works fine. Thanks for the help. I hope this thread helps someone from the future.
@Kryptos-FR commented on GitHub (Nov 14, 2018):
@martinkearn welcome. Thanks for providing the explanation as other people might stumble upon the same issue.