Added highlighting for doctypes & XML prolog, removed the iframed examples and replaced them with XHR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
diff --git a/code.js b/code.js
index 2cd2984..cc2f871 100644
--- a/code.js
+++ b/code.js
@@ -1,55 +1,21 @@
-$$('iframe').forEach(function(iframe) {
- (iframe.onload = function() {
- var doc = iframe.contentDocument,
- pre = $('pre', doc),
- language = /.css$/.test(iframe.src)? 'css' : 'javascript',
- depth = (iframe.getAttribute('src').match(/\//g) || []).length,
- pathPrefix = Array(depth + 1).join('../');
-
- if(!pre) {
- return;
+$$('pre[data-src]').forEach(function(pre) {
+ var src = pre.getAttribute('data-src');
+
+ var language = {
+ 'js': 'javascript',
+ 'css': 'css',
+ 'html': 'markup',
+ 'svg': 'markup'
+ }[(src.match(/\.(\w+)$/) || [,''])[1]]
+
+ pre.className = 'prism language-' + language;
+
+ $u.xhr({
+ url: src,
+ callback: function(xhr) {
+ pre.textContent = xhr.responseText;
+
+ Prism.highlight(pre, true);
}
-
- iframe.onload = null;
-
- pre.className = 'prism language-' + language;
- pre.style.whiteSpace = 'pre';
- pre.style.wordWrap = 'normal';
-
- var height = doc.documentElement.offsetHeight;
- if (height && iframe.offsetHeight > height) {
- iframe.style.height = height + 'px';
- }
-
- var link = {
- tag: 'link',
- properties: {
- rel: 'stylesheet'
- },
- inside: $('head', doc)
- }
-
- link.properties.href = 'style.css';
- $u.element.create(link);
-
- link.properties.href = 'prism.css';
- $u.element.create(link);
-
- link.properties.href = pathPrefix + 'style.css';
- $u.element.create(link);
-
- link.properties.href = pathPrefix + 'prism.css';
- $u.element.create(link);
-
-
- Prism.highlight(pre);
- })();
-});
-
-setTimeout(function(){
- var code = $('code', innerHTML);
- code.innerHTML = document.documentElement.innerHTML
- .replace(/</g, '&lt;')
- .replace(/</g, '<');
- Prism.highlight(code);
-},1000);
+ });
+});
\ No newline at end of file
diff --git a/components/prism-markup.js b/components/prism-markup.js
index 79aa4d2..891cd11 100644
--- a/components/prism-markup.js
+++ b/components/prism-markup.js
@@ -1,5 +1,7 @@
Prism.languages.markup = {
'comment': /<!--[\w\W]*?--(>|>)/g,
+ 'prolog': /<\?.+?\?(>|>)/,
+ 'doctype': /<!DOCTYPE.+?(>|>)/,
'script': null,
'style': null,
'tag': {
@@ -13,7 +15,7 @@ Prism.languages.markup = {
}
},
'attr-value': {
- pattern: /=(('|").*?(\2)|[^\s>]+)/gi,
+ pattern: /=(('|")[\w\W]*?(\2)|[^\s>]+)/gi,
inside: {
'punctuation': /=/g
}
diff --git a/examples.html b/examples.html
index f85d5f3..47acb00 100644
--- a/examples.html
+++ b/examples.html
@@ -31,6 +31,11 @@
<h2>Empty tag</h2>
<pre class="prism"><code class="language-markup"><p></p></code></pre>
+ <h2>Tag that spans multiple lines</h2>
+ <pre class="prism"><code class="language-markup"><p
+>hello!
+</p></code></pre>
+
<h2>Name-attribute pair</h2>
<pre class="prism"><code class="language-markup"><p class="prism"></p></code></pre>
@@ -43,6 +48,14 @@
<h2>Namespaces</h2>
<pre class="prism"><code class="language-markup"><html:p foo:bar="baz" foo:weee></html:p></code></pre>
+
+ <h2>XML prolog</h2>
+ <pre class="prism"><code class="language-markup"><?xml version="1.0" encoding="utf-8"?>
+<svg></svg></code></pre>
+
+ <h2>DOCTYPE</h2>
+ <pre class="prism"><code class="language-markup"><!DOCTYPE html>
+<html></html></code></pre>
</pre>
</section>
diff --git a/index.html b/index.html
index 743898a..1ab9180 100644
--- a/index.html
+++ b/index.html
@@ -64,13 +64,16 @@
<section id="examples">
<h1>Examples</h1>
<p>The Prism source, highlighted with Prism (don’t you just love how meta this is?):</p>
- <iframe src="prism.js"></iframe>
+ <pre data-src="prism.js"></pre>
<p>This page’s CSS code, highlighted with Prism:</p>
- <iframe src="style.css"></iframe>
+ <pre data-src="style.css"></pre>
- <p>And this page’s innerHTML, highlighted with Prism:</p>
- <pre id="innerHTML" class="prism"><code class="language-markup"></code></pre>
+ <p>This page’s HTML, highlighted with Prism:</p>
+ <pre data-src="index.html"></pre>
+
+ <p>This page’s logo (SVG), highlighted with Prism:</p>
+ <pre data-src="logo.svg"></pre>
</section>
<section id="how-to-use">
@@ -97,12 +100,12 @@
<h1>Language definitions</h1>
<p>Every language is defined as a set of tokens, which are expressed as regular expressions. For example, this is the language definition for JavaScript:</p>
- <iframe src="components/prism-javascript.js"></iframe>
+ <pre data-src="components/prism-javascript.js"></pre>
<p>Each token cannot contain other tokens, so their order is significant. Although per the ECMAScript specification, objects are not required to have a specific ordering of their properties, in practice they do in every modern browser.</p>
<p>In some cases, it’s easier to define a language when certain tokens can only be nested inside other tokens. This is allowed by using an object as the token value, instead of a regular expression. This object has a <code>pattern</code> property,
which contains the regular expression that describes the entire token and an <code>inside</code> property that contains the tokens that can be nested inside that token. For example, the tokens for HTML are defined in that way:</p>
- <iframe src="components/prism-html.js"></iframe>
+ <pre data-src="components/prism-markup.js"></pre>
</section>
<section id="api">
diff --git a/logo.svg b/logo.svg
index ded2b92..6a1cac3 100644
--- a/logo.svg
+++ b/logo.svg
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200px" height="170px" viewBox="0 0 200 170">
-<g>
- <path fill="#FFFFFF" d="M55.371,131.506h-6.976v9.12h6.976c1.664,0,2.923-0.405,3.776-1.216c0.853-0.811,1.28-1.925,1.28-3.344
+<g fill="white">
+ <path d="M55.371,131.506h-6.976v9.12h6.976c1.664,0,2.923-0.405,3.776-1.216c0.853-0.811,1.28-1.925,1.28-3.344
s-0.427-2.533-1.28-3.345C58.293,131.911,57.035,131.506,55.371,131.506z"/>
- <path fill="#FFFFFF" d="M84.894,137.906c0.32-0.533,0.48-1.216,0.48-2.048c0-1.345-0.459-2.405-1.376-3.185
+ <path d="M84.894,137.906c0.32-0.533,0.48-1.216,0.48-2.048c0-1.345-0.459-2.405-1.376-3.185
c-0.917-0.778-2.134-1.168-3.648-1.168h-7.456v8.512h7.328C82.483,140.018,84.041,139.314,84.894,137.906z"/>
- <path fill="#FFFFFF" d="M100,0L0,170h200L100,0z M60.859,141.026c-1.312,1.227-3.088,1.84-5.328,1.84h-7.136v7.552h-2.4v-21.184
+ <path d="M100,0L0,170h200L100,0z M60.859,141.026c-1.312,1.227-3.088,1.84-5.328,1.84h-7.136v7.552h-2.4v-21.184
h9.536c2.24,0,4.021,0.618,5.344,1.855c1.301,1.237,1.952,2.892,1.952,4.96C62.827,138.141,62.171,139.8,60.859,141.026z
M85.374,150.418l-5.12-8.128h-7.36v8.128h-2.4v-21.184h10.144c2.155,0,3.883,0.597,5.184,1.792
c1.301,1.173,1.952,2.783,1.952,4.832c0,2.646-1.099,4.447-3.296,5.407c-0.619,0.278-1.227,0.48-1.824,0.608l5.568,8.544H85.374z
diff --git a/prism.css b/prism.css
index e05647b..a5600d8 100644
--- a/prism.css
+++ b/prism.css
@@ -24,7 +24,9 @@ pre.prism {
}
.comment,
-.line-comment {
+.line-comment,
+.prolog,
+.doctype {
color: slategray;
}
diff --git a/prism.js b/prism.js
index 1d18a83..045d7c3 100644
--- a/prism.js
+++ b/prism.js
@@ -219,6 +219,8 @@ Prism.languages.javascript = {
Prism.languages.markup = {
'comment': /<!--[\w\W]*?--(>|>)/g,
+ 'prolog': /<\?.+?\?(>|>)/,
+ 'doctype': /<!DOCTYPE.+?(>|>)/,
'script': null,
'style': null,
'tag': {
@@ -232,7 +234,7 @@ Prism.languages.markup = {
}
},
'attr-value': {
- pattern: /=(('|").*?(\2)|[^\s>]+)/gi,
+ pattern: /=(('|")[\w\W]*?(\2)|[^\s>]+)/gi,
inside: {
'punctuation': /=/g
}
diff --git a/style.css b/style.css
index 890686a..97faf15 100644
--- a/style.css
+++ b/style.css
@@ -1,8 +1,8 @@
-@import url(http://fonts.googleapis.com/css?family=Questrial);
+@import url(http://fonts.googleapis.com/css?family=Questrial);*/
/*
Shared styles
- */
+
h1,
#features li strong {
font: italic 100% Baskerville, Palatino Linotype, Georgia, serif;
@@ -68,6 +68,10 @@ code, pre {
hyphens: none;
}
+pre {
+ max-height: 30em;
+}
+
body > pre:only-child {
padding: 1em;
min-height: 100%;