From bfc6e4e6b6171b601decfa00a8a729f843a1a758 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Mon, 25 Apr 2016 11:25:16 -0400
Subject: PLT-2619/PLT-2661 Removed line numbers from markdown code blocks
 (#2795)

* Changed .editorconfig to indent CSS files using spaces

* Removed line numbers from markdown code blocks and made them wrap when no language is specified
---
 webapp/utils/syntax_hightlighting.jsx | 67 ++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 28 deletions(-)

(limited to 'webapp/utils/syntax_hightlighting.jsx')

diff --git a/webapp/utils/syntax_hightlighting.jsx b/webapp/utils/syntax_hightlighting.jsx
index 981ce6b35..882afe67f 100644
--- a/webapp/utils/syntax_hightlighting.jsx
+++ b/webapp/utils/syntax_hightlighting.jsx
@@ -124,56 +124,67 @@ hlJS.registerLanguage('yaml', hljsYaml);
 const HighlightedLanguages = Constants.HighlightedLanguages;
 
 export function formatCode(lang, data, filename) {
-    var language = lang || '';
-    var parsed;
-    var header = '';
-
-    language = language.toLowerCase();
+    const language = lang.toLowerCase() || '';
+    let contents;
+    let header = '';
 
     if (HighlightedLanguages[language]) {
-        var name = HighlightedLanguages[language].name;
+        let name = HighlightedLanguages[language].name;
 
         if (filename) {
             const fname = decodeURIComponent(Utils.getFileName(filename));
             name = fname + ' - ' + name;
         }
 
-        header = '<span class="post-body--code__language">' + name + '</span>';
+        header = '<span class="post-code__language">' + name + '</span>';
 
         try {
-            parsed = hlJS.highlight(language, data).value;
+            contents = hlJS.highlight(language, data).value;
         } catch (e) {
-            parsed = TextFormatting.sanitizeHtml(data);
+            contents = TextFormatting.sanitizeHtml(data);
         }
     } else {
-        parsed = TextFormatting.sanitizeHtml(data);
+        contents = TextFormatting.sanitizeHtml(data);
+    }
+
+    let className = 'post-code';
+    if (!language) {
+        // wrap when no language is specified
+        className += ' post-code--wrap';
     }
 
-    const lines = data.match(/\r\n|\r|\n|$/g).length;
-    var strlines = '';
-    for (var i = 1; i <= lines; i++) {
-        if (strlines) {
-            strlines += '\n' + i;
-        } else {
-            strlines += i;
+    if (filename) {
+        // add line numbers when viewing a code file preview
+        const lines = data.match(/\r\n|\r|\n|$/g).length;
+        let strlines = '';
+        for (let i = 1; i <= lines; i++) {
+            if (strlines) {
+                strlines += '\n' + i;
+            } else {
+                strlines += i;
+            }
         }
+
+        contents = (
+            '<table>' +
+                '<tbody>' +
+                    '<tr>' +
+                        '<td class="post-code__lineno">' + strlines + '</td>' +
+                        '<td>' +
+                            contents +
+                        '</td>' +
+                    '</tr>' +
+                '</tbody>' +
+            '</table>'
+        );
     }
 
     return (
-        '<div class="post-body--code">' +
+        '<div class="' + className + '">' +
             header +
             '<pre>' +
                 '<code class="hljs">' +
-                    '<table>' +
-                        '<tbody>' +
-                            '<tr>' +
-                                '<td class="post-body--code__lineno">' + strlines + '</td>' +
-                                '<td>' +
-                                    parsed +
-                                '</td>' +
-                            '</tr>' +
-                        '</tbody>' +
-                    '</table>' +
+                    contents +
                 '</code>' +
             '</pre>' +
         '</div>'
-- 
cgit v1.2.3-1-g7c22

