forked from Juicy/juicy-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjuicy-markdown.html
82 lines (79 loc) · 2.03 KB
/
juicy-markdown.html
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
<!--
Copyright 2014 Smörgåsbord Development.
Update to Polymer 1.0 by carlos araya
version: 1.0.1
-->
<link rel="import" href="../polymer/polymer.html">
<!--
if we're already using bower for everything, why not use it for highlightjs too
Added highlight.js as a bower dependency
-->
<script src="../marked/lib/marked.js"></script>
<script src="../highlightjs/highlight.pack.min.js"></script>
<dom-module id="juicy-markdown">
<!--
Styles are moved outside templates in 1.0
-->
<style>
:host { overflow: auto; }
#preview { height: 100%; width: 100%; }
img { max-width:100%; }
</style>
<template>
<!-- New way to do template if tags -->
<dom-if>
<template is="dom-if" if="{{ghcss}}" restamp>
<link rel="stylesheet" type="text/css" href="https://juicy.github.io/github-markdown-css/github-markdown.css">
</template>
</dom-if>
<link rel="stylesheet" href="../highlightjs/styles/default.css">
<!-- TODO: try to remove this layer -->
<span id="preview" class="markdown-body"></span>
</template>
</dom-module>
<script>
'use strict';
Polymer({
is: 'juicy-markdown',
properties: {
ghcss: {
type: Boolean,
value: false,
notify: true
},
options: {
type: Object,
value: function () {
return {};
}
},
value: {
type: String,
value: '',
notify: true,
observer: 'valueChanged'
}
},
created: function () {
this.options = {
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: true,
pedantic: true,
sanitize: true,
smartLists: true,
smartypants: false,
highlight: function (code) {
return hljs.highlightAuto(code).value;
}
};
},
valueChanged: function (newValue, oldValue) {
this.parseText(newValue);
},
parseText: function (text) {
this.$.preview.innerHTML = marked(text ? text : "", this.options);
}
});
</script>