Giter Club home page Giter Club logo

highlightjs-cshtml-razor's People

Contributors

gribovalexander avatar himura2la avatar joshgoebel avatar konstantinbelyakov avatar marcoscaceres avatar romanresh avatar tupikovvladimir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

highlightjs-cshtml-razor's Issues

Razor syntax not highlighting

I used the Static website or simple usage explained on the readme page.

<script type="text/javascript" src="/path/to/highlight.min.js"></script>
<script type="text/javascript" src="/path/to/highlightjs-cshtml-razor/dist/cshtml-razor.min.js"></script>
<script>
    hljs.highlightAll();
</script>

Then how can I use it on an HTML page?

I tried the following:

<pre><code class="language-cshtml"> cshtml here </code></pre>
didn't work, then tried

<pre><code class="language-cshtml-razor"> cshtml here </code></pre>
no luck.

Thanks

Nested Razor blocks breaks formatting

Hi there - first and foremost thanks for the grammar!

I am finding that nested blocks of Razor break the formatting. Specifically I am using the following to illustrate this:

<markdown>
    ```cshtml
    @@if (this)
    {
        <span>this</span>
        @@if (this)
        {
            <span>this</span>
        }
        else if (that)
        {
            <span>that</span>
        }
        else {
            <span>nope</span>
        }
    }
    else if (that)
    {
        <span>that</span>
        @@if (this)
        {
            <span>this</span>
        }
        else if (that)
        {
            <span>that</span>
        }
        else {
            <span>nope</span>
        }
    }
    else {
        <span>nope</span>
        @@if (this)
        {
            <span>this</span>
        }
        else if (that)
        {
            <span>that</span>
        }
        else {
            <span>nope</span>
        }
    }
    ```
</markdown>

This results in the following HTML:

