Merge pull request #772 from warpc/762-ui_and_refactoring

[refs #762] ui and refactoring for mass build; fix syntax highlight
This commit is contained in:
Vladimir Sharshov 2012-12-11 14:19:56 -08:00
commit 59c1d75a36
51 changed files with 382 additions and 237 deletions

View File

@ -0,0 +1,29 @@
$(document).ready(function() {
var projects_list = $('.form.mass_build #projects_list');
var repositories = $(".form.mass_build input:checkbox");
repositories.click(function(){
if (this.checked){
$(this).attr('disabled',true);
$.ajax({
type: 'GET',
url: $(this).attr('href'),
success: function(data){
var text = projects_list.val();
if(text.length > 0 && text.slice(-1) != '\n') {text = text + "\n"}
projects_list.val(text+data);
},
error: function(data){
alert('Error :(') // TODO remove
}
});
}
return true;
});
projects_list.keyup(function(){
if($(this).val().length == 0) {
repositories.attr('disabled',false)
.attr('checked', false);
}
});
});

View File

@ -1101,12 +1101,21 @@ div#advisory_search_block div.continue_input {
margin-bottom: 20px; margin-bottom: 20px;
} }
form.mass_build section.left { form.mass_build {
margin-left: 50px; section.left {
} margin-left: 10px;
width: 350px;
}
form.mass_build section.right { section.right {
margin-right: 50px; margin-right: 50px;
}
input[type="submit"] {
margin: 10px 0 10px 0;
}
#projects_list {
min-width:315px;
}
} }
.toggle { .toggle {

View File

@ -10,8 +10,7 @@ class Platforms::MassBuildsController < Platforms::BaseController
skip_authorize_resource :platform, :only => [:create, :index] skip_authorize_resource :platform, :only => [:create, :index]
def create def create
mass_build = @platform.mass_builds.new(:repositories => params[:repositories], mass_build = @platform.mass_builds.new(:arches => params[:arches],
:arches => params[:arches],
:auto_publish => params[:auto_publish] || false, :auto_publish => params[:auto_publish] || false,
:projects_list => params[:projects_list]) :projects_list => params[:projects_list])
mass_build.user = current_user mass_build.user = current_user

View File

@ -97,6 +97,7 @@ class Platforms::RepositoriesController < Platforms::BaseController
end end
def projects_list def projects_list
render(:text => @repository.projects.map(&:name).join("\n")) && return if params[:text] == 'true'
owner_subquery = " owner_subquery = "
INNER JOIN ( INNER JOIN (

View File

@ -6,11 +6,10 @@ class MassBuild < ActiveRecord::Base
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
scope :outdated, where('created_at < ?', Time.now + 1.day - BuildList::MAX_LIVE_TIME) scope :outdated, where('created_at < ?', Time.now + 1.day - BuildList::MAX_LIVE_TIME)
attr_accessor :repositories, :arches attr_accessor :arches
attr_accessible :repositories, :arches, :auto_publish, :projects_list attr_accessible :arches, :auto_publish, :projects_list
validates :platform_id, :arch_names, :name, :user_id, :presence => true validates :platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true
validate :rep_names, :repositories, :presence => true, :if => Proc.new {|mb| mb.projects_list.blank?}
validates_inclusion_of :auto_publish, :in => [true, false] validates_inclusion_of :auto_publish, :in => [true, false]
after_create :build_all after_create :build_all
@ -25,26 +24,33 @@ class MassBuild < ActiveRecord::Base
:build_error :build_error
] ]
# ATTENTION: repositories and arches must be set before calling this method!
def build_all def build_all
# later with resque # later with resque
if projects_list.present? arches_list = arches ? Arch.where(:id => arches) : Arch.all
platform.build_from_list( auto_publish ||= false
:mass_build_id => self.id,
:user => self.user, projects_list.lines.each do |name|
:arches => self.arches, next if name.blank?
:auto_publish => self.auto_publish name.chomp!; name.strip!
)
else if project = Project.joins(:repositories).where('repositories.id in (?)', platform.repository_ids).find_by_name(name)
platform.build_all( begin
:mass_build_id => self.id, return if self.reload.stop_build
:user => self.user, arches_list.each do |arch|
:repositories => self.repositories, rep = (project.repositories & platform.repositories).first
:arches => self.arches, project.build_for(platform, rep.id, user, arch, auto_publish, self.id)
:auto_publish => self.auto_publish end
) rescue RuntimeError, Exception
end
else
MassBuild.increment_counter :missed_projects_count, id
list = (missed_projects_list || '') << "#{name}\n"
update_column :missed_projects_list, list
end
sleep 1
end end
end end
later :build_all, :loner => true, :queue => :clone_build
def generate_failed_builds_list def generate_failed_builds_list
report = "" report = ""
@ -67,10 +73,8 @@ class MassBuild < ActiveRecord::Base
def set_data def set_data
if new_record? if new_record?
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}" self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
end end
end end
end end

View File

@ -178,66 +178,6 @@ class Platform < ActiveRecord::Base
end end
end end
def build_all(opts={})
# Set options to build all need
repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
auto_publish = opts[:auto_publish] || false
user = opts[:user]
mass_build_id = opts[:mass_build_id]
mass_build = MassBuild.find mass_build_id
repositories.each do |rep|
rep.projects.find_in_batches(:batch_size => 2) do |group|
sleep 1
group.each do |p|
arches.map(&:name).each do |arch|
begin
return if mass_build.reload.stop_build
p.build_for(self, rep.id, user, arch, auto_publish, mass_build_id)
rescue RuntimeError, Exception
# p.async(:build_for, self, user, arch, auto_publish, mass_build_id) # TODO need this?
end
end
end
end
end
end
later :build_all, :loner => true, :queue => :clone_build
def build_from_list(opts={})
mass_build = MassBuild.find opts[:mass_build_id]
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
auto_publish = opts[:auto_publish] || false
user = opts[:user]
mass_build.projects_list.lines.each do |name|
name.chomp!; name.strip!
project = ""
Project.where(:name => name).each do |pr|
project = pr if (pr.repository_ids & self.repository_ids).present?
end
if project
begin
return if mass_build.reload.stop_build
arches.map(&:name).each do |arch|
rep = (project.repositories & self.repositories).first
project.build_for(self, rep.id, user, arch, auto_publish, mass_build.id)
end
rescue RuntimeError, Exception
end
else
MassBuild.increment_counter :missed_projects_count, mass_build.id
list = (mass_build.missed_projects_list || '') << "#{name}\n"
mass_build.update_column :missed_projects_list, list
end
sleep 1
end
end
later :build_from_list, :loner => true, :queue => :clone_build
def destroy def destroy
with_skip {super} # avoid cascade XML RPC requests with_skip {super} # avoid cascade XML RPC requests
end end

View File

@ -124,14 +124,13 @@ class Project < ActiveRecord::Base
#path #share by NFS #path #share by NFS
end end
def build_for(platform, repository_id, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0) def build_for(platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build_id = nil, priority = 0)
# Select main and project platform repository(contrib, non-free and etc) # Select main and project platform repository(contrib, non-free and etc)
# If main does not exist, will connect only project platform repository # If main does not exist, will connect only project platform repository
# If project platform repository is main, only main will be connect # If project platform repository is main, only main will be connect
main_rep_id = platform.repositories.find_by_name('main').try(:id) main_rep_id = platform.repositories.find_by_name('main').try(:id)
build_reps_ids = [main_rep_id, repository_id].compact.uniq build_reps_ids = [main_rep_id, repository_id].compact.uniq
arch = Arch.find_by_name(arch) if arch.acts_like?(:string)
build_lists.create do |bl| build_lists.create do |bl|
bl.save_to_platform = platform bl.save_to_platform = platform
bl.build_for_platform = platform bl.build_for_platform = platform

View File

@ -0,0 +1,8 @@
%h3=t("layout.mass_builds.repositories")
-@platform.repositories.each do |rep|
.both
=check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}", :href => "#{projects_list_platform_repository_path(@platform, rep)}?text=true"
=label_tag "repositories_#{rep.id}", rep.name
%h3=t("layout.mass_builds.projects_list")
=text_area_tag :projects_list, nil

