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

Unified Diff: polymer_1.0.4/bower_components/marked-element/marked-element.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/marked-element/marked-element.html
diff --git a/polymer_1.0.4/bower_components/marked-element/marked-element.html b/polymer_1.0.4/bower_components/marked-element/marked-element.html
new file mode 100644
index 0000000000000000000000000000000000000000..3184eba568823229bdd6387aba459f7d8f61e430
--- /dev/null
+++ b/polymer_1.0.4/bower_components/marked-element/marked-element.html
@@ -0,0 +1,145 @@
+<!--
+@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="marked-import.html">
+
+<!--
+Element wrapper for the [marked](http://marked.org/) library.
+
+`<marked-element>` accepts Markdown source either via its `markdown` attribute:
+
+ <marked-element markdown="`Markdown` is _awesome_!"></marked-element>
+
+Or, you can provide it via a `<script type="text/markdown">` element child:
+
+ <marked-element>
+ <script type="text/markdown">
+ Check out my markdown!
+
+ We can even embed elements without fear of the HTML parser mucking up their
+ textual representation:
+
+ ```html
+ <awesome-sauce>
+ <div>Oops, I'm about to forget to close this div.
+ </awesome-sauce>
+ ```
+ </script>
+ </marked-element>
+
+Note that the `<script type="text/markdown">` approach is _static_. Changes to
+the script content will _not_ update the rendered markdown!
+@element marked-element
+@group Molecules
+@hero hero.svg
+@demo demo/index.html
+-->
+<dom-module id="marked-element">
+
+ <template>
+ <div id="content"></div>
+ </template>
+
+</dom-module>
+
+<script>
+
+ 'use strict';
+
+ Polymer({
+
+ is: 'marked-element',
+
+ properties: {
+
+ /** The markdown source that should be rendered by this element. */
+ markdown: {
+ observer: 'render',
+ type: String,
+ value: null
+ }
+
+ },
+
+ ready: function() {
+ if (!this.markdown) {
+ // Use the Markdown from the first `<script>` descendant whose MIME type starts with
+ // "text/markdown". Script elements beyond the first are ignored.
+ var markdownElement = Polymer.dom(this).querySelector('[type^="text/markdown"]');
+ if (markdownElement != null) {
+ this.markdown = this._unindent(markdownElement.textContent);
+ }
+ }
+ },
+
+ /**
+ * Renders `markdown` to HTML when the element is attached.
+ *
+ * This serves a dual purpose:
+ *
+ * * Prevents unnecessary work (no need to render when not visible).
+ *
+ * * `attached` fires top-down, so we can give ancestors a chance to
+ * register listeners for the `syntax-highlight` event _before_ we render
+ * any markdown.
+ *
+ */
+ attached: function() {
+ this._attached = true;
+ this.render();
+ },
+
+ detached: function() {
+ this._attached = false;
+ },
+
+ /**
+ * Renders `markdown` into this element's DOM.
+ *
+ * This is automatically called whenever the `markdown` property is changed.
+ *
+ * The only case where you should be calling this is if you are providing
+ * markdown via `<script type="text/markdown">` after this element has been
+ * constructed (or updating that markdown).
+ */
+ render: function() {
+ if (!this._attached) return;
+ if (!this.markdown) {
+ this.$.content.innerHTML = '';
+ return;
+ }
+
+ this.$.content.innerHTML = marked(this.markdown, {
+ highlight: this._highlight.bind(this),
+ });
+ },
+
+ _highlight: function(code, lang) {
+ var event = this.fire('syntax-highlight', {code: code, lang: lang});
+ return event.detail.code || code;
+ },
+
+ _unindent: function(text) {
+ if (!text) return text;
+ var lines = text.replace(/\t/g, ' ').split('\n');
+ var indent = lines.reduce(function(prev, line) {
+ if (/^\s*$/.test(line)) return prev; // Completely ignore blank lines.
+
+ var lineIndent = line.match(/^(\s*)/)[0].length;
+ if (prev === null) return lineIndent;
+ return lineIndent < prev ? lineIndent : prev;
+ }, null);
+
+ return lines.map(function(l) { return l.substr(indent); }).join('\n');
+ },
+
+ });
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698