GitHub Flavored Markdown Editor
Created
October 16, 2020 18:58
-
-
Save e-gons/fdc3705b744a80ea8f54b7a5ede8bb2c to your computer and use it in GitHub Desktop.
Angular Markdown Editor
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
<body ng-app="app" ng-controller="ctrl"> | |
<div class="left"> | |
<textarea id="txt" ng-model="my_markdown"></textarea> | |
</div> | |
<div class="right"> | |
<div class="markdown-body" marked="my_markdown"></div> | |
</div> | |
</body> |
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
angular.module('app', ['hc.marked']) | |
angular.module('app').config(function(markedProvider) { | |
markedProvider.setOptions({ | |
gfm: true, | |
tables: true, | |
highlight: function(code) { | |
return hljs.highlightAuto(code).value; | |
} | |
}); | |
}) | |
angular.module('app').controller('ctrl', function($scope) { | |
$scope.my_markdown = '# Angular Markdown Editor\n\n> GitHub Flavored Markdown Editor\n\n# Built with\n- **[marked](https://github.com/chjj/marked)** for Parsing Markdown\n- **[angular-marked](https://github.com/Hypercubed/angular-marked)** for easier usage of *marked*\n- **[highlight-js](https://github.com/isagalaev/highlight.js)** for code highlighting\n- **[github-markdown-css](https://github.com/sindresorhus/github-markdown-css)** for beautifying markdown output\n- **[highlight-js css](https://github.com/isagalaev/highlight.js/tree/master/src/styles)** for beautifying code output\n\n# Examples\n* Javascript\n\n```javascript\nfunction() { \n console.log("This is awesome!");\n}\n```\n\n* Bash\n\n```bash\n# step 1\nnpm install\n```\netc..\n\n# The End\n- Enjoy ~\n' | |
// Tab Support for Text-area | |
function enableTab(id) { | |
var el = document.getElementById(id); | |
el.onkeydown = function(e) { | |
if (e.keyCode === 9) { | |
var val = this.value, | |
start = this.selectionStart, | |
end = this.selectionEnd; | |
this.value = val.substring(0, start) + '\t' + val.substring(end); | |
this.selectionStart = this.selectionEnd = start + 1; | |
return false; | |
} | |
}; | |
}; | |
enableTab('txt') | |
}) |
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/angular.js/1.4.3/angular.min.js"></script> | |
<script src="https://cdn.rawgit.com/Hypercubed/angular-marked/master/dist/angular-marked.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.7/highlight.min.js"></script> |
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
.left | |
position: fixed | |
top: 0 | |
left: 0 | |
bottom: 0 | |
width: 50% | |
box-shadow: -10px 2px 6px 10px rgba(0,0,0,0.4) | |
textarea | |
font-family: 'Consolas' | |
background: #F5F5F5 | |
overflow: auto | |
&:focus | |
outline: none | |
resize: none | |
border: none | |
padding: 30px | |
width: 100% | |
height: 100% | |
box-sizing: border-box | |
.right | |
position: fixed | |
top: 0 | |
right: 0 | |
left: 50% | |
bottom: 0 | |
overflow: auto | |
padding: 30px | |
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
<link href="https://cdn.rawgit.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css" rel="stylesheet" /> | |
<link href="https://cdn.rawgit.com/isagalaev/highlight.js/master/src/styles/github.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment