Search code examples
markdown

Markdown code block with user-input bolded


We are using Markdown for all our labs and study modules and everything works great. We are using Typora for all the editing since it provides (non-technical) users with a quick way to view their output in human-readable format, i.e., WYSIWYG. However, management has expressed their desire for some customization of the Markdown files so it more accurately reflects the code. In other words, they want user-input to be bolded in the fenced code. Also, they wanted a ToC that when converted to PDF format would be clickable.

In response to this, I started using Eisvogel. It does pretty much everything needed except for bolded code font. I was able to get some basic bolding by using the formula:

lab@desktop:~$ ssh lab@172.25.11.3
lab@172.25.11.3's password:
[lab@centos1 ~]$

bolded text in code

However, they still would like a colored background, though this is not required.

Ideally, they would like some thing O'Reilly-esque, like the following:

O'Reilly bolded code and then Courier regular

I have also included some LaTeX code at the beginning of the first Lab file, which does provide a lot of functionality. And, I have added additional text to the Eisvogel document so I can have multi-colored text boxes.

Any suggestions for bolding code font?

I have read through all the posts here, and I recognize Markdown takes code and will not do anything else with it. However, I have done something similar using LaTeX, but aside from moving everyone to LaTeX (which would not go over well with the ndev folks), was wondering if there was a way to incorporate the TeX code into Markdown like I have done with the test labs.

This is my build.sh file:

pandoc  --toc \
    --toc-depth 2 \
        "T1.md" \
        -s -o "Test_v23.pdf" \
        --from markdown \
        --filter=pandoc-latex-environment \
        --template "eisvogel.tex" \
        --listings

I attempted to add the contents of my T1.md file and the custom items from my eisvogel.tex file, but it looked like Spam, which given the length of this post, probably now is...

Thanks in advance.


Solution

  • I was able to get this to work using the following conventions. Within my Markdown code I added the following lines:

    ::: code
    \begin{Verbatim}[commandchars=\\\{\},fontsize=\small,breaklines=true]
    test@rtr> \textbf{telnet 172.16.10.1 port 21}
    \end{Verbatim}
    :::
    

    I embedded all my code within a ::: code at the beginning and ::: and the end. I also used the LaTeX command \begin{Verbatim}[commandchars=\\\{\},fontsize=\small,breaklines=true] to force the selected code to be in Verbatim format.

    The line starting with test@rtr> is the prompt and then to make the command appear in bolded font, I used the LaTeX command \textbf{} while enclosing the command within the curly brackets.

    However, as I am using the Eisbogel template to generate the output, it also needed to have some code added to it so it would know what to do with this selection.

    I added the following two lines to my eisvogel.tex file:

    \usepackage{fvextra}
    \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,fontsize=$if(code-block-font-size)$$code-block-font-size$$else$\small$endif$,commandchars=\\\{\}}
    

    I believe that is all I did. It has been a few months since I got this working, but I wanted to share with others. If you have any questions, contact me. Happy to share my modified template.