<code class="language-cshtml hljs language-cshtml-razor"><span class="hljs-built_in">@</span><span class="language-csharp"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>)
</span><span class="hljs-built_in">{</span><span class="language-csharp">
    </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp"><span class="hljs-keyword">this</span></span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">@</span><span class="language-csharp"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>)
    </span><span class="hljs-built_in">{</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp"><span class="hljs-keyword">this</span></span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span><span class="language-csharp">
    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (that)
    {</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">that</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span><span class="language-csharp">
    <span class="hljs-keyword">else</span> </span><span class="hljs-built_in">{</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">nope</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span>
}
else if (that)
{
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>that<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
    <span class="hljs-built_in">@</span><span class="language-csharp"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>)
    </span><span class="hljs-built_in">{</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp"><span class="hljs-keyword">this</span></span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span><span class="language-csharp">
    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (that)
    {</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">that</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span><span class="language-csharp">
    <span class="hljs-keyword">else</span> </span><span class="hljs-built_in">{</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">nope</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span>
}
else {
    <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>nope<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
    <span class="hljs-built_in">@</span><span class="language-csharp"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>)
    </span><span class="hljs-built_in">{</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp"><span class="hljs-keyword">this</span></span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span><span class="language-csharp">
    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (that)
    {</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">that</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span><span class="language-csharp">
    <span class="hljs-keyword">else</span> </span><span class="hljs-built_in">{</span><span class="language-csharp">
        </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">nope</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
    </span><span class="hljs-built_in">}</span>
}
</code>

Specifically, note the instances of e.g. }, else if (that), {, and else { that have no surrounding HTML tags.

This ends up rendering (with the GitHub Dark theme) as such:

Screenshot 2023-02-08 at 14-34-12 IDMWORKS MVC Template - Access Control

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

highlight Blazor code

I've been attempting to use your library with snippets of Blazor code (Razor syntax) in Google's Blogger blog to no avail. I was under the impression that the syntax isn't different to any great extent. All that appears in the

 block are those tags that are preceded by an @ symbol.

Any suggestions on how to make this work?

hljs.COMMENT is not a function

I'm using

<link rel="stylesheet" href="/Resources/Shared/stylesheets/vs2015.css">
<script src="/Resources/Shared/scripts/highlight.pack.js"></script>
<script type="text/javascript" src="/Resources/Shared/scripts/cshtml.js"></script>
<script>
  hljs.registerLanguage('cshtml', window.hljsDefineRazorCshtml);
  hljs.initHighlightingOnLoad();
</script>

and getting this error

Uncaught TypeError: hljs.COMMENT is not a function
    at hljsDefineRazorCshtml (cshtml.js:373)
    at Object.N [as registerLanguage] (highlight.pack.js:2)
    at adding-a-site:13

I'm using hljs v9.14.1 and the current cshtml.js

How to specify language?

I want to use highlightjs to process my code which not in <code class='language'>.But it at <div class='language'>,How to specify language in function highlightBlock().

Contribute to the thought process for 3rd party language packaging if you'd like

Contribute to the thought process for 3rd party language packaging if you'd like

As a maintainer of a Highlight.js language grammar you might be interested in the discussion of an official packaging format. I just created an issue to track the discussion and I've been working on this along with the new build system.

highlightjs/highlight.js#2328

Sorry for the spam, but I couldn't think of an easier way to ping the people who might be most interested in weighing in on the subject. Feel free to simply close this issue or leave it open (whatever works best for you!).

Please include `dist` folder with CDN distributable

This issue is being opened as part of our iniative to make all 3rd party grammars:

  • easier to use for all end users
  • internally a bit more consistent (both to help end users and also encourage cross-maintenance)
  • ready to go for version 11

Please include a dist folder that includes a ready-to-go CDN distributable that can be used with a single line of JS. IE, our simple 3 install should "just work" without any other code or markup:

<script type="text/javascript" src="/path/to/highlight.min.js"></script>
<script type="text/javascript" src="/path/to/highlightjs-cshtml-razor/cshtml-razor.js"></script>
<script type="text/javascript">hljs.highlightAll();</script>

Your README optimally would also document this usage. Please see the robots-txt repository for a usage example.

Our build system can generate this file for you (and we recommend that). Using our internal build system also allows you to easily check your grammar for exponential or polynomical run-away regular expressions.

If you have any questions, feel free to ask!

Thanks,
Highlight.js Maintainer

C# keywords highlighted in HTML nested in Razor blocks

Again, thanks very much for the grammar!

It seems like C# keywords are being highlighted when they are found in HTML that is nested inside of Razor blocks.

For instance, the following source:

<markdown>
    ```cshtml
    @@if (this)
    {
        <span>Lorem is ipsum as dolor not sit this amet, for consectetur in adipiscing while elit.</span>
    }
    ```
</markdown>

Results in the following HTML:

<code class="language-cshtml hljs language-cshtml-razor"><span class="hljs-built_in">@</span><span class="language-csharp"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>)
</span><span class="hljs-built_in">{</span><span class="language-csharp">
    </span><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">Lorem <span class="hljs-keyword">is</span> ipsum <span class="hljs-keyword">as</span> dolor <span class="hljs-keyword">not</span> sit <span class="hljs-keyword">this</span> amet, <span class="hljs-keyword">for</span> consectetur <span class="hljs-keyword">in</span> adipiscing <span class="hljs-keyword">while</span> elit.</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="language-csharp">
</span><span class="hljs-built_in">}</span>
</code>

This ends up looking like the following (with the GitHub Dark theme):

Screen Shot 2023-02-08 at 2 43 42 PM

TypeScript Typings

Would you be open to a PR that adds an index.d.ts typings file to this library? I'm guessing it's not a super common use case but could come in handy sometimes.

C# highlighting in Blazor/Razor @code blocks not working

It looks as if the highlighting is broken in Blazor/Razor files, where C# code inside @code blocks are not correctly highlighted.

For example, this .razor file:

<Fixture Test="InitialHtmlIsCorrect">
  <ComponentUnderTest>
    <Heading />
  </ComponentUnderTest>
  <Fragment>
    <h3 id:regex="heading-\d{4}" required>
      Heading text
      <small diff:ignore></small>
    </h3>    
  </Fragment>

  @code 
  {
    void InitialHtmlIsCorrect(Fixture fixture)
    {
      // Arrange - Gets the Heading component
      var cut = fixture.GetComponentUnderTest<Heading>();

      // Assert      
      // Here we get expected HTML from the Fragment element above.
      var expectedHtml = fixture.GetFragment();

      // Here we use the HTML diffing library to assert that the rendered HTML
      // from CUT is semantically the same as the expected HTML string above.
      cut.MarkupMatches(expectedHtml);
    }
  }
</Fixture>

Becomes this HTML with highlightjs-cshtml-razor:

<code class="lang-razor hljs cshtml-razor" name="SemanticHtmlTest.razor"><span class="hljs-tag">&lt;<span class="hljs-name">Fixture</span> <span class="hljs-attr">Test</span>=<span class="hljs-string">"InitialHtmlIsCorrect"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ComponentUnderTest</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Heading</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ComponentUnderTest</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Fragment</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">id:regex</span>=<span class="hljs-string">"heading-\d{4}"</span> <span class="hljs-attr">required</span>&gt;</span>
      Heading text
      <span class="hljs-tag">&lt;<span class="hljs-name">small</span> <span class="hljs-attr">diff:ignore</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">small</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>    
  <span class="hljs-tag">&lt;/<span class="hljs-name">Fragment</span>&gt;</span>

  <span class="hljs-built_in">@</span><span class="csharp">code</span> 
  {
    void InitialHtmlIsCorrect(Fixture fixture)
    {
      // Arrange - Gets the Heading component
      var cut = fixture.GetComponentUnderTest<span class="hljs-tag">&lt;<span class="hljs-name">Heading</span>&gt;</span>();

      // Assert      
      // Here we get expected HTML from the Fragment element above.
      var expectedHtml = fixture.GetFragment();

      // Here we use the HTML diffing library to assert that the rendered HTML
      // from CUT is semantically the same as the expected HTML string above.
      cut.MarkupMatches(expectedHtml);
    }
  }
<span class="hljs-tag">&lt;/<span class="hljs-name">Fixture</span>&gt;</span>
</code>

And looks like this with the default highlight style:

image

Versions:

  • Highlight.js 10.1.1 (93fd0d73)
  • cshtml-razor (master branch from today) (b047bc1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.