FANDOM


How do I get that sexy code highlighting we all know and love?Edit

What you do to enable code highlighting is go to the upper right of the editing pane, looking for the Source tab (the editor defaults to Visual). 

Go to the Source tab, and enclose your code in these tags:

<syntaxhighlight lang="YOUR_LANGUAGE">
        
        
 </syntaxhighlight>

It seems to preserve whitespace without much of a fuss, so that's cool. Just remember to replace YOUR_LANGUAGE with the language you want to use.

You can find the full documentation of the extention that provides this code highlighting here, as well as a full list of supported languages. 

For our purposes, it does support HTML5, CSS, Ruby, JavaScript, and Rails. Also Python (for Sublime Text config) and Vimscript (for Vim config) if you're into that sort of thing.

You should get something like this if done correctly:

# my solution to the Roman numerals problem in the Chris Pine book
class Roman
  def initialize
    @roms = {'M' => 1000, 'D' => 500, 'C' => 100, 'L' => 50, 'X' => 10, 'V' => 5, 'I' => 1}
  end
 
  def to_roman(n)
    sub = []
    @roms.each_pair do |key, value|
      until n < value
        # sub << key has the odd function of being value-reductive, in that 1203 will yield 'M' based on the fact that 'M'
        # is less than 1000, likewise 57 will select 'L', because it is the largest number that is still less than 57.
        sub << key
        # takeaway the queried value, so as to not repeat anything unnecessarily
        n -= value
      end
    end
 
    # join array, sub out the edge cases
    sub.join.gsub('VIIII', 'IX').gsub('IIII', 'IV')
  end
 
  def to_arabic(n)
    tote = 0
    # sub the edge cases for more easily summable
    n.gsub!('IX', 'VIIII')
    n.gsub!('IV', 'IIII')
    # query the array for the current value, sum it with tote
    until n.length == 0
      tote += @roms[n.slice!(-1)]
    end
 
    tote
  end
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.