View File

@ -3,13 +3,7 @@
= form_for :build, :url => platform_mass_builds_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f| = form_for :build, :url => platform_mass_builds_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
%section.left %section.left
%h3= t("layout.mass_builds.repositories") =render 'repos_or_list_choice'
- @platform.repositories.each do |rep|
.both
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}"
= label_tag "repositories_#{rep.id}", rep.name
%h3= t("layout.mass_builds.projects_list")
= text_area_tag :projects_list, nil
%br %br
= f.submit t("layout.projects.build_button") = f.submit t("layout.projects.build_button")
%section.right %section.right

View File

@ -13,7 +13,8 @@ Mime::Type.register "text/plain", 'patch'
["text/x-rpm-spec", ['spec'], '8bit'], ["text/x-rpm-spec", ['spec'], '8bit'],
["text/x-csrc", ['h', 'c'], '8bit'], ["text/x-csrc", ['h', 'c'], '8bit'],
["text/x-c++src", ['cpp'], '8bit'], ["text/x-c++src", ['cpp'], '8bit'],
["text/x-diff", ['diff'], '8bit'] ["text/x-diff", ['diff'], '8bit'],
["text/x-markdown", ['md'], '8bit']
].each do |type| ].each do |type|
MIME::Types.add MIME::Type.from_array(type) MIME::Types.add MIME::Type.from_array(type)
end end

View File

@ -22,4 +22,3 @@ en:
user: User user: User
auto_publish: Auto Publish auto_publish: Auto Publish
repositories: Repositories repositories: Repositories
rep_names: Repositories

View File

@ -22,4 +22,3 @@ ru:
user: Пользователь user: Пользователь
auto_publish: Авто Публикация auto_publish: Авто Публикация
repositories: Репозитории repositories: Репозитории
rep_names: Репозитории

View File

@ -0,0 +1,5 @@
class RemoveRepNamesFromMassBuild < ActiveRecord::Migration
def change
remove_column :mass_builds, :rep_names
end
end

View File

@ -0,0 +1,6 @@
class AddIndexes < ActiveRecord::Migration
def change
add_index :project_to_repositories, [:repository_id, :project_id], :unique => true
add_index :repositories, :platform_id
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121206143724) do ActiveRecord::Schema.define(:version => 20121211132948) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
@ -250,7 +250,6 @@ ActiveRecord::Schema.define(:version => 20121206143724) do
t.integer "build_started_count", :default => 0, :null => false t.integer "build_started_count", :default => 0, :null => false
t.integer "build_publish_count", :default => 0, :null => false t.integer "build_publish_count", :default => 0, :null => false
t.integer "build_error_count", :default => 0, :null => false t.integer "build_error_count", :default => 0, :null => false
t.string "rep_names"
t.boolean "stop_build", :default => false, :null => false t.boolean "stop_build", :default => false, :null => false
t.text "projects_list" t.text "projects_list"
t.integer "missed_projects_count", :default => 0, :null => false t.integer "missed_projects_count", :default => 0, :null => false
@ -330,6 +329,8 @@ ActiveRecord::Schema.define(:version => 20121206143724) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true
create_table "projects", :force => true do |t| create_table "projects", :force => true do |t|
t.string "name" t.string "name"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
@ -403,6 +404,8 @@ ActiveRecord::Schema.define(:version => 20121206143724) do
t.boolean "publish_without_qa", :default => true t.boolean "publish_without_qa", :default => true
end end
add_index "repositories", ["platform_id"], :name => "index_repositories_on_platform_id"
create_table "settings_notifiers", :force => true do |t| create_table "settings_notifiers", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.boolean "can_notify", :default => true t.boolean "can_notify", :default => true

View File

@ -37,7 +37,7 @@ shared_examples_for 'mass_build platform owner' do
Platform.update_all("platform_type = 'personal'") Platform.update_all("platform_type = 'personal'")
end end
[:cancel, :failed_builds_list, :create].each do |action| [:cancel, :get_list, :create].each do |action|
it "should not be able to perform #{ action } action" do it "should not be able to perform #{ action } action" do
get action, :platform_id => @platform, :id => @mass_build.id get action, :platform_id => @platform, :id => @mass_build.id
response.should redirect_to(forbidden_path) response.should redirect_to(forbidden_path)
@ -54,7 +54,7 @@ shared_examples_for 'mass_build platform reader' do
end end
end end
[:cancel, :failed_builds_list].each do |action| [:cancel, :get_list].each do |action|
it "should not be able to perform #{ action } action" do it "should not be able to perform #{ action } action" do
get action, :platform_id => @platform, :id => @mass_build.id get action, :platform_id => @platform, :id => @mass_build.id
response.should redirect_to(forbidden_path) response.should redirect_to(forbidden_path)
@ -81,14 +81,17 @@ describe Platforms::MassBuildsController do
@repository = FactoryGirl.create(:repository, :platform => @platform) @repository = FactoryGirl.create(:repository, :platform => @platform)
@personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal') @personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal')
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
project = FactoryGirl.create(:project, :owner => @user)
@repository.projects << project
@create_params = { @create_params = {
:platform_id => @platform, :platform_id => @platform,
:repositories => [@platform.repositories.first.id], :projects_list => @repository.projects.map(&:name).join("\n"),
:arches => [Arch.first.id], :arches => [Arch.first.id],
:auto_publish => true :auto_publish => true
} }
@mass_build = FactoryGirl.create(:mass_build, :platform => @platform, :user => @user) @mass_build = FactoryGirl.create(:mass_build, :platform => @platform, :user => @user, :projects_list => project.name)
end end
context 'for guest' do context 'for guest' do
@ -99,8 +102,8 @@ describe Platforms::MassBuildsController do
end end
end end
it "should not be able to perform failed_builds_list action" do it "should not be able to get failed builds list" do
get :failed_builds_list, :platform_id => @platform, :id => @mass_build get :get_list, :platform_id => @platform, :id => @mass_build, :kind => 'failed_builds_list'
response.should redirect_to(new_user_session_path) response.should redirect_to(new_user_session_path)
end end
@ -161,4 +164,3 @@ describe Platforms::MassBuildsController do
it_should_behave_like 'mass_build platform reader' it_should_behave_like 'mass_build platform reader'
end end
end end

View File

@ -4,7 +4,7 @@ FactoryGirl.define do
association :platform association :platform
#name FactoryGirl.generate(:name) #name FactoryGirl.generate(:name)
association :user association :user
repositories { |mb| [ mb.platform.repositories.first.id ] } projects_list "first"
arches { [ Arch.first.id ] } arches { [ Arch.first.id ] }
auto_publish true auto_publish true
stop_build false stop_build false

View File

@ -176,14 +176,14 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
return "string"; return "string";
} }
CodeMirror.defineMIME("text/x-csrc", { CodeMirror.defineMIME("application/x-csrc", {
name: "clike", name: "clike",
keywords: words(cKeywords), keywords: words(cKeywords),
blockKeywords: words("case do else for if switch while struct"), blockKeywords: words("case do else for if switch while struct"),
atoms: words("null"), atoms: words("null"),
hooks: {"#": cppHook} hooks: {"#": cppHook}
}); });
CodeMirror.defineMIME("text/x-c++src", { CodeMirror.defineMIME("application/x-c++src", {
name: "clike", name: "clike",
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " + keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
"static_cast typeid catch operator template typename class friend private " + "static_cast typeid catch operator template typename class friend private " +
@ -193,7 +193,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
atoms: words("true false null"), atoms: words("true false null"),
hooks: {"#": cppHook} hooks: {"#": cppHook}
}); });
CodeMirror.defineMIME("text/x-java", { CodeMirror.defineMIME("application/x-java", {
name: "clike", name: "clike",
keywords: words("abstract assert boolean break byte case catch char class const continue default " + keywords: words("abstract assert boolean break byte case catch char class const continue default " +
"do double else enum extends final finally float for goto if implements import " + "do double else enum extends final finally float for goto if implements import " +
@ -209,7 +209,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
} }
} }
}); });
CodeMirror.defineMIME("text/x-csharp", { CodeMirror.defineMIME("application/x-csharp", {
name: "clike", name: "clike",
keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" + keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
" default delegate do double else enum event explicit extern finally fixed float for" + " default delegate do double else enum event explicit extern finally fixed float for" +

View File

@ -205,3 +205,4 @@ CodeMirror.defineMode("clojure", function (config, mode) {
}); });
CodeMirror.defineMIME("text/x-clojure", "clojure"); CodeMirror.defineMIME("text/x-clojure", "clojure");
CodeMirror.defineMIME("application/x-clojure", "clojure");

View File

@ -339,3 +339,4 @@ CodeMirror.defineMode('coffeescript', function(conf) {
}); });
CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript'); CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript');
CodeMirror.defineMIME('application/x-coffeescript', 'coffeescript');

View File

@ -122,3 +122,4 @@ CodeMirror.defineMode("css", function(config) {
}); });
CodeMirror.defineMIME("text/css", "css"); CodeMirror.defineMIME("text/css", "css");
CodeMirror.defineMIME('application/x-coffeescript', 'css');

View File

@ -11,3 +11,4 @@ CodeMirror.defineMode("diff", function() {
}); });
CodeMirror.defineMIME("text/x-diff", "diff"); CodeMirror.defineMIME("text/x-diff", "diff");
CodeMirror.defineMIME("application/x-diff", "diff");

View File

@ -170,3 +170,4 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
}); });
CodeMirror.defineMIME("text/x-go", "go"); CodeMirror.defineMIME("text/x-go", "go");
CodeMirror.defineMIME("application/x-go", "go");

View File

@ -208,3 +208,4 @@ CodeMirror.defineMode("groovy", function(config, parserConfig) {
}); });
CodeMirror.defineMIME("text/x-groovy", "groovy"); CodeMirror.defineMIME("text/x-groovy", "groovy");
CodeMirror.defineMIME("application/x-groovy", "groovy");

View File

@ -4,7 +4,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
setState(f); setState(f);
return f(source, setState); return f(source, setState);
} }
// These should all be Unicode extended, as per the Haskell 2010 report // These should all be Unicode extended, as per the Haskell 2010 report
var smallRE = /[a-z_]/; var smallRE = /[a-z_]/;
var largeRE = /[A-Z]/; var largeRE = /[A-Z]/;
@ -15,12 +15,12 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/; var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
var specialRE = /[(),;[\]`{}]/; var specialRE = /[(),;[\]`{}]/;
var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer
function normal(source, setState) { function normal(source, setState) {
if (source.eatWhile(whiteCharRE)) { if (source.eatWhile(whiteCharRE)) {
return null; return null;
} }
var ch = source.next(); var ch = source.next();
if (specialRE.test(ch)) { if (specialRE.test(ch)) {
if (ch == '{' && source.eat('-')) { if (ch == '{' && source.eat('-')) {
@ -32,7 +32,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
} }
return null; return null;
} }
if (ch == '\'') { if (ch == '\'') {
if (source.eat('\\')) { if (source.eat('\\')) {
source.next(); // should handle other escapes here source.next(); // should handle other escapes here
@ -45,11 +45,11 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
} }
return "error"; return "error";
} }
if (ch == '"') { if (ch == '"') {
return switchState(source, setState, stringLiteral); return switchState(source, setState, stringLiteral);
} }
if (largeRE.test(ch)) { if (largeRE.test(ch)) {
source.eatWhile(idRE); source.eatWhile(idRE);
if (source.eat('.')) { if (source.eat('.')) {
@ -57,12 +57,12 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
} }
return "variable-2"; return "variable-2";
} }
if (smallRE.test(ch)) { if (smallRE.test(ch)) {
source.eatWhile(idRE); source.eatWhile(idRE);
return "variable"; return "variable";
} }
if (digitRE.test(ch)) { if (digitRE.test(ch)) {
if (ch == '0') { if (ch == '0') {
if (source.eat(/[xX]/)) { if (source.eat(/[xX]/)) {
@ -87,7 +87,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
} }
return t; return t;
} }
if (symbolRE.test(ch)) { if (symbolRE.test(ch)) {
if (ch == '-' && source.eat(/-/)) { if (ch == '-' && source.eat(/-/)) {
source.eatWhile(/-/); source.eatWhile(/-/);
@ -101,12 +101,12 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
t = "variable-2"; t = "variable-2";
} }
source.eatWhile(symbolRE); source.eatWhile(symbolRE);
return t; return t;
} }
return "error"; return "error";
} }
function ncomment(type, nest) { function ncomment(type, nest) {
if (nest == 0) { if (nest == 0) {
return normal; return normal;
@ -130,7 +130,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
return type; return type;
} }
} }
function stringLiteral(source, setState) { function stringLiteral(source, setState) {
while (!source.eol()) { while (!source.eol()) {
var ch = source.next(); var ch = source.next();
@ -153,7 +153,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
setState(normal); setState(normal);
return "error"; return "error";
} }
function stringGap(source, setState) { function stringGap(source, setState) {
if (source.eat('\\')) { if (source.eat('\\')) {
return switchState(source, setState, stringLiteral); return switchState(source, setState, stringLiteral);
@ -162,8 +162,8 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
setState(normal); setState(normal);
return "error"; return "error";
} }
var wellKnownWords = (function() { var wellKnownWords = (function() {
var wkw = {}; var wkw = {};
function setType(t) { function setType(t) {
@ -172,19 +172,19 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
wkw[arguments[i]] = t; wkw[arguments[i]] = t;
} }
} }
setType("keyword")( setType("keyword")(
"case", "class", "data", "default", "deriving", "do", "else", "foreign", "case", "class", "data", "default", "deriving", "do", "else", "foreign",
"if", "import", "in", "infix", "infixl", "infixr", "instance", "let", "if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
"module", "newtype", "of", "then", "type", "where", "_"); "module", "newtype", "of", "then", "type", "where", "_");
setType("keyword")( setType("keyword")(
"\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>"); "\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
setType("builtin")( setType("builtin")(
"!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<", "!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
"==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**"); "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
setType("builtin")( setType("builtin")(
"Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq", "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
"False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT", "False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
@ -192,7 +192,7 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
"Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read", "Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
"ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS", "ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
"String", "True"); "String", "True");
setType("builtin")( setType("builtin")(
"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf", "abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling", "asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
@ -220,16 +220,16 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
"toRational", "truncate", "uncurry", "undefined", "unlines", "until", "toRational", "truncate", "uncurry", "undefined", "unlines", "until",
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip", "unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
"zip3", "zipWith", "zipWith3"); "zip3", "zipWith", "zipWith3");
return wkw; return wkw;
})(); })();
return { return {
startState: function () { return { f: normal }; }, startState: function () { return { f: normal }; },
copyState: function (s) { return { f: s.f }; }, copyState: function (s) { return { f: s.f }; },
token: function(stream, state) { token: function(stream, state) {
var t = state.f(stream, function(s) { state.f = s; }); var t = state.f(stream, function(s) { state.f = s; });
var w = stream.current(); var w = stream.current();
@ -240,3 +240,4 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
}); });
CodeMirror.defineMIME("text/x-haskell", "haskell"); CodeMirror.defineMIME("text/x-haskell", "haskell");
CodeMirror.defineMIME("application/x-haskell", "haskell");

View File

@ -81,3 +81,4 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
}); });
CodeMirror.defineMIME("text/html", "htmlmixed"); CodeMirror.defineMIME("text/html", "htmlmixed");
CodeMirror.defineMIME("application/html", "htmlmixed");

View File

@ -53,7 +53,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
else if (ch == "0" && stream.eat(/x/i)) { else if (ch == "0" && stream.eat(/x/i)) {
stream.eatWhile(/[\da-f]/i); stream.eatWhile(/[\da-f]/i);
return ret("number", "number"); return ret("number", "number");
} }
else if (/\d/.test(ch)) { else if (/\d/.test(ch)) {
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
return ret("number", "number"); return ret("number", "number");
@ -135,7 +135,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
// Communicate our context to the combinators. // Communicate our context to the combinators.
// (Less wasteful than consing up a hundred closures on every call.) // (Less wasteful than consing up a hundred closures on every call.)
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
if (!state.lexical.hasOwnProperty("align")) if (!state.lexical.hasOwnProperty("align"))
state.lexical.align = true; state.lexical.align = true;
@ -240,7 +240,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type.match(/[;\}\)\],]/)) return pass(); if (type.match(/[;\}\)\],]/)) return pass();
return pass(expression); return pass(expression);
} }
function maybeoperator(type, value) { function maybeoperator(type, value) {
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
if (type == "operator") return cont(expression); if (type == "operator") return cont(expression);
@ -357,4 +357,5 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
}); });
CodeMirror.defineMIME("text/javascript", "javascript"); CodeMirror.defineMIME("text/javascript", "javascript");
CodeMirror.defineMIME("application/javascript", "javascript");
CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); CodeMirror.defineMIME("application/json", {name: "javascript", json: true});

View File

@ -1,7 +1,7 @@
// LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's // LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's
// CodeMirror 1 mode. // CodeMirror 1 mode.
// highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting // highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting
CodeMirror.defineMode("lua", function(config, parserConfig) { CodeMirror.defineMode("lua", function(config, parserConfig) {
var indentUnit = config.indentUnit; var indentUnit = config.indentUnit;
@ -12,7 +12,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
return new RegExp("^(?:" + words.join("|") + ")$", "i"); return new RegExp("^(?:" + words.join("|") + ")$", "i");
} }
var specials = wordRE(parserConfig.specials || []); var specials = wordRE(parserConfig.specials || []);
// long list of standard functions from lua manual // long list of standard functions from lua manual
var builtins = wordRE([ var builtins = wordRE([
"_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load", "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load",
@ -47,7 +47,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
"table.concat","table.insert","table.maxn","table.remove","table.sort" "table.concat","table.insert","table.maxn","table.remove","table.sort"
]); ]);
var keywords = wordRE(["and","break","elseif","false","nil","not","or","return", var keywords = wordRE(["and","break","elseif","false","nil","not","or","return",
"true","function", "end", "if", "then", "else", "do", "true","function", "end", "if", "then", "else", "do",
"while", "repeat", "until", "for", "in", "local" ]); "while", "repeat", "until", "for", "in", "local" ]);
var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]); var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]);
@ -68,7 +68,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state); return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state);
stream.skipToEnd(); stream.skipToEnd();
return "comment"; return "comment";
} }
if (ch == "\"" || ch == "'") if (ch == "\"" || ch == "'")
return (state.cur = string(ch))(stream, state); return (state.cur = string(ch))(stream, state);
if (ch == "[" && /[\[=]/.test(stream.peek())) if (ch == "[" && /[\[=]/.test(stream.peek()))
@ -108,7 +108,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
return "string"; return "string";
}; };
} }
return { return {
startState: function(basecol) { startState: function(basecol) {
return {basecol: basecol || 0, indentDepth: 0, cur: normal}; return {basecol: basecol || 0, indentDepth: 0, cur: normal};
@ -138,3 +138,4 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
}); });
CodeMirror.defineMIME("text/x-lua", "lua"); CodeMirror.defineMIME("text/x-lua", "lua");
CodeMirror.defineMIME("application/x-lua", "lua");

View File

