最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Showing C# <summary> tags in Jekyll Github pages using Highlight.js - Stack Overflow

programmeradmin2浏览0评论

To show codes successfully with simple HTML, I have added Highlight.js in my Jekyll based blog which is running on Github pages

<!--Add Highlight.js / -->
<link rel="stylesheet" href="//cdnjs.cloudflare/ajax/libs/highlight.js/9.0.0/styles/default.min.css">
<script src="//cdnjs.cloudflare/ajax/libs/highlight.js/9.0.0/highlight.min.js"></script>

<!-- Using Highight.js ;
<script>
  hljs.initHighlightingOnLoad();
</script>

To show codes successfully with simple HTML, I have added Highlight.js in my Jekyll based blog which is running on Github pages

<!--Add Highlight.js https://highlightjs/download/ -->
<link rel="stylesheet" href="//cdnjs.cloudflare./ajax/libs/highlight.js/9.0.0/styles/default.min.css">
<script src="//cdnjs.cloudflare./ajax/libs/highlight.js/9.0.0/highlight.min.js"></script>

<!-- Using Highight.js https://highlightjs/usage/-->
<script>
  hljs.initHighlightingOnLoad();
</script>

I need to show the below C# code i.e. everything between <pre> <code class="csharp"> and </code> </pre>:

<pre>
<code class="csharp">

/// <summary>
/// Main class of the project
/// </summary>
class Program
{
    /// <summary>
    /// Main entry point of the program
    /// </summary>
    /// <param name="args">Command line args</param>
    static void Main(string[] args)
    {
        //Do stuff
    }
}

</code>
</pre>
     

This code is added in this .md file which is displayed here.

Everything is getting rendered, except <summary> tags. Is the Highlighter misunderstanding it as normal HTML?

Question:

How do a developer make sure that everything between <pre> <code class="csharp"> and </code> </pre> including that <summary> tag is displayed using Highlight.js in such scenarios?

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Dec 30, 2015 at 15:37 Mr.XMr.X 31.4k27 gold badges147 silver badges229 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Jekyll has highlight tag and css (_sass/_syntax-highlighting.scss) onboard.

{% highlight csharp %}
/// <summary>
/// Main class of the project
/// </summary>
class Program
{
    /// <summary>
    /// Main entry point of the program
    /// </summary>
    /// <param name="args">Command line args</param>
    static void Main(string[] args)
    {
        //Do stuff
    }
}
{% endhighlight %}

This works out of the box with no need to client side overload. All Pygment lexers available are here.

The code HTML Tag uses Phrasing Content which means it will treat regular HTML Tags such as <summary> as regular HTML Code and therefore omits the output.

To avoid this problem you'd have to properly encode all tags:

<pre>
<code class="csharp">

    /// &lt;summary&gt;
    /// Summary description for the function or property goes here
    /// &lt;/summary&gt;

</code>
</pre>
发布评论

评论列表(0)

  1. 暂无评论