JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.angularjs.org/angular-1.0.0rc8.min.js"></script>
<script src="https://raw.github.com/coreyti/showdown/master/compressed/showdown.js"></script>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<div ng-app="myApp" class="container-fluid">
<div class="row-fluid">
<div class="span12">
<p>Text in the textarea is bound to the markdown area on the right.<br />
The markdown directive does not run on the data.<br />
Try entering <code>#title</code> into the textarea.</p>
</div>
<div class="span6">
<textarea ng-model="text"> </textarea>
</div>
<div class="span5 border">
<markdown ng-bind="text">#title
</markdown>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<p>This is a direct copy of the above, but the data binding has been removed.<br />
The markdown directive runs on the dom content, and renders markdown.<br />
The html <code>#title</code> renders as expected in markdown.</p>
</div>
<div class="span6">
<textarea ng-model="content"> </textarea>
</div>
<div class="span5 border">
<markdown>#title
</markdown>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<p>What I need to do is make the bound <code><markdown></code> display formatted markdown as I type. So it looks the same as the unbound <code><markdown></code> does.<br />
</p>
</div>
</div>
</div>
CSS
.border {
border: 2px solid black;
padding: 5px;
}
JavaScript
var myApp = angular.module('myApp', [])
myApp.directive('markdown', function () {
var converter = new Showdown.converter();
return {
restrict: 'E',
require: '?ngModel',
link: function (scope, element, attrs, model) {
var ngModel = attrs['ngModel'],
render = function () {
var html, value;
value = ((ngModel) ? model.$modelValue : element.text()) || '';
html = converter.makeHtml(value);
element.html(html);
};
if (ngModel) {
scope.$watch(ngModel, render);
}
render();
}
}
});