@ -38,11 +38,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
stream.skipToEnd(); stream.skipToEnd();
return code; return code;
} }
if (stream.eatSpace()) { if (stream.eatSpace()) {
return null; return null;
} }
if (stream.peek() === '#' || stream.match(headerRE)) { if (stream.peek() === '#' || stream.match(headerRE)) {
stream.skipToEnd(); stream.skipToEnd();
return header; return header;
@ -60,13 +60,13 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return hr; return hr;
} }
} }
var match; var match;
if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { if (match = stream.match(ulRE, true) || stream.match(olRE, true)) {
state.indentation += match[0].length; state.indentation += match[0].length;
return list; return list;
} }
return switchInline(stream, state, state.inline); return switchInline(stream, state, state.inline);
} }
@ -90,16 +90,16 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (stream.match(textRE, true)) { if (stream.match(textRE, true)) {
return getType(state); return getType(state);
} }
return undefined; return undefined;
} }
function inlineNormal(stream, state) { function inlineNormal(stream, state) {
var style = state.text(stream, state) var style = state.text(stream, state)
if (typeof style !== 'undefined') if (typeof style !== 'undefined')
return style; return style;
var ch = stream.next(); var ch = stream.next();
if (ch === '\\') { if (ch === '\\') {
stream.next(); stream.next();
return getType(state); return getType(state);
@ -122,7 +122,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
} }
return (state.em = !state.em) ? getType(state) : t; return (state.em = !state.em) ? getType(state) : t;
} }
return getType(state); return getType(state);
} }
@ -184,11 +184,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
startState: function() { startState: function() {
return { return {
f: blockNormal, f: blockNormal,
block: blockNormal, block: blockNormal,
htmlState: htmlMode.startState(), htmlState: htmlMode.startState(),
indentation: 0, indentation: 0,
inline: inlineNormal, inline: inlineNormal,
text: handleText, text: handleText,
em: false, em: false,
@ -199,11 +199,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
copyState: function(s) { copyState: function(s) {
return { return {
f: s.f, f: s.f,
block: s.block, block: s.block,
htmlState: CodeMirror.copyState(htmlMode, s.htmlState), htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
indentation: s.indentation, indentation: s.indentation,
inline: s.inline, inline: s.inline,
text: s.text, text: s.text,
em: s.em, em: s.em,
@ -228,7 +228,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
} }
} }
state.indentation = currentIndentation; state.indentation = currentIndentation;
if (currentIndentation > 0) return null; if (currentIndentation > 0) return null;
} }
return state.f(stream, state); return state.f(stream, state);
@ -240,3 +240,4 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
}); });
CodeMirror.defineMIME("text/x-markdown", "markdown"); CodeMirror.defineMIME("text/x-markdown", "markdown");
CodeMirror.defineMIME("application/x-markdown", "markdown");

View File

@ -186,3 +186,4 @@ CodeMirror.defineMode("mysql", function(config) {
}); });
CodeMirror.defineMIME("text/x-mysql", "mysql"); CodeMirror.defineMIME("text/x-mysql", "mysql");
CodeMirror.defineMIME("application/x-mysql", "mysql");

View File

@ -136,3 +136,4 @@ CodeMirror.defineMode("pascal", function(config) {
}); });
CodeMirror.defineMIME("text/x-pascal", "pascal"); CodeMirror.defineMIME("text/x-pascal", "pascal");
CodeMirror.defineMIME("application/x-pascal", "pascal");

View File

@ -778,6 +778,7 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
electricChars:"{}"}}); electricChars:"{}"}});
CodeMirror.defineMIME("text/x-perl", "perl"); CodeMirror.defineMIME("text/x-perl", "perl");
CodeMirror.defineMIME("application/x-perl", "perl");
// it's like "peek", but need for look-ahead or look-behind if index < 0 // it's like "peek", but need for look-ahead or look-behind if index < 0
CodeMirror.StringStream.prototype.look=function(c){ CodeMirror.StringStream.prototype.look=function(c){

View File

@ -118,4 +118,5 @@
CodeMirror.defineMIME("application/x-httpd-php", "php"); CodeMirror.defineMIME("application/x-httpd-php", "php");
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true}); CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
CodeMirror.defineMIME("text/x-php", phpConfig); CodeMirror.defineMIME("text/x-php", phpConfig);
CodeMirror.defineMIME("application/x-php", phpConfig);
})(); })();

View File

@ -207,7 +207,7 @@ CodeMirror.defineMode("plsql", function(config, parserConfig) {
"verify version " + "verify version " +
"wrap"; "wrap";
CodeMirror.defineMIME("text/x-plsql", { CodeMirror.defineMIME("application/x-plsql", {
name: "plsql", name: "plsql",
keywords: keywords(cKeywords), keywords: keywords(cKeywords),
functions: keywords(cFunctions), functions: keywords(cFunctions),

View File

@ -1,10 +1,10 @@
CodeMirror.defineMode("python", function(conf, parserConf) { CodeMirror.defineMode("python", function(conf, parserConf) {
var ERRORCLASS = 'error'; var ERRORCLASS = 'error';
function wordRegexp(words) { function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b"); return new RegExp("^((" + words.join(")|(") + "))\\b");
} }
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
@ -72,15 +72,15 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (stream.eatSpace()) { if (stream.eatSpace()) {
return null; return null;
} }
var ch = stream.peek(); var ch = stream.peek();
// Handle Comments // Handle Comments
if (ch === '#') { if (ch === '#') {
stream.skipToEnd(); stream.skipToEnd();
return 'comment'; return 'comment';
} }
// Handle Number Literals // Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) { if (stream.match(/^[0-9\.]/, false)) {
var floatLiteral = false; var floatLiteral = false;
@ -116,13 +116,13 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return 'number'; return 'number';
} }
} }
// Handle Strings // Handle Strings
if (stream.match(stringPrefixes)) { if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current()); state.tokenize = tokenStringFactory(stream.current());
return state.tokenize(stream, state); return state.tokenize(stream, state);
} }
// Handle operators and Delimiters // Handle operators and Delimiters
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
return null; return null;
@ -135,31 +135,31 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (stream.match(singleDelimiters)) { if (stream.match(singleDelimiters)) {
return null; return null;
} }
if (stream.match(keywords)) { if (stream.match(keywords)) {
return 'keyword'; return 'keyword';
} }
if (stream.match(builtins)) { if (stream.match(builtins)) {
return 'builtin'; return 'builtin';
} }
if (stream.match(identifiers)) { if (stream.match(identifiers)) {
return 'variable'; return 'variable';
} }
// Handle non-detected items // Handle non-detected items
stream.next(); stream.next();
return ERRORCLASS; return ERRORCLASS;
} }
function tokenStringFactory(delimiter) { function tokenStringFactory(delimiter) {
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) { while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1); delimiter = delimiter.substr(1);
} }
var singleline = delimiter.length == 1; var singleline = delimiter.length == 1;
var OUTCLASS = 'string'; var OUTCLASS = 'string';
return function tokenString(stream, state) { return function tokenString(stream, state) {
while (!stream.eol()) { while (!stream.eol()) {
stream.eatWhile(/[^'"\\]/); stream.eatWhile(/[^'"\\]/);
@ -185,7 +185,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return OUTCLASS; return OUTCLASS;
}; };
} }
function indent(stream, state, type) { function indent(stream, state, type) {
type = type || 'py'; type = type || 'py';
var indentUnit = 0; var indentUnit = 0;
@ -208,7 +208,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
type: type type: type
}); });
} }
function dedent(stream, state, type) { function dedent(stream, state, type) {
type = type || 'py'; type = type || 'py';
if (state.scopes.length == 1) return; if (state.scopes.length == 1) return;
@ -257,7 +257,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return ERRORCLASS; return ERRORCLASS;
} }
} }
// Handle decorators // Handle decorators
if (current === '@') { if (current === '@') {
style = state.tokenize(stream, state); style = state.tokenize(stream, state);
@ -270,7 +270,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return ERRORCLASS; return ERRORCLASS;
} }
} }
// Handle scope changes. // Handle scope changes.
if (current === 'pass' || current === 'return') { if (current === 'pass' || current === 'return') {
state.dedent += 1; state.dedent += 1;
@ -298,7 +298,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (state.scopes.length > 1) state.scopes.shift(); if (state.scopes.length > 1) state.scopes.shift();
state.dedent -= 1; state.dedent -= 1;
} }
return style; return style;
} }
@ -312,29 +312,30 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
dedent: 0 dedent: 0
}; };
}, },
token: function(stream, state) { token: function(stream, state) {
var style = tokenLexer(stream, state); var style = tokenLexer(stream, state);
state.lastToken = {style:style, content: stream.current()}; state.lastToken = {style:style, content: stream.current()};
if (stream.eol() && stream.lambda) { if (stream.eol() && stream.lambda) {
state.lambda = false; state.lambda = false;
} }
return style; return style;
}, },
indent: function(state, textAfter) { indent: function(state, textAfter) {
if (state.tokenize != tokenBase) { if (state.tokenize != tokenBase) {
return 0; return 0;
} }
return state.scopes[0].offset; return state.scopes[0].offset;
} }
}; };
return external; return external;
}); });
CodeMirror.defineMIME("text/x-python", "python"); CodeMirror.defineMIME("text/x-python", "python");
CodeMirror.defineMIME("application/x-python", "python");

View File

@ -139,3 +139,4 @@ CodeMirror.defineMode("r", function(config) {
}); });
CodeMirror.defineMIME("text/x-rsrc", "r"); CodeMirror.defineMIME("text/x-rsrc", "r");
CodeMirror.defineMIME("application/x-rsrc", "r");

View File

@ -17,3 +17,4 @@ CodeMirror.defineMode("changes", function(config, modeConfig) {
}); });
CodeMirror.defineMIME("text/x-rpm-changes", "changes"); CodeMirror.defineMIME("text/x-rpm-changes", "changes");
CodeMirror.defineMIME("application/x-rpm-changes", "changes");

View File

@ -64,3 +64,4 @@ CodeMirror.defineMode("spec", function(config, modeConfig) {
}); });
CodeMirror.defineMIME("text/x-rpm-spec", "spec"); CodeMirror.defineMIME("text/x-rpm-spec", "spec");
CodeMirror.defineMIME("application/x-rpm-spec", "spec");

View File

@ -324,3 +324,4 @@ CodeMirror.defineMode('rst', function(config, options) {
}); });
CodeMirror.defineMIME("text/x-rst", "rst"); CodeMirror.defineMIME("text/x-rst", "rst");
CodeMirror.defineMIME("application/x-rst", "rst");

View File

@ -197,4 +197,5 @@ CodeMirror.defineMode("ruby", function(config, parserConfig) {
}); });
CodeMirror.defineMIME("text/x-ruby", "ruby"); CodeMirror.defineMIME("text/x-ruby", "ruby");
CodeMirror.defineMIME("application/x-ruby", "ruby");

View File

@ -430,3 +430,4 @@ CodeMirror.defineMode("rust", function() {
}); });
CodeMirror.defineMIME("text/x-rustsrc", "rust"); CodeMirror.defineMIME("text/x-rustsrc", "rust");
CodeMirror.defineMIME("application/x-rustsrc", "rust");

View File

