Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: polymer_1.0.4/bower_components/prism-element/prism-highlighter.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: polymer_1.0.4/bower_components/prism-element/prism-highlighter.html
diff --git a/polymer_1.0.4/bower_components/prism-element/prism-highlighter.html b/polymer_1.0.4/bower_components/prism-element/prism-highlighter.html
new file mode 100644
index 0000000000000000000000000000000000000000..dd4be8143cdb095edde9506d3daddae2ff540486
--- /dev/null
+++ b/polymer_1.0.4/bower_components/prism-element/prism-highlighter.html
@@ -0,0 +1,95 @@
+<!--
+@license
+Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
+Code distributed by Google as part of the polymer project is also
+subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
+-->
+
+<link rel="import" href="../polymer/polymer.html">
+
+<link rel="import" href="prism-import.html">
+
+<!--
+Syntax highlighting via [Prism](http://prismjs.com/).
+
+Place a `<prism-highlighter>` in your document, preferably as a direct child of
+`<body>`. It will listen for `syntax-highlight` events on its parent element,
+and annotate the code being provided via that event.
+
+The `syntax-highlight` event's detail is expected to have a `code` property
+containing the source to highlight. The event detail can optionally contain a
+`lang` property, containing a string like `"html"`, `"js"`, etc.
+
+This flow is supported by [`<marked-element>`](https://github.com/PolymerElements/marked-element).
+-->
+<script>
+(function() {
+
+ 'use strict';
+
+ var HIGHLIGHT_EVENT = 'syntax-highlight';
+
+ Polymer({
+
+ is: 'prism-highlighter',
+
+ ready: function() {
+ this._handler = this._highlight.bind(this);
+ },
+
+ attached: function() {
+ (this.parentElement || this.parentNode.host).addEventListener(HIGHLIGHT_EVENT, this._handler);
+ },
+
+ detached: function() {
+ (this.parentElement || this.parentNode.host).removeEventListener(HIGHLIGHT_EVENT, this._handler);
+ },
+
+ /**
+ * Handle the highlighting event, if we can.
+ *
+ * @param {!CustomEvent} event
+ */
+ _highlight: function(event) {
+ if (!event.detail || !event.detail.code) {
+ console.warn('Malformed', HIGHLIGHT_EVENT, 'event:', event.detail);
+ return;
+ }
+
+ var detail = event.detail;
+ detail.code = Prism.highlight(detail.code, this._detectLang(detail.code, detail.lang));
+ },
+
+ /**
+ * Picks a Prism formatter based on the `lang` hint and `code`.
+ *
+ * @param {string} code The source being highlighted.
+ * @param {string=} lang A language hint (e.g. ````LANG`).
+ * @return {!prism.Lang}
+ */
+ _detectLang: function(code, lang) {
+ if (!lang) {
+ // Stupid simple detection if we have no lang, courtesy of:
+ // https://github.com/robdodson/mark-down/blob/ac2eaa/mark-down.html#L93-101
+ return code.match(/^\s*</) ? Prism.languages.markup : Prism.languages.javascript;
+ }
+
+ if (lang === 'js' || lang.substr(0, 2) === 'es') {
+ return Prism.languages.javascript;
+ } else if (lang === 'css') {
+ return Prism.languages.css;
+ } else if (lang === 'c') {
+ return Prism.langauges.clike;
+ } else {
+ // The assumption is that you're mostly documenting HTML when in HTML.
+ return Prism.languages.markup;
+ }
+ },
+
+ });
+
+})();
+</script>

Powered by Google App Engine
This is Rietveld 408576698