azu / gitbook-plugin-include-codeblock

GitBook plugin for including file
Other
40 stars 25 forks source link

Included Rust sources don't get highlighted #8

Closed zsiciarz closed 8 years ago

zsiciarz commented 8 years ago

When importing a Rust source file, it gets incorrectly detected as text and therefore syntax highlighting doesn't work. I've dug around and it looks like the .rs extension is found earlier in the language map, under the RenderScript entry with the corresponding aceMode set as text. See an example in my fork here: https://github.com/zsiciarz/gitbook-plugin-include-codeblock/commit/41115eb30b5e0cf979f1409e51070bef80f8eb26, the test output is:

± % npm test                                                                                                                            !10116

> gitbook-plugin-include-codeblock@1.6.0 test /home/zbyszek/Development/gitbook-plugin-include-codeblock
> mocha

  parse
    ✓ should return object for replace
    ✓ should translate elixir extensions
    1) should translate Rust extensions
    sliced text
      ✓ should return sliced object for replace
      ✓ should return sliced `start`- text
      ✓ should return sliced -`end` text
    containIncludeLabel
      ✓ support import
      ✓ support include
      ✓ support command split by space
      ✓ support command split by ,

  9 passing (184ms)
  1 failing

  1) parse should translate Rust extensions:

      AssertionError:   # test/parser-test.js:43

  assert.equal(result.replaced, expected)
               |      |         |        
               |      |         "> <a name=\"test.rs\" href=\"fixtures/test.rs\">test.rs</a>\n\n``` rust\nextern crate num;\n```"
               |      "> <a name=\"test.rs\" href=\"fixtures/test.rs\">test.rs</a>\n\n``` text\nextern crate num;\n```"
               Object{target:"[include](fixtures/test.rs)",replaced:"> <a name=\"test.rs\" href=\"fixtures/test.rs\">test.rs</a>\n\n``` text\nextern crate num;\n```"}

      + expected - actual

       > <a name="test.rs" href="fixtures/test.rs">test.rs</a>

      -``` text
      +``` rust
       extern crate num;
  at Function.decoratedAssert [as equal] (node_modules/empower/lib/decorate.js:42:30)
  at Context.<anonymous> (test/parser-test.js:43:16)

npm ERR! Test failed. See above for more details


 I'm not entirely sure how to fix this, as RenderScript is a perfectly valid option for .rs files. This is probably happening as well with for example .h files being detected as C headers, even if they contain C++ or ObjC code. Perhaps we could use some sort of language hint directly in the directive? Something like:

include:1-4,rust

azu commented 8 years ago

@zsiciarz Thanks for report. I'll fix it :soon:

azu commented 8 years ago

I'v fixed this issue and publish 1.6.1.

Thanks.