MurhafSousli / ngx-highlightjs

Angular syntax highlighting module
https://ngx-highlight.netlify.app/
MIT License
279 stars 35 forks source link

Python instructions not getting syntax-highlight if inside same code block #27

Closed h4k1m0u closed 6 years ago

h4k1m0u commented 6 years ago

Bug Report or Feature Request (mark with an x)

- [ x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] question

OS and Version?

Archlinux

Versions

Angular CLI: 1.5.0
Node: 9.5.0
OS: linux x64
Angular: 5.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.0.2
@angular/cli: 1.5.0
@angular/flex-layout: 2.0.0-beta.12
@angular/material: 5.0.2
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.8.1

Repro steps

The following two python instructions won't get syntax-highlighed if they're in the same <pre><code>...</code></pre> block, but they're normally syntax-highlighted if we put each in a different code block:

k_means = cluster.KMeans(n_clusters=2)
l = k_means.fit(X)

This error can be reproduced on stackblitz.

MurhafSousli commented 6 years ago

@h4k1m0u As I see in the stackblitz, they are getting highlighted. This could be highlightjs python issue check this

h4k1m0u commented 6 years ago

I think I've identified from the code you just shared on stackblitz why it wasn't getting syntax highlighter (i.e. no spans created inside the code tag). It has to do with the alignment of the code:

This works:

<pre>
  <code class="language-python">
k_means = cluster.KMeans(n_clusters=2)
l = k_means.fit(X)
  </code>
</pre>

While this doesn't:

<pre>
  <code class="language-python">
  k_means = cluster.KMeans(n_clusters=2)
  l = k_means.fit(X)
  </code>
</pre>

Another point, though maybe in this case the problem is coming from highlightjs:

This won't work:

<pre>
    <code class="language-python">
k_means = cluster.KMeans(n_clusters=2)
k_means.fit(X)
    </code>
</pre>

But this does work (notice the assignment in the second instruction):

<pre>
    <code class="language-python">
k_means = cluster.KMeans(n_clusters=2)
_ = k_means.fit(X)
    </code>
</pre>