Created
April 4, 2017 17:35
-
-
Save pmacaluso3/0796c2fcab46091147c1c62bb49bcdc9 to your computer and use it in GitHub Desktop.
Markdown Widget Demo
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
| window.MarkdownWidget = {} | |
| $(document).ready(function() { | |
| $('#user_input').on('keyup', function() { | |
| var inputText = window.MarkdownWidget.viewObject.grabUserInput('#user_input') | |
| var transformedText = window.MarkdownWidget.transform(inputText) | |
| window.MarkdownWidget.viewObject.render(transformedText, '#output') | |
| }) | |
| }) |
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
| .bold { | |
| font-weight: bold; | |
| } | |
| .italic { | |
| font-style: italic; | |
| } |
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> | |
| <head> | |
| <title>Markdown Demo</title> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
| <script type="text/javascript" src="application.js"></script> | |
| <script type="text/javascript" src="model.js"></script> | |
| <script type="text/javascript" src="view.js"></script> | |
| <link rel="stylesheet" type="text/css" href="demo.css"> | |
| </head> | |
| <body> | |
| <h1>Markdown Demo</h1> | |
| <textarea id="user_input"></textarea> | |
| <div id="output"></div> | |
| </body> | |
| </html> |
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
| window.MarkdownWidget.transform = function(inputText) { | |
| return inputText | |
| .replace(/\*(.*)\*/, "<span class='bold'>$1</span>") | |
| .replace(/_(.*)_/, "<span class='italic'>$1</span>") | |
| } |
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
| window.MarkdownWidget.viewObject = { | |
| render: function(text, selector) { | |
| $(selector).html(text) | |
| }, | |
| grabUserInput: function(selector) { | |
| var $inputField = $(selector) | |
| return $inputField.val() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment