在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Hypercubed/angular-marked开源软件地址(OpenSource Url):https://github.com/Hypercubed/angular-marked开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):angular-markedAngularJS Markdown using marked. Please note: neither this directive nor marked (by default) implement sanitization. As always, sanitizing is necessary for user-generated content. Install
or
or
Depending on your setup you may need include script tags in your html: <script src="bower_components/marked/lib/marked.js"></script>
<script src="bower_components/angular-marked/dist/angular-marked.js"></script> Usagevar app = angular.module('example-app', ['hc.marked']); Set default options (optional)app.config(['markedProvider', function (markedProvider) {
markedProvider.setOptions({gfm: true});
}]); Example using highlight.js Javascript syntax highlighter (must include highlight.js script). app.config(['markedProvider', function (markedProvider) {
markedProvider.setOptions({
gfm: true,
tables: true,
highlight: function (code, lang) {
if (lang) {
return hljs.highlight(lang, code, true).value;
} else {
return hljs.highlightAuto(code).value;
}
}
});
}]); Override Rendered Markdown LinksExample overriding the way custom markdown links are displayed to open in new windows: app.config(['markedProvider', function (markedProvider) {
markedProvider.setRenderer({
link: function(href, title, text) {
return "<a href='" + href + "'" + (title ? " title='" + title + "'" : '') + " target='_blank'>" + text + "</a>";
}
});
}]); Use as a directive<marked>
# Markdown directive
*It works!*
</marked> Bind the markdown input to a scope variable: <div marked="my_markdown">
</div>
<!-- Uses $scope.my_markdown --> Include a markdown file: <div marked src="'README.md'">
</div>
<!-- Uses markdown content from README.md --> Or a template (great for md that includes code blocks): <script type="text/ng-template" id="tpl.md">
## Markdown
**Code blocks**
This is <b>bold</b>
**Ampersands**
Star Trek & Star Wars
</script>
<div marked src="'tpl.md'"></div>
<!-- Uses markdown content from tpl.md --> Use <script type="text/ng-template" id="tpl.md">
## Markdown
**This will go through $compile and will be effective**
<button ng-click="doClick()"></button>
</script>
<div ng-controller="ClickHandler">
<div marked src="'tpl.md'" compile="true"></div>
</div> .controller('ClickHandler', function() {
this.doClick = function() {
...
};
}) As a serviceapp.controller('myCtrl', ['marked', function (marked) {
$scope.html = marked('#TEST');
}]); TestingInstall npm and bower dependencies: npm install
bower install
npm test Why?I wanted to use AcknowledgmentsBased on angular-markdown-directive by briantford which, in turn, is based on this excellent tutorial by @johnlinquist. LicenseCopyright (c) 2013-2015 Jayson Harshbarger |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论