@ -5,7 +5,7 @@ CodeMirror.defineMode("scheme", function (config, mode) {
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword"; ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword";
var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1; var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
function makeKeywords(str) { function makeKeywords(str) {
var obj = {}, words = str.split(" "); var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true; for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
@ -14,7 +14,7 @@ CodeMirror.defineMode("scheme", function (config, mode) {
var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?"); var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
var indentKeys = makeKeywords("define let letrec let* lambda"); var indentKeys = makeKeywords("define let letrec let* lambda");
function stateStack(indent, type, prev) { // represents a state stack object function stateStack(indent, type, prev) { // represents a state stack object
this.indent = indent; this.indent = indent;
@ -29,14 +29,14 @@ CodeMirror.defineMode("scheme", function (config, mode) {
function popStack(state) { function popStack(state) {
state.indentStack = state.indentStack.prev; state.indentStack = state.indentStack.prev;
} }
/** /**
* Scheme numbers are complicated unfortunately. * Scheme numbers are complicated unfortunately.
* Checks if we're looking at a number, which might be possibly a fraction. * Checks if we're looking at a number, which might be possibly a fraction.
* Also checks that it is not part of a longer identifier. Returns true/false accordingly. * Also checks that it is not part of a longer identifier. Returns true/false accordingly.
*/ */
function isNumber(ch, stream){ function isNumber(ch, stream){
if(/[0-9]/.exec(ch) != null){ if(/[0-9]/.exec(ch) != null){
stream.eatWhile(/[0-9]/); stream.eatWhile(/[0-9]/);
stream.eat(/\//); stream.eat(/\//);
stream.eatWhile(/[0-9]/); stream.eatWhile(/[0-9]/);
@ -67,13 +67,13 @@ CodeMirror.defineMode("scheme", function (config, mode) {
return null; return null;
} }
var returnType = null; var returnType = null;
switch(state.mode){ switch(state.mode){
case "string": // multi-line string parsing mode case "string": // multi-line string parsing mode
var next, escaped = false; var next, escaped = false;
while ((next = stream.next()) != null) { while ((next = stream.next()) != null) {
if (next == "\"" && !escaped) { if (next == "\"" && !escaped) {
state.mode = false; state.mode = false;
break; break;
} }
@ -85,7 +85,7 @@ CodeMirror.defineMode("scheme", function (config, mode) {
var next, maybeEnd = false; var next, maybeEnd = false;
while ((next = stream.next()) != null) { while ((next = stream.next()) != null) {
if (next == "#" && maybeEnd) { if (next == "#" && maybeEnd) {
state.mode = false; state.mode = false;
break; break;
} }
@ -106,11 +106,11 @@ CodeMirror.defineMode("scheme", function (config, mode) {
} }
default: // default parsing mode default: // default parsing mode
var ch = stream.next(); var ch = stream.next();
if (ch == "\"") { if (ch == "\"") {
state.mode = "string"; state.mode = "string";
returnType = STRING; returnType = STRING;
} else if (ch == "'") { } else if (ch == "'") {
returnType = ATOM; returnType = ATOM;
} else if (ch == '#') { } else if (ch == '#') {
@ -123,16 +123,16 @@ CodeMirror.defineMode("scheme", function (config, mode) {
state.mode = "s-expr-comment"; state.mode = "s-expr-comment";
returnType = COMMENT; returnType = COMMENT;
} }
} else if (ch == ";") { // comment } else if (ch == ";") { // comment
stream.skipToEnd(); // rest of the line is a comment stream.skipToEnd(); // rest of the line is a comment
returnType = COMMENT; returnType = COMMENT;
} else if (ch == "-"){ } else if (ch == "-"){
if(!isNaN(parseInt(stream.peek()))){ if(!isNaN(parseInt(stream.peek()))){
stream.eatWhile(/[\/0-9]/); stream.eatWhile(/[\/0-9]/);
returnType = NUMBER; returnType = NUMBER;
}else{ }else{
returnType = null; returnType = null;
} }
} else if (isNumber(ch,stream)){ } else if (isNumber(ch,stream)){
@ -140,18 +140,18 @@ CodeMirror.defineMode("scheme", function (config, mode) {
} else if (ch == "(" || ch == "[") { } else if (ch == "(" || ch == "[") {
var keyWord = ''; var indentTemp = stream.column(); var keyWord = ''; var indentTemp = stream.column();
/** /**
Either Either
(indent-word .. (indent-word ..
(non-indent-word .. (non-indent-word ..
(;something else, bracket, etc. (;something else, bracket, etc.
*/ */
while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) { while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
keyWord += letter; keyWord += letter;
} }
if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
} else { // non-indent word } else { // non-indent word
// we continue eating the spaces // we continue eating the spaces
@ -165,15 +165,15 @@ CodeMirror.defineMode("scheme", function (config, mode) {
} }
} }
stream.backUp(stream.current().length - 1); // undo all the eating stream.backUp(stream.current().length - 1); // undo all the eating
if(typeof state.sExprComment == "number") state.sExprComment++; if(typeof state.sExprComment == "number") state.sExprComment++;
returnType = BRACKET; returnType = BRACKET;
} else if (ch == ")" || ch == "]") { } else if (ch == ")" || ch == "]") {
returnType = BRACKET; returnType = BRACKET;
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) { if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
popStack(state); popStack(state);
if(typeof state.sExprComment == "number"){ if(typeof state.sExprComment == "number"){
if(--state.sExprComment == 0){ if(--state.sExprComment == 0){
returnType = COMMENT; // final closing bracket returnType = COMMENT; // final closing bracket
@ -183,7 +183,7 @@ CodeMirror.defineMode("scheme", function (config, mode) {
} }
} else { } else {
stream.eatWhile(/[\w\$_\-]/); stream.eatWhile(/[\w\$_\-]/);
if (keywords && keywords.propertyIsEnumerable(stream.current())) { if (keywords && keywords.propertyIsEnumerable(stream.current())) {
returnType = BUILTIN; returnType = BUILTIN;
}else returnType = null; }else returnType = null;
@ -199,4 +199,5 @@ CodeMirror.defineMode("scheme", function (config, mode) {
}; };
}); });
CodeMirror.defineMIME("text/x-scheme", "scheme"); CodeMirror.defineMIME("text/x-scheme", "scheme");
CodeMirror.defineMIME("application/x-scheme", "scheme");

View File

@ -0,0 +1,119 @@
CodeMirror.defineMode('shell', function(config) {
var words = {};
function define(style, string) {
var split = string.split(' ');
for(var i = 0; i < split.length; i++) {
words[split[i]] = style;
}
};
// Atoms
define('atom', 'true false');
// Keywords
define('keyword', 'if then do else elif while until for in esac fi fin ' +
'fil done exit set unset export function');
// Commands
define('builtin', 'ab awk bash beep cat cc cd chown chmod chroot clear cp ' +
'curl cut diff echo find gawk gcc get git grep kill killall ln ls make ' +
'mkdir openssl mv nc node npm ping ps restart rm rmdir sed service sh ' +
'shopt shred source sort sleep ssh start stop su sudo tee telnet top ' +
'touch vi vim wall wc wget who write yes zsh');
function tokenBase(stream, state) {
var sol = stream.sol();
var ch = stream.next();
if (ch === '\'' || ch === '"' || ch === '`') {
state.tokens.unshift(tokenString(ch));
return tokenize(stream, state);
}
if (ch === '#') {
if (sol && stream.eat('!')) {
stream.skipToEnd();
return 'meta'; // 'comment'?
}
stream.skipToEnd();
return 'comment';
}
if (ch === '$') {
state.tokens.unshift(tokenDollar);
return tokenize(stream, state);
}
if (ch === '+' || ch === '=') {
return 'operator';
}
if (ch === '-') {
stream.eat('-');
stream.eatWhile(/\w/);
return 'attribute';
}
if (/\d/.test(ch)) {
stream.eatWhile(/\d/);
if(!/\w/.test(stream.peek())) {
return 'number';
}
}
stream.eatWhile(/\w/);
var cur = stream.current();
if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';
return words.hasOwnProperty(cur) ? words[cur] : null;
}
function tokenString(quote) {
return function(stream, state) {
var next, end = false, escaped = false;
while ((next = stream.next()) != null) {
if (next === quote && !escaped) {
end = true;
break;
}
if (next === '$' && !escaped && quote !== '\'') {
escaped = true;
stream.backUp(1);
state.tokens.unshift(tokenDollar);
break;
}
escaped = !escaped && next === '\\';
}
if (end || !escaped) {
state.tokens.shift();
}
return (quote === '`' || quote === ')' ? 'quote' : 'string');
};
};
var tokenDollar = function(stream, state) {
if (state.tokens.length > 1) stream.eat('$');
var ch = stream.next(), hungry = /\w/;
if (ch === '{') hungry = /[^}]/;
if (ch === '(') {
state.tokens[0] = tokenString(')');
return tokenize(stream, state);
}
if (!/\d/.test(ch)) {
stream.eatWhile(hungry);
stream.eat('}');
}
state.tokens.shift();
return 'def';
};
function tokenize(stream, state) {
return (state.tokens[0] || tokenBase) (stream, state);
};
return {
startState: function() {return {tokens:[]};},
token: function(stream, state) {
if (stream.eatSpace()) return null;
return tokenize(stream, state);
}
};
});
CodeMirror.defineMIME('text/x-sh', 'shell');
CodeMirror.defineMIME('application/x-sh', 'shell');

View File

@ -136,4 +136,5 @@ CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
}); });
CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'}); CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
CodeMirror.defineMIME('application/x-stsrc', {name: 'smalltalk'});

View File

@ -3,13 +3,13 @@
* Licence: MIT * Licence: MIT
*/ */
CodeMirror.defineMode("stex", function(cmCfg, modeCfg) CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
{ {
function pushCommand(state, command) { function pushCommand(state, command) {
state.cmdState.push(command); state.cmdState.push(command);
} }
function peekCommand(state) { function peekCommand(state) {
if (state.cmdState.length>0) if (state.cmdState.length>0)
return state.cmdState[state.cmdState.length-1]; return state.cmdState[state.cmdState.length-1];
else else
@ -20,7 +20,7 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
if (state.cmdState.length>0) { if (state.cmdState.length>0) {
var plug = state.cmdState.pop(); var plug = state.cmdState.pop();
plug.closeBracket(); plug.closeBracket();
} }
} }
function applyMostPowerful(state) { function applyMostPowerful(state) {
@ -58,7 +58,7 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
} }
var plugins = new Array(); var plugins = new Array();
plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]); plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]);
plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]); plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]);
plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]); plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
@ -99,7 +99,7 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
if (ch == "%") { if (ch == "%") {
setState(state, inCComment); setState(state, inCComment);
return "comment"; return "comment";
} }
else if (ch=='}' || ch==']') { else if (ch=='}' || ch==']') {
plug = peekCommand(state); plug = peekCommand(state);
if (plug) { if (plug) {
@ -109,10 +109,10 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
return "error"; return "error";
return "bracket"; return "bracket";
} else if (ch=='{' || ch=='[') { } else if (ch=='{' || ch=='[') {
plug = plugins["DEFAULT"]; plug = plugins["DEFAULT"];
plug = new plug(); plug = new plug();
pushCommand(state, plug); pushCommand(state, plug);
return "bracket"; return "bracket";
} }
else if (/\d/.test(ch)) { else if (/\d/.test(ch)) {
source.eatWhile(/[\w.%]/); source.eatWhile(/[\w.%]/);
@ -154,7 +154,7 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
return { return {
startState: function() { return { f:normal, cmdState:[] }; }, startState: function() { return { f:normal, cmdState:[] }; },
copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; }, copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; },
token: function(stream, state) { token: function(stream, state) {
var t = state.f(stream, state); var t = state.f(stream, state);
var w = stream.current(); var w = stream.current();
@ -165,3 +165,4 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
CodeMirror.defineMIME("text/x-stex", "stex"); CodeMirror.defineMIME("text/x-stex", "stex");
CodeMirror.defineMIME("application/x-stex", "stex");

View File

@ -90,14 +90,14 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
} }
function jsTokenBase(stream, state) { function jsTokenBase(stream, state) {
var sol = stream.sol(), var sol = stream.sol(),
ch, tch; ch, tch;
state.block = false; // indicates the start of a code block. state.block = false; // indicates the start of a code block.
ch = stream.peek(); // don't eat, to make match simpler ch = stream.peek(); // don't eat, to make match simpler
// check start of blocks // check start of blocks
if (sol && /[<\/\*{}\-]/.test(ch)) { if (sol && /[<\/\*{}\-]/.test(ch)) {
if (stream.match(reCodeBlockStart)) { if (stream.match(reCodeBlockStart)) {
state.block = true; state.block = true;
@ -180,7 +180,7 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
if (stream.eat("%")) { if (stream.eat("%")) {
return chain(stream, state, twTokenComment); return chain(stream, state, twTokenComment);
} }
else if (stream.eat("/")) { // else if (stream.eat("/")) { //
return chain(stream, state, twTokenEm); return chain(stream, state, twTokenEm);
} }
} }
@ -254,7 +254,7 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
// tw code // tw code
function twTokenCode(stream, state) { function twTokenCode(stream, state) {
var ch, sb = state.block; var ch, sb = state.block;
if (sb && stream.current()) { if (sb && stream.current()) {
return ret("code", "code"); return ret("code", "code");
} }
@ -301,12 +301,12 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
return ret("text", "underlined"); return ret("text", "underlined");
} }
// tw strike through text looks ugly // tw strike through text looks ugly
// TODO just strike through the first and last 2 chars if possible. // TODO just strike through the first and last 2 chars if possible.
function twTokenStrike(stream, state) { function twTokenStrike(stream, state) {
var maybeEnd = false, var maybeEnd = false,
ch, nr; ch, nr;
while (ch = stream.next()) { while (ch = stream.next()) {
if (ch == "-" && maybeEnd) { if (ch == "-" && maybeEnd) {
state.tokenize = jsTokenBase; state.tokenize = jsTokenBase;
@ -371,4 +371,5 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
}); });
CodeMirror.defineMIME("text/x-tiddlywiki", "tiddlywiki"); CodeMirror.defineMIME("text/x-tiddlywiki", "tiddlywiki");
CodeMirror.defineMIME("application/x-tiddlywiki", "tiddlywiki");
//}}} //}}}

View File

@ -144,3 +144,4 @@ CodeMirror.defineMode("velocity", function(config) {
}); });
CodeMirror.defineMIME("text/velocity", "velocity"); CodeMirror.defineMIME("text/velocity", "velocity");
CodeMirror.defineMIME("application/velocity", "velocity");

View File

@ -184,7 +184,7 @@ CodeMirror.defineMode("verilog", function(config, parserConfig) {
return "string"; return "string";
} }
CodeMirror.defineMIME("text/x-verilog", { CodeMirror.defineMIME("application/x-verilog", {
name: "verilog", name: "verilog",
keywords: words(verilogKeywords), keywords: words(verilogKeywords),
blockKeywords: words(verilogBlockKeywords), blockKeywords: words(verilogBlockKeywords),

View File

@ -50,7 +50,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var ok; var ok;
if (stream.eat("#")) { if (stream.eat("#")) {
if (stream.eat("x")) { if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";"); ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else { } else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";"); ok = stream.eatWhile(/[\d]/) && stream.eat(";");
} }
@ -256,5 +256,6 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
}; };
}); });
CodeMirror.defineMIME("application/xml", "xml"); //CodeMirror.defineMIME("application/xml", "xml");
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true}); CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
CodeMirror.defineMIME("application/html", {name: "xml", htmlMode: true});

View File

@ -1,8 +1,8 @@
CodeMirror.defineMode("yaml", function() { CodeMirror.defineMode("yaml", function() {
var cons = ['true', 'false', 'on', 'off', 'yes', 'no']; var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i'); var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
return { return {
token: function(stream, state) { token: function(stream, state) {
var ch = stream.peek(); var ch = stream.peek();
@ -31,7 +31,7 @@ CodeMirror.defineMode("yaml", function() {
return "atom"; return "atom";
} }
if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; } if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
/* inline pairs/lists */ /* inline pairs/lists */
if (stream.match(/^(\{|\}|\[|\])/)) { if (stream.match(/^(\{|\}|\[|\])/)) {
if (ch == '{') if (ch == '{')
@ -44,7 +44,7 @@ CodeMirror.defineMode("yaml", function() {
state.inlineList--; state.inlineList--;
return 'meta'; return 'meta';
} }
/* list seperator */ /* list seperator */
if (state.inlineList > 0 && !esc && ch == ',') { if (state.inlineList > 0 && !esc && ch == ',') {
stream.next(); stream.next();
@ -58,7 +58,7 @@ CodeMirror.defineMode("yaml", function() {
stream.next(); stream.next();
return 'meta'; return 'meta';
} }
/* start of value of a pair */ /* start of value of a pair */
if (state.pairStart) { if (state.pairStart) {
/* block literals */ /* block literals */
@ -93,3 +93,4 @@ CodeMirror.defineMode("yaml", function() {
}); });
CodeMirror.defineMIME("text/x-yaml", "yaml"); CodeMirror.defineMIME("text/x-yaml", "yaml");
CodeMirror.defineMIME("application/x-yaml", "yaml");

View File

@ -815,4 +815,3 @@ a.badge:hover {
.badge-inverse[href] { .badge-inverse[href] {
background-color: #1a1a1a; background-color: #1a1a1a;
} }