Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Automatically wrap code in Markdown code blocks #15

Open
MarkEwer opened this issue Dec 17, 2024 · 5 comments
Open

Suggestion: Automatically wrap code in Markdown code blocks #15

MarkEwer opened this issue Dec 17, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@MarkEwer
Copy link

MarkEwer commented Dec 17, 2024

Situation:

When generating .md files from unit tests that have helper methods or sections that we don't need to appear in the documentation, like the using statements, I have been using collapsed sections to "hide" those things from display unless the person needs to drill into them. But the switching from code blocks to markdown and back as I am adding documentation is a little tedious.

Suggestion:

Add a new comment tag called //md language:{language} that we can add near the top of the file. Having added this tag in the file, the processor can then automatically wrap all code lines in a Markdown code block using the named language. This would save the user from having to add //md ``` to every section of code in the document.

Example:

As an example, consider this unit test:

     //md language:CSharp
     /*md
     # Bootstrap Tests
     This C# class provides unit tests to verify the test framework.
     md*/
     //md{ Using Statements
     using System.Reflection;
     using System.Text.Json;

     namespace MyDomain.Tests;

     public class BootstrapTests
     {
     //md}
     /*md

     This test verifies that the testing framework is functional. 
     The only reason this test exists is just to prove that the 
     testing framework is successfully running the unit tests.

     md*/
       [Fact, Trait("JIRA", "EV-1201")]
       public void AssertTrue()
       {
         Assert.True(true);
       }
     }
     /*md

Then we would get this output:

     # Bootstrap Tests
     This C# class provides unit tests to verify the test framework.

     <details><summary><strong>Using Statements</strong></summary>
     ```csharp
     using System.Reflection;
     using System.Text.Json;
     namespace MyDomain.Tests;

     public class BootstrapTests
     {
     ```
     </details>

     This test verifies that the testing framework is functional. 
     The only reason this test exists is just to prove that the testing 
     framework is successfully running the unit tests.
     ```csharp 
       [Fact, Trait("JIRA", "EV-1201")]
       public void AssertTrue()
       {
         Assert.True(true);
       }
     }
     ```

As you can see from the example, the suggestion is for the parser to identify the sections of code that are not tagged as Markdown and automatically wrap them in a Markdown code block using the default language specified at the top of the file. This enhancement would save some typing and make the unit test source code a bit easier to read.

@dadhi
Copy link
Owner

dadhi commented Dec 17, 2024

@MarkEwer
Hi. Nice surprise seeing someone other than me commenting here :)

So, you are proposing to add automatic insertion of code fences?
I will think about that.

Btw, are you using CsToMd or planning?

@MarkEwer
Copy link
Author

Yes, I am suggesting automatic insertion of code fences if the default language comment is present in the file.

I am evaluating CsToMd for my team as an addition to our "living documentation" setup.

@dadhi dadhi self-assigned this Dec 18, 2024
@dadhi dadhi added the enhancement New feature or request label Dec 18, 2024
@dadhi dadhi added this to the v1.3.0 milestone Dec 18, 2024
@dadhi
Copy link
Owner

dadhi commented Jan 8, 2025

I need to think how to support both explicit and configured fences together. I don't want to redo all my existing docs for this.

@dadhi
Copy link
Owner

dadhi commented Jan 20, 2025

Ok, it seems too ambiguous to decide when to insert the code fence if there are already some code fences specified.
To avoid the confusion, I will introduce code:-- to stop the insertion of the fences. Example:

//md code:cs
var x = 3;
//md code:-- stop the cs fences
//md```js
const y = function() {};
//md```
//md code:cs back to cs

In principle, you may simplify the above code like this:

//md code:cs
var x = 3;
//md code:js
const y = function() {};
//md code:cs back to cs

You probably don't need to worry about the code:-- unless you are working with the existing documentation which uses the explicit code fences, and you don't want to migrate it yet.

@MarkEwer
Copy link
Author

MarkEwer commented Jan 26, 2025 via email

dadhi added a commit that referenced this issue Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants