реклама на сайте
подробности

 
 
 
Reply to this topicStart new topic
> Раскраска кода
andyp
сообщение Mar 1 2016, 11:52
Сообщение #1


Местный
***

Группа: Участник
Сообщений: 453
Регистрация: 23-07-08
Пользователь №: 39 163



Нельзя ли прикрутить раскраску кода для matlab/c++/c ?
Go to the top of the page
 
+Quote Post
megajohn
сообщение Mar 1 2016, 14:42
Сообщение #2


Профессионал
*****

Группа: Свой
Сообщений: 1 080
Регистрация: 16-11-04
Из: СПб
Пользователь №: 1 143



до сих пор *.cpp *.c нельзя прикреплять, так что до раскраски еще огого


--------------------
Марс - единственная планета, полностью населенная роботами (около 7 штук).
Go to the top of the page
 
+Quote Post
andyp
сообщение May 23 2016, 14:51
Сообщение #3


Местный
***

Группа: Участник
Сообщений: 453
Регистрация: 23-07-08
Пользователь №: 39 163



Локально прикрутил раскраску с помощью greasemonkey, google prettifier и следующего скрипта
Код
// ==UserScript==
// @name        Elecronix code prettifier
// @match *://electronix.ru/forum/*
// @version     1
// @grant       none
// ==/UserScript==

// google prettify highlighting script
var HLJS = "//cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=matlab&skin=sunburst";

(function() {
  'use strict';

  // Don't run inside iframes (Looking at you GreaseMonkey + TinyMCE)
  if (window.top !== window.self) return;

  // Runs a function in the document. Basically like a Content Script.
  // http://wiki.greasespot.net/Content_Script_Injection
  function contentEval(source) {

    // Check for function input.
    if ('function' == typeof source) {
      // Execute this function with no arguments, by adding parentheses.
      // One set around the function, required for valid syntax, and a
      // second empty set calls the surrounded function.
      source = '(' + source + ')();'
    }

    // Create a script node holding this  source code.
    var script = document.createElement('script');
    script.setAttribute("type", "application/javascript");
    script.textContent = source;

    // Insert the script node into the page, so it will run, and immediately
    // remove it to clean up.
    document.body.appendChild(script);
    //document.body.removeChild(script);
  }


  // Given a src attribute, makes a <script> tag into the end of <body>
  function contentScript(source) {
    var tag = document.createElement('script');
    tag.setAttribute('type', 'application/javascript');
    tag.src = source;

    document.body.appendChild(tag);
    //document.body.removeChild(tag);
    return tag;
  }

  var ds = document.getElementsByClassName('codemain');

  while(ds.length)    
  {
     var old_elem = ds[0];
     var new_elem = document.createElement('pre');
     new_elem.innerHTML = old_elem.innerHTML;    
     new_elem.className = 'prettyprint';
     old_elem.parentNode.replaceChild(new_elem, old_elem);    
  }
  
  var hl = contentScript(HLJS);

})();


Выглядит как-то так:



Матлаб иногда глючит:



как переключать скины написано тут:
https://github.com/google/code-prettify/blo...ting_started.md

Если есть спецы по js, то буду рад любым замечаниям по улучшению.
Go to the top of the page
 
+Quote Post
СНБ
сообщение May 23 2016, 15:25
Сообщение #4


Участник
*

Группа: Участник
Сообщений: 73
Регистрация: 2-05-16
Пользователь №: 91 564



Цитата(andyp @ Mar 1 2016, 12:52) *
Нельзя ли прикрутить раскраску кода для matlab/c++/c ?

В смысле "раскраску"?
Синтаксическую подсветку что ли?
Go to the top of the page
 
+Quote Post
andyp
сообщение May 23 2016, 15:45
Сообщение #5


Местный
***

Группа: Участник
Сообщений: 453
Регистрация: 23-07-08
Пользователь №: 39 163



Цитата(СНБ @ May 23 2016, 18:25) *
В смысле "раскраску"?
Синтаксическую подсветку что ли?


Ну да.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 17th June 2025 - 21:09
Рейтинг@Mail.ru


Страница сгенерированна за 0.01385 секунд с 7
ELECTRONIX ©2004-2016