Skip to content

jlguenego/angular-markdown-include

Repository files navigation

angular-markdown-include

Angular module for including markdown and syntax highlighting. This module brings the directive md-include.

##Syntax

<script src="path/to/jquery.min.js"></script>
<script src="path/to/angular.min.js"></script>
<script src="path/to/angular-markdown-include.min.js"></script>

<md-include src="'{mardown file url}'" [autoscroll] parser="{javascript function}" [script="{path to javascript file}"]></md-include>

Include the module angularMarkdownInclude in your angular app module.

var app = angular.module('app', ['angularMarkdownInclude']);

Attributes:

  • src: URL of the markdown file. Be careful, it is surrounded by quotes.
  • parser: Javascript function taking one argument (the markdown file content) and returning a string (the html content).
  • autoscroll: (optional) Like the autoscroll of Angular ng-include.
  • script: (optional) Specify a script that will be appended at the end of the HTML content and evaluated just after loading.

##Example

Here is an example using Marked and HighlightJS.

<md-include src="'markdown/data.md'" autoscroll parser="myParser"></md-include>

<script>
function myParser(str) {
	var result = marked(str);
	var div = $('<div/>').html(result);

	div.find('pre').each(function(i, block) {
		var code = $(this).find('code');
		var lang = code.attr('class');
		console.log('lang=', lang);
		console.log('$(this)=', $(this));
		hljs.highlightBlock(code.get(0));
	});
	return div.html();
}
</script>

See the test directory for two real use cases.

  • Showdown and Prettify
  • Marked and HighlightJS

##Installation

###Simple method

Just download the angular-mardown-include.min.js.

###Bower

Bower installs the minimum to run the library, not the test files.

bower install angular-mardown-include

##Build

If you clone the Git repository, then you need npm to run the build.

npm install
grunt

##Notes

Javascript library for markdown:

Javascript library for syntax highlighting:

##Issues

You can submit your issues on the Github system.

##License

MIT

##Authors

  • Yannis THOMIAS
  • Jean-Louis GUÉNÉGO

About

Angular module for markdown and syntax highlighting.

Resources

Stars

Watchers

Forks

Packages

No packages published