From ad9e7a62692e07b43853e8c1d90a54230c171ca1 Mon Sep 17 00:00:00 2001 From: Phil Scherer Date: Thu, 8 Aug 2019 21:44:41 -0500 Subject: [PATCH 1/3] Add Octave Documentation --- assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_octave.scss | 9 +++++ lib/docs/filters/octave/clean_html.rb | 45 ++++++++++++++++++++++++ lib/docs/filters/octave/entries.rb | 20 +++++++++++ lib/docs/scrapers/octave.rb | 38 ++++++++++++++++++++ public/icons/docs/octave/16.png | Bin 0 -> 1310 bytes public/icons/docs/octave/16@2x.png | Bin 0 -> 1940 bytes public/icons/docs/octave/SOURCE | 1 + 8 files changed, 114 insertions(+) create mode 100644 assets/stylesheets/pages/_octave.scss create mode 100644 lib/docs/filters/octave/clean_html.rb create mode 100644 lib/docs/filters/octave/entries.rb create mode 100644 lib/docs/scrapers/octave.rb create mode 100644 public/icons/docs/octave/16.png create mode 100644 public/icons/docs/octave/16@2x.png create mode 100644 public/icons/docs/octave/SOURCE diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 85d1134f..7a09dd97 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -75,6 +75,7 @@ 'pages/nginx', 'pages/node', 'pages/npm', + 'pages/octave', 'pages/openjdk', 'pages/perl', 'pages/phalcon', diff --git a/assets/stylesheets/pages/_octave.scss b/assets/stylesheets/pages/_octave.scss new file mode 100644 index 00000000..1dfc3f8c --- /dev/null +++ b/assets/stylesheets/pages/_octave.scss @@ -0,0 +1,9 @@ +._octave { + @extend %simple; + + dl:not([compact]) > dt { @extend %block-label, %label-blue; } + + dl[compact] > dt { @extend %block-label; } + + .footnotes-heading { @extend %block-heading; } +} diff --git a/lib/docs/filters/octave/clean_html.rb b/lib/docs/filters/octave/clean_html.rb new file mode 100644 index 00000000..cae7ec1c --- /dev/null +++ b/lib/docs/filters/octave/clean_html.rb @@ -0,0 +1,45 @@ +module Docs + class Octave + class CleanHtmlFilter < Filter + def call + root_page? ? root : other + doc + end + + def root + @doc = at_css('.contents') + end + + def other + css('.header', 'hr').remove + + css('.footnote > h3').each do |node| + node.name = 'h5' + end + + at_css('h2, h3, h4').name = 'h1' + + css('.example').each do |node| + node.name = 'pre' + node['data-language'] = 'matlab' + node.content = node.content + end + + css('a[name] + dl').each do |node| + node['id'] = node.previous['name'] + end + + css('dt > a[name]', 'th > a[name]').each do |node| + node.parent['id'] = node['name'] + node.parent.content = node.parent.content.strip + end + + css('h5 > a').each do |node| + node.parent['id'] = node['name'] + node.parent.content = node.content + end + + end + end + end +end diff --git a/lib/docs/filters/octave/entries.rb b/lib/docs/filters/octave/entries.rb new file mode 100644 index 00000000..70b29df1 --- /dev/null +++ b/lib/docs/filters/octave/entries.rb @@ -0,0 +1,20 @@ +module Docs + class Octave + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('h1').content + end + + def get_type + 'Manual' + end + + def additional_entries + css('dl:not([compact]) > dt').each_with_object [] do |node, entries| + name = node.content.gsub(/[A-z0-9\,… ]*\=/,'').strip + entries << [name, node['id'], 'Functions'] + end + end + end + end +end diff --git a/lib/docs/scrapers/octave.rb b/lib/docs/scrapers/octave.rb new file mode 100644 index 00000000..1b8e70c0 --- /dev/null +++ b/lib/docs/scrapers/octave.rb @@ -0,0 +1,38 @@ +module Docs + class Octave < UrlScraper + self.name = 'Octave' + self.type = 'octave' + self.release = '5.1.0' + self.base_url = 'https://octave.org/doc/interpreter/' + self.root_path = 'index.html' + self.links = { + home: 'http://www.octave.org/', + code: 'http://www.octave.org/hg/octave' + } + + html_filters.push 'octave/clean_html', 'octave/entries', 'title' + + options[:skip] = %w( + Copying.html + Preface.html + Acknowledgements.html + Citing-Octave-in-Publications.html + How-You-Can-Contribute-to-Octave.html + Distribution.html) + + options[:title] = false + options[:root_title] = 'GNU Octave' + + options[:attribution] = <<-HTML + © 1996–2018 John W. Eaton
+ Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
+Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
+Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
+ HTML + + def get_latest_version(opts) + doc = fetch_doc('https://octave.org/doc/interpreter/', opts) + doc.at_css('h1').content.scan(/([0-9.]+)/)[0][0] + end + end +end diff --git a/public/icons/docs/octave/16.png b/public/icons/docs/octave/16.png new file mode 100644 index 0000000000000000000000000000000000000000..bef5229f9dbf701d066cb7f642d7600307f8b190 GIT binary patch literal 1310 zcmb7CdsLEV7=MA#BD|yy)5@qVwF`!LTg;i39;AdJkVnc3re@BxQnJ*RWS4Wyl}=}A zsB^0vWjQ;wnKwj%@)8(c$WYO8c5J8V$}%yFJ)ZvBpZm`9J@4~=&*l65e(#&hVKXcU zjs%2|1v5C13#;|QyBG)Fm14z%Wl=%^D*&O}`Ag?x@USPx26I^mWjZ4yK8?^Ed=gI} zbcBk~UqXcFB?#FcDr*S!MF<Apf$yEZZFM?f=TnbcTA$x~IJ#NNbj=UXt}%fK%wZ1ual z0E5vm5Ynsf^BIq|017Tu>J3s2u=D@D9}vzS`}~b)wSG4qxVV)y zx?fTF{!~94wdC()dqbK_QEATe1e=FPeN>rS$C4Ze1z4b|WuW4`L(%Pq$d0G4Q&+t^ zy4Da)0M=kI4Fm!1V4q@uw@WcRb`E?04X@~L8zaIBT7U&lTM@wPUWo6zX{3& z%Z4#Uow!1!MX}QQq7oz>k6F^3;eYZ{E(ir?S*%!gNlChVA7IaT#&N5 zs00}u${sjXcGydwlzt}wU`SktyU=1@AYWS4W-qzFvZ9@QMa}!M{875ctHUcN679?i z5O9us464@w}gHCipOe_+zi65p+Mv9Qvxk zIR9qG^itbso6z=px_-xJR!Nq1=K(He?@mTw$G6Q15wI~AFmpHwC04GD}ywS z85qD{-Ww|v#`X02P(5kh?q0F`5SA2{mUrZ0n9lo;^cl+o{+M*euWvPOH7msx z3=za3KiP`;`3y0)33D=_^*C|O&npydM!XoCv+RdZ?KYzOZOOA|wx>^G*XA-i)?X(k zO6m@(bgbH>=@;16ykvP)o1R>|Ze&2zqMI*q*YhEAIyt!`vQZogAEb!aQ6 zTz5LR=t4*Z?TG%310!F(=tWqJ4}qPQ4QJUuow9u`ESx^JOSJt$O9K8;2Pqk2-PUUVuoi8O2epN8av naf$mf78;;}Mxpuesh)Hw_3-}GKyJEh2MvfB#15?4Cd~O4_VGD3 literal 0 HcmV?d00001 diff --git a/public/icons/docs/octave/16@2x.png b/public/icons/docs/octave/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..3f6c9700b3254e8b5619ebc0a53db6ac5dfca41f GIT binary patch literal 1940 zcmV;F2W$9=P)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00006 zVoOIv0RI600RN!9r;`8x00(qQO+^Re0|f&X7$L~owg3PIm`OxIR9M5kmwSv=)fL8n z-`eNCW}E@aOCF^>jG`b=v86nU6i8aIRBdTQ!T!-ltg&hOP&7?!|Ijv#Hrm#vS7A3NdFB+*-W`$>Tl9GlV+P~W)Q8I-SbY* z-pjJ3Qu&Edy-rVH?6R#SL8OtJO)N4~eK&Yj?gM7JH<*^-yc<38?Ceq93thi%4|N&C zovayGnc3H~mE!afdsaVs?aJF%Iv~-O$FU{Zm^I4CMe0$d|jg=#9fQrT9-lIp`=Sl3W5l8?= zKK>6Ji0;>UWSk4!z#||^zduMIkTm+3=uYZR8lBWVO{4#|R7u~d#52M^Mv4`e^e{0JLK+mu3Suz25Wk>AM>*n<}YGEm4=Yw~lY#@W;^c?w``gQ)ZNF=6S!^ zG^;w6D`argvju9vlIjuF{h4&1vw|9%`^XZz8zr*U`LVeHED zRKOt!V(N`9lB8HH-nMW5{;y?{WDwvTmdn4MAADIV%Lu3t*j)dy;_9KFc&k^bmEO}Q za_H8{=S(1tPNlPw4M9TfeWT3o zG<>^9Z#f?YQU^x^h+Kg@J-+sfULjXJfGd1b?n@Bih1s#PCEK0M5eeW?}?#F8Z1;_6L?lMWWhSa2zN%u?q;7mxo^m#Bd z+l00Tu(-R@*ZO)vmZxrbQ<1b?0D` z1P*>>;wcGi+Ki@7&MY1{aNrm6`8*DoM`BuG|AFR~lYR#x5Zznc{f_AVLh4S8-Azi) z-EVj2ag#nS_t59j4JRcaU_d`4vqC15AtVV&2w0NAvUwCj;iLr8Z%*s#5qa62ug2(G zYb0WXG-A=2>G1pL{;)}t2K;Jc{nNgi!N1-Jz_{gGSv>Ym9{cPMv!#&B)r`;`UGvjl zZ$DatNjQF`(8FfBCYWlapf)#CTaf-~rp>{$JDA#nDHBXXGQbB^PF0o{7=`?QL0dv%l0=hHAu6}^wD4%YEpd{aC05UK!IV~_VEig1xGBP?c zGCD9cEig4YFfeNt_y+(003~!qSaf7zbY(hiZ)9m^c>ppnF*GeOGA%MUR4_C;Ff}?e aHZ3qUIxsLGyqXjM0000a0 literal 0 HcmV?d00001 diff --git a/public/icons/docs/octave/SOURCE b/public/icons/docs/octave/SOURCE new file mode 100644 index 00000000..917586bc --- /dev/null +++ b/public/icons/docs/octave/SOURCE @@ -0,0 +1 @@ +https://www.gnu.org/software/octave/img/octave-logo.svg From 4da5ae7e732b21c8c78aa94a8355cf89a1365117 Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Sat, 17 Aug 2019 00:02:54 +0200 Subject: [PATCH 2/3] octave: finish scraper and filters --- .../templates/pages/about_tmpl.coffee | 5 + assets/javascripts/vendor/prism.js | 4787 +++++++++-------- lib/docs/filters/octave/clean_html.rb | 7 +- lib/docs/filters/octave/entries.rb | 8 +- lib/docs/scrapers/octave.rb | 2 +- 5 files changed, 2592 insertions(+), 2217 deletions(-) diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 892c4284..5238d850 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -516,6 +516,11 @@ credits = [ '2008-2017 NumPy Developers', 'NumPy', 'https://raw.githubusercontent.com/numpy/numpy/master/LICENSE.txt' + ], [ + 'Octave', + '1996-2018 John W. Eaton', + 'Custom', + 'https://octave.org/doc/interpreter/' ], [ 'OpenJDK', '1993-2017, Oracle and/or its affiliates. All rights reserved.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses.
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.', diff --git a/assets/javascripts/vendor/prism.js b/assets/javascripts/vendor/prism.js index 09d6df87..c2cbaadd 100644 --- a/assets/javascripts/vendor/prism.js +++ b/assets/javascripts/vendor/prism.js @@ -1,12 +1,12 @@ -/* PrismJS 1.15.0 -https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+c+bash+cpp+coffeescript+ruby+d+dart+django+elixir+markup-templating+erlang+go+java+json+kotlin+lua+crystal+nginx+nim+perl+php+sql+scss+python+jsx+typescript+rust+yaml */ +/* PrismJS 1.17.1 +https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+c+bash+cpp+coffeescript+ruby+d+dart+markup-templating+elixir+erlang+go+java+php+json+kotlin+crystal+lua+django+matlab+typescript+nginx+nim+perl+sql+scss+python+jsx+rust+yaml */ var _self = (typeof window !== 'undefined') - ? window // if in browser - : ( - (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) - ? self // if in worker - : {} // if in node js - ); + ? window // if in browser + : ( + (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) + ? self // if in worker + : {} // if in node js + ); /** * Prism: Lightweight, robust, elegant syntax highlighting @@ -14,977 +14,1174 @@ var _self = (typeof window !== 'undefined') * @author Lea Verou http://lea.verou.me */ -var Prism = (function(){ +var Prism = (function (_self){ // Private helper vars -var lang = /\blang(?:uage)?-([\w-]+)\b/i; -var uniqueId = 0; - -var _ = _self.Prism = { - manual: _self.Prism && _self.Prism.manual, - disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, - util: { - encode: function (tokens) { - if (tokens instanceof Token) { - return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias); - } else if (_.util.type(tokens) === 'Array') { - return tokens.map(_.util.encode); - } else { - return tokens.replace(/&/g, '&').replace(/ text.length) { - // Something went terribly wrong, ABORT, ABORT! - return; - } - - if (str instanceof Token) { - continue; - } - - if (greedy && i != strarr.length - 1) { - pattern.lastIndex = pos; - var match = pattern.exec(text); - if (!match) { - break; - } - - var from = match.index + (lookbehind ? match[1].length : 0), - to = match.index + match[0].length, - k = i, - p = pos; - - for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) { - p += strarr[k].length; - // Move the index i to the element in strarr that is closest to from - if (from >= p) { - ++i; - pos = p; - } - } - - // If strarr[i] is a Token, then the match starts inside another Token, which is invalid - if (strarr[i] instanceof Token) { - continue; - } - - // Number of tokens to delete and replace with the new match - delNum = k - i; - str = text.slice(pos, p); - match.index -= pos; - } else { - pattern.lastIndex = 0; - - var match = pattern.exec(str), - delNum = 1; - } - - if (!match) { - if (oneshot) { - break; - } - - continue; - } - - if(lookbehind) { - lookbehindLength = match[1] ? match[1].length : 0; - } - - var from = match.index + lookbehindLength, - match = match[0].slice(lookbehindLength), - to = from + match.length, - before = str.slice(0, from), - after = str.slice(to); + var lang = /\blang(?:uage)?-([\w-]+)\b/i; + var uniqueId = 0; + + var _ = { + manual: _self.Prism && _self.Prism.manual, + disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, + util: { + encode: function (tokens) { + if (tokens instanceof Token) { + return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias); + } else if (Array.isArray(tokens)) { + return tokens.map(_.util.encode); + } else { + return tokens.replace(/&/g, '&').replace(/ text.length) { + // Something went terribly wrong, ABORT, ABORT! + return; + } + + if (str instanceof Token) { + continue; + } + + if (greedy && i != strarr.length - 1) { + pattern.lastIndex = pos; + var match = pattern.exec(text); + if (!match) { + break; + } + + var from = match.index + (lookbehind ? match[1].length : 0), + to = match.index + match[0].length, + k = i, + p = pos; + + for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) { + p += strarr[k].length; + // Move the index i to the element in strarr that is closest to from + if (from >= p) { + ++i; + pos = p; + } + } + + // If strarr[i] is a Token, then the match starts inside another Token, which is invalid + if (strarr[i] instanceof Token) { + continue; + } + + // Number of tokens to delete and replace with the new match + delNum = k - i; + str = text.slice(pos, p); + match.index -= pos; + } else { + pattern.lastIndex = 0; + + var match = pattern.exec(str), + delNum = 1; + } + + if (!match) { + if (oneshot) { + break; + } + + continue; + } + + if(lookbehind) { + lookbehindLength = match[1] ? match[1].length : 0; + } + + var from = match.index + lookbehindLength, + match = match[0].slice(lookbehindLength), + to = from + match.length, + before = str.slice(0, from), + after = str.slice(to); + + var args = [i, delNum]; + + if (before) { + ++i; + pos += before.length; + args.push(before); + } + + var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy); + + args.push(wrapped); + + if (after) { + args.push(after); + } + + Array.prototype.splice.apply(strarr, args); + + if (delNum != 1) + _.matchGrammar(text, strarr, grammar, i, pos, true, token); + + if (oneshot) + break; + } + } + } + }, + + tokenize: function(text, grammar) { + var strarr = [text]; + + var rest = grammar.rest; + + if (rest) { + for (var token in rest) { + grammar[token] = rest[token]; + } + + delete grammar.rest; + } + + _.matchGrammar(text, strarr, grammar, 0, 0, false); + + return strarr; + }, + + hooks: { + all: {}, + + add: function (name, callback) { + var hooks = _.hooks.all; + + hooks[name] = hooks[name] || []; + + hooks[name].push(callback); + }, + + run: function (name, env) { + var callbacks = _.hooks.all[name]; + + if (!callbacks || !callbacks.length) { + return; + } - var args = [i, delNum]; - - if (before) { - ++i; - pos += before.length; - args.push(before); - } + for (var i=0, callback; callback = callbacks[i++];) { + callback(env); + } + } + }, - var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy); - - args.push(wrapped); + Token: Token + }; - if (after) { - args.push(after); - } - - Array.prototype.splice.apply(strarr, args); - - if (delNum != 1) - _.matchGrammar(text, strarr, grammar, i, pos, true, token); + _self.Prism = _; - if (oneshot) - break; - } - } - } - }, + function Token(type, content, alias, matchedStr, greedy) { + this.type = type; + this.content = content; + this.alias = alias; + // Copy of the full string this token was created from + this.length = (matchedStr || "").length|0; + this.greedy = !!greedy; + } - tokenize: function(text, grammar, language) { - var strarr = [text]; + Token.stringify = function(o, language) { + if (typeof o == 'string') { + return o; + } - var rest = grammar.rest; + if (Array.isArray(o)) { + return o.map(function(element) { + return Token.stringify(element, language); + }).join(''); + } - if (rest) { - for (var token in rest) { - grammar[token] = rest[token]; - } - - delete grammar.rest; - } - - _.matchGrammar(text, strarr, grammar, 0, 0, false); - - return strarr; - }, - - hooks: { - all: {}, - - add: function (name, callback) { - var hooks = _.hooks.all; - - hooks[name] = hooks[name] || []; - - hooks[name].push(callback); - }, - - run: function (name, env) { - var callbacks = _.hooks.all[name]; - - if (!callbacks || !callbacks.length) { - return; - } - - for (var i=0, callback; callback = callbacks[i++];) { - callback(env); - } - } - } -}; - -var Token = _.Token = function(type, content, alias, matchedStr, greedy) { - this.type = type; - this.content = content; - this.alias = alias; - // Copy of the full string this token was created from - this.length = (matchedStr || "").length|0; - this.greedy = !!greedy; -}; - -Token.stringify = function(o, language, parent) { - if (typeof o == 'string') { - return o; - } - - if (_.util.type(o) === 'Array') { - return o.map(function(element) { - return Token.stringify(element, language, o); - }).join(''); - } - - var env = { - type: o.type, - content: Token.stringify(o.content, language, parent), - tag: 'span', - classes: ['token', o.type], - attributes: {}, - language: language, - parent: parent - }; - - if (o.alias) { - var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias]; - Array.prototype.push.apply(env.classes, aliases); - } - - _.hooks.run('wrap', env); - - var attributes = Object.keys(env.attributes).map(function(name) { - return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; - }).join(' '); - - return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + ''; - -}; + var env = { + type: o.type, + content: Token.stringify(o.content, language), + tag: 'span', + classes: ['token', o.type], + attributes: {}, + language: language + }; -// if (!_self.document) { -// if (!_self.addEventListener) { -// // in Node.js -// return _self.Prism; -// } - -// if (!_.disableWorkerMessageHandler) { -// // In worker -// _self.addEventListener('message', function (evt) { -// var message = JSON.parse(evt.data), -// lang = message.language, -// code = message.code, -// immediateClose = message.immediateClose; - -// _self.postMessage(_.highlight(code, _.languages[lang], lang)); -// if (immediateClose) { -// _self.close(); -// } -// }, false); -// } - -// return _self.Prism; -// } - -// //Get current script and highlight -// var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop(); - -// if (script) { -// _.filename = script.src; - -// if (!_.manual && !script.hasAttribute('data-manual')) { -// if(document.readyState !== "loading") { -// if (window.requestAnimationFrame) { -// window.requestAnimationFrame(_.highlightAll); -// } else { -// window.setTimeout(_.highlightAll, 16); -// } -// } -// else { -// document.addEventListener('DOMContentLoaded', _.highlightAll); -// } -// } -// } - -return _self.Prism; - -})(); + if (o.alias) { + var aliases = Array.isArray(o.alias) ? o.alias : [o.alias]; + Array.prototype.push.apply(env.classes, aliases); + } + + _.hooks.run('wrap', env); + + var attributes = Object.keys(env.attributes).map(function(name) { + return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; + }).join(' '); + + return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + ''; + }; + + if (!_self.document) { + if (!_self.addEventListener) { + // in Node.js + return _; + } + + if (!_.disableWorkerMessageHandler) { + // In worker + _self.addEventListener('message', function (evt) { + var message = JSON.parse(evt.data), + lang = message.language, + code = message.code, + immediateClose = message.immediateClose; + + _self.postMessage(_.highlight(code, _.languages[lang], lang)); + if (immediateClose) { + _self.close(); + } + }, false); + } + + return _; + } + +//Get current script and highlight + var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop(); + + if (script) { + _.filename = script.src; + + if (!_.manual && !script.hasAttribute('data-manual')) { + if(document.readyState !== "loading") { + if (window.requestAnimationFrame) { + window.requestAnimationFrame(_.highlightAll); + } else { + window.setTimeout(_.highlightAll, 16); + } + } + else { + document.addEventListener('DOMContentLoaded', _.highlightAll); + } + } + } + + return _; + +})(_self); if (typeof module !== 'undefined' && module.exports) { - module.exports = Prism; + module.exports = Prism; } // hack for components to work correctly in node.js if (typeof global !== 'undefined') { - global.Prism = Prism; + global.Prism = Prism; } ; Prism.languages.markup = { - 'comment': //, - 'prolog': /<\?[\s\S]+?\?>/, - 'doctype': //i, - 'cdata': //i, - 'tag': { - pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i, - greedy: true, - inside: { - 'tag': { - pattern: /^<\/?[^\s>\/]+/i, - inside: { - 'punctuation': /^<\/?/, - 'namespace': /^[^\s>\/:]+:/ - } - }, - 'attr-value': { - pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i, - inside: { - 'punctuation': [ - /^=/, - { - pattern: /(^|[^\\])["']/, - lookbehind: true - } - ] - } - }, - 'punctuation': /\/?>/, - 'attr-name': { - pattern: /[^\s>\/]+/, - inside: { - 'namespace': /^[^\s>\/:]+:/ - } - } - - } - }, - 'entity': /&#?[\da-z]{1,8};/i + 'comment': //, + 'prolog': /<\?[\s\S]+?\?>/, + 'doctype': //i, + 'cdata': //i, + 'tag': { + pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/i, + greedy: true, + inside: { + 'tag': { + pattern: /^<\/?[^\s>\/]+/i, + inside: { + 'punctuation': /^<\/?/, + 'namespace': /^[^\s>\/:]+:/ + } + }, + 'attr-value': { + pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i, + inside: { + 'punctuation': [ + /^=/, + { + pattern: /^(\s*)["']|["']$/, + lookbehind: true + } + ] + } + }, + 'punctuation': /\/?>/, + 'attr-name': { + pattern: /[^\s>\/]+/, + inside: { + 'namespace': /^[^\s>\/:]+:/ + } + } + + } + }, + 'entity': /&#?[\da-z]{1,8};/i }; Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = - Prism.languages.markup['entity']; + Prism.languages.markup['entity']; // Plugin to make entity title show the real entity, idea by Roman Komarov Prism.hooks.add('wrap', function(env) { - if (env.type === 'entity') { - env.attributes['title'] = env.content.replace(/&/, '&'); - } + if (env.type === 'entity') { + env.attributes['title'] = env.content.replace(/&/, '&'); + } +}); + +Object.defineProperty(Prism.languages.markup.tag, 'addInlined', { + /** + * Adds an inlined language to markup. + * + * An example of an inlined language is CSS with `