Free Code Camp: simple markdown editor challenge.
Created
August 20, 2022 12:02
-
-
Save fernaoguerra/6d299d5bb46989ed129008cebeefb99a to your computer and use it in GitHub Desktop.
Simple Markdown Editor
This file contains hidden or 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
| <!--[if lt IE 8]> | |
| <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | |
| <![endif]--> | |
| <!-- Add your site or application content here --> | |
| <div class="container fullheight"> | |
| <h1>Markdown Editor</h1> | |
| <div class="row"> | |
| <div class="six columns"> | |
| <textarea id="smde" class="CodeMirror"></textarea> | |
| </div> | |
| <div class="six columns reader" id="write_here"> | |
| </div> | |
| </div> | |
| </div> |
This file contains hidden or 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
| var sample = [ | |
| "### Instructions", | |
| "Enter text in the area on the left. For more info, click the ? (help) icon in the menu." | |
| ] | |
| var simplemde = new SimpleMDE({element: $("#smde")[0], toolbar: ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "|", "guide"]}); | |
| $(document).ready(function() { | |
| writeSample(); | |
| simplemde.codemirror.on("change", function(){ | |
| var renderedHTML = simplemde.options.previewRender(simplemde.value()); | |
| $("#write_here").html(renderedHTML); | |
| $("#write_here").css("height", $(".row").height() + "px" ); | |
| }); | |
| }); | |
| function writeSample() { | |
| var s = ""; | |
| s = getSample(); | |
| simplemde.value(s); | |
| var renderedHTML = simplemde.options.previewRender(simplemde.value()); | |
| $("#write_here").html(renderedHTML); | |
| $("#write_here").css("height", $(".row").height() + "px" ); | |
| } | |
| function getSample() { | |
| var s = ""; | |
| $.each(sample, function( index, value ) { | |
| //alert( index + ": " + value ); | |
| s = s + value + "\n\r"; | |
| }); | |
| return s; | |
| } |
This file contains hidden or 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/jquery/3.1.1/jquery.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/simplemde/1.11.2/simplemde.min.js"></script> |
This file contains hidden or 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
| html, body { | |
| height: 100vh; | |
| } | |
| .fullheight { | |
| height: 100%; | |
| max-height: 100vh; | |
| } | |
| .CodeMirror { | |
| height: 300px; | |
| overflow-y: auto; | |
| border: 1px solid #bbb; | |
| border-radius: 5px; | |
| padding-top: 2px; | |
| padding-bottom: 2px; | |
| padding-left: 4px; | |
| padding-right: 4px; | |
| } | |
| .editor { | |
| height: 100%; | |
| } |
This file contains hidden or 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
| <link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.22.2/codemirror.min.css" rel="stylesheet" /> | |
| <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet" /> | |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/simplemde/1.11.2/simplemde.min.css" rel="stylesheet" /> | |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment