Browse Source

Merge pull request #15 from gaearon/hotfix/csharp-mapping

Hotfix/csharp mapping
robert mcguinness 7 years ago
parent
commit
c616c99df3
2 changed files with 23 additions and 3 deletions
  1. 1 1
      index.js
  2. 22 2
      test.js

+ 1 - 1
index.js

@@ -10,7 +10,7 @@ var MAP_LANGUAGES = {
   'py': 'python',
   'js': 'javascript',
   'rb': 'ruby',
-  'csharp': 'cs',
+  'cs': 'csharp',
   'html': 'markup'
 };
 

+ 22 - 2
test.js

@@ -3,7 +3,7 @@ var test = require('tape');
 
 var pkg = require('./package.json');
 
-test('should highlight javascript code block', function (t) {
+test('highlight javascript code block', function (t) {
 
   t.plan(1);
 
@@ -16,7 +16,27 @@ test('should highlight javascript code block', function (t) {
     })
     .create()
     .then(function(result) {
-      var expected = '<pre class="language-"><code class="lang-js"><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>\n</code></pre>';
+      var expected = '<pre class="language-"><code class="lang-js"><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>';
+      t.equal(result[0].content, expected);
+    })
+    .done();
+
+});
+
+test('highlight csharp code using shortcut', function (t) {
+
+  t.plan(1);
+
+  tester.builder()
+    .withContent('```cs\nusing System; class Program {public static void Main(string[] args) {Console.WriteLine("Hello, world!"); } }\n```')
+    .withLocalPlugin(__dirname)
+    .withBookJson({
+      gitbook: pkg.engines.gitbook,
+      plugins: ['prism', '-highlight']
+    })
+    .create()
+    .then(function(result) {
+      var expected = '<pre class="language-"><code class="lang-cs"><span class="token keyword">using</span> System<span class="token punctuation">;</span> <span class="token keyword">class</span> <span class="token class-name">Program</span> <span class="token punctuation">{</span><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">Main</span><span class="token punctuation">(</span><span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span><span class="token string">&quot;Hello, world!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span></code></pre>';
       t.equal(result[0].content, expected);
     })
     .done();