markdown

Pub

Markdown view generator for Angel.

With this plug-in, you can easily servestatic sites without doing more than writing simple Markdown. Thus, it is a friendlychoice for writing API documentation or other tedious HTML-writing tasks.

Installation

In your pubspec.yaml:

  1. dependencies:
  2. angel_framework: ^1.0.0
  3. angel_markdown: ^1.0.0

Usage

It's very straightforward to configure an Angel server to use Markdown.Keep in mind to use package:file instead of dart:io:

  1. configureServer(Angel app) async {
  2. var fs = LocalFileSystem();
  3. await app.configure(markdown(
  4. // The directory where your views are located.
  5. fs.directory('views'),
  6. ));
  7. }

You can then generate HTML on-the-fly in a request handler.Assuming your view directory contained a file named hello.md, thefollowing would render it as an HTML response:

  1. configureServer(Angel app) async {
  2. app.get('/hello', (res) => res.render('hello'));
  3. }

package:angel_markdown by default searches for files with a .md extension; however,you can easily override this.

Interpolation

angel_markdown can interpolate the values of data from locals before building the Markdown.

For example, with the following template species.md:

  1. # Species: {{species.name}}
  2. The species *{{species.genus.name}} {{species.name}}* is fascinating...

You can render as follows:

  1. requestHandler(ResponseContext res) {
  2. return res.render('species', {
  3. 'species': new Species('sapiens', genius: 'homo')
  4. });
  5. }

To disable interpolation for a single bracket, prefix it with an @, ex: @{{raw | not_interpolated | angular}}.

Templates

Markdown is frequently used to build the content of sites, but not the templates.You might want to wrap the content of pages in a custom template to apply prettyCSS and JS, etc:

  1. configureServer(Angel app) async {
  2. await app.configure(
  3. markdown(
  4. // The directory where your views are located.
  5. fs.directory('views'), template: (content, Map locals) {
  6. return '''<!DOCTYPE html>
  7. <html>
  8. <head>
  9. <title>${locals['title']} - My Site</title>
  10. </head>
  11. <body>
  12. $content
  13. </body>
  14. </html>
  15. ''';
  16. }),
  17. );
  18. }

The template function will have access to whatever values were passed to the renderer,or an empty Map.

Enhancing Markdown

You can pass an extensionSet to add additional features to the Markdown renderer.By default, this plug-in configures it to enable Github-flavored Markdown.