Last active
April 3, 2017 03:48
-
-
Save koara-local/dd05da1f2eaffba19f32 to your computer and use it in GitHub Desktop.
[Vue.js 1.x] 最低限のMarkdown Editor作成 ( Vue.js + Marked.js + Highlight.js ) ref: http://qiita.com/koara-local/items/ee65916c46a89b055948
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.5/vue.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/solarized_light.min.css"> | |
<style type="text/css"> | |
html, body, #editor { | |
margin: 0; | |
height: 100%; | |
font-family: 'Helvetica Neue', Arial, sans-serif; | |
color: #333; | |
} | |
textarea, #editor div { | |
display: inline-block; | |
width: 49%; | |
height: 100%; | |
vertical-align: top; | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
padding: 0 20px; | |
} | |
textarea { | |
border: none; | |
border-right: 1px solid #ccc; | |
resize: none; | |
outline: none; | |
background-color: #f6f6f6; | |
font-size: 14px; | |
font-family: 'Monaco', courier, monospace; | |
padding: 20px; | |
} | |
</style> | |
<div id="editor"> | |
<textarea v-model="input" debounce="300"></textarea> | |
<div v-html="input | marked"></div> | |
</div> | |
<script> | |
(function() { | |
marked.setOptions({ | |
highlight: function(code, lang) { | |
return hljs.highlightAuto(code, [lang]).value; | |
} | |
}); | |
new Vue({ | |
el: '#editor', | |
data: { | |
input: '# hello' | |
}, | |
filters: { | |
marked: marked | |
} | |
}) | |
}).call(this); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment