<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Markdown Edit</title>
    <script src="/static/vue.min.js"></script>
    <script src="/static/axios_min.js"></script>
    <script src="/static/showdown.min.js"></script>
</head>

<body>
<div align="center" id="md_view">
    <h1>{{name}} 's Markdown Edit </h1>
    <button><a href="/view" target="_blank"> View</a></button>
    <button><a href="/about" target="_blank"> About</a></button>
    <button><a href="/help" target="_blank"> Help</a></button>
    <button><a href="https://github.com/425776024/easy_leetcode" target="_blank">Github</a></button>
    <button @click="save_func()">Save Markdown</button>
</div>
<h6></h6>
<div id="area">
    <textarea spellcheck="false"  id="md-area" onkeyup=mdSwitch() v-model="code_md_str"></textarea>
    <div id="show-area" class="clearfix"></div>
</div>
<style>
    .markdown-here-wrapper {
        font-size: 16px;
        line-height: 1.8em;
        letter-spacing: 0.1em;
    }

    pre,code {
        font-size: 14px;
        font-family: Roboto, 'Courier New', Consolas, Inconsolata, Courier, monospace;
        margin: auto 5px;
    }
    code {
        white-space: pre-wrap;
        border-radius: 2px;
        display: inline;
    }

    pre {
        font-size: 15px;
        line-height: 1.4em;
        display: block;
         !important;
    }

    pre code {
        white-space: pre;
        overflow: auto;
        border-radius: 3px;
        padding: 1px 1px;
        display: block !important;
    }

    strong,
    b {
        color: #BF360C;
    }


    hr {
        margin: 1.5em auto;
    }

    p {
        margin: 1.5em 5px !important;
    }

    table,
    pre,
    dl,
    blockquote,
    q,
    ul,
    ol {
        margin: 10px 5px;
    }

    ul,
    ol {
        padding-left: 15px;
    }

    li {
        margin: 10px;
    }

    li p {
        margin: 10px 0 !important;
    }

    ul ul,
    ul ol,
    ol ul,
    ol ol {
        margin: 0;
        padding-left: 10px;
    }

    ul {
        list-style-type: circle;
    }

    dl {
        padding: 0;
    }

    dl dt {
        font-size: 1em;
        font-weight: bold;
        font-style: italic;
    }

    dl dd {
        margin: 0 0 10px;
        padding: 0 10px;
    }

    blockquote,
    q {
        border-left: 2px solid #009688;
        padding: 0 10px;
        color: #777;
        quotes: none;
        margin-left: 1em;
    }

    blockquote::before,
    blockquote::after,
    q::before,
    q::after {
        content: none;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        margin: 20px 0 10px;
        padding: 0;
        font-style: bold !important;
        text-align: center !important;
        margin: 1.5em 5px !important;
        padding: 0.5em 1em !important;
    }

    h1 {
        font-size: 24px !important;
    }

    h2 {
        font-size: 20px !important;
        border-bottom: 1px solid #eee !important;
    }

    h3 {
        font-size: 18px;
    }

    h4 {
        font-size: 16px;
    }


    table {
        padding: 0;
        border-collapse: collapse;
        border-spacing: 0;
        font-size: 1em;
        font: inherit;
        border: 0;
        margin: 0 auto;
    }

    tbody {
        margin: 0;
        padding: 0;
        border: 0;
    }

    table tr {
        border: 0;
        border-top: 1px solid #CCC;
        background-color: white;
        margin: 0;
        padding: 0;
    }

    table tr:nth-child(2n) {
        background-color: #F8F8F8;
    }

    table tr th,
    table tr td {
        font-size: 16px;
        border: 1px solid #CCC;
        margin: 0;
        padding: 5px 10px;
    }

    table tr th {
        font-weight: bold;
        color: #eee;
        border: 1px solid #009688;
        background-color: #009688;
    }




</style>
<style>

 button{
            background-color: #F8F8F8;
            height: 40px;
            width: 10%;
}
    #md-area {
        float:left;
            spellcheck:false;
            background-color: #F8F8F8;
            height: 800px;
            width: 45%;
            margin-left: auto;
            margin-right: auto;
            outline: 0;
            border: 1px solid #a0b3d6;
            font-size: 12px;
            line-height: 24px;
            word-wrap: break-word;
            overflow-x: hidden;
            overflow-y: auto;
            border-color: rgba(82, 168, 236, 0.8);
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6);
    }

    #show-area {
        width: 50%;
        float:right;
        min-height: 500px;
        background-color: #FCF6E5;
    }

    .clearfix:before {
        content: "";
        display: table;
    }






</style>
<script>
    function mdSwitch() {
        var mdValue = document.getElementById("md-area").value;
        var converter = new showdown.Converter();
        var html = converter.makeHtml(mdValue);
        document.getElementById("show-area").innerHTML = html;
    }
window.onload=function(){
    var mdValue = {[data['code_md_str']|tojson]};
    document.getElementById("md-area").value = mdValue;
    var converter = new showdown.Converter();
    var html = converter.makeHtml(mdValue);
    document.getElementById("show-area").innerHTML = html;
}

var area = new Vue({
        el: '#area',
        data:{
            code_md_str:{[data['code_md_str']|tojson]},
        }
});

var md_view = new Vue({
        el: '#md_view',
        data:{
            name:{[data['name']|tojson]},
            code_md_str:area.code_md_str,
        },
        methods: {
            save_func:function(){
<!--                console.log(area.code_md_str);-->
                axios.put('/save', {
                    "code_md_str":area.code_md_str,
                    "name":this.name,
                  })
                  .then(function (response) {
                    host = window.location.host;
                    url='http://'+host+'/code/'+response.data['name'];
                    window.location.href = url;
                  })
                  .catch(function (error) {
                    console.log(error);
                  });
            }
        }
});



</script>

</body>

</html>