├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test ├── fixtures ├── a.md └── b.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": false, 4 | "es6": true, 5 | "node": true, 6 | "mocha": true 7 | }, 8 | 9 | "globals": { 10 | "document": false, 11 | "navigator": false, 12 | "window": false 13 | }, 14 | 15 | "rules": { 16 | "accessor-pairs": 2, 17 | "arrow-spacing": [2, { "before": true, "after": true }], 18 | "block-spacing": [2, "always"], 19 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 20 | "comma-dangle": [2, "never"], 21 | "comma-spacing": [2, { "before": false, "after": true }], 22 | "comma-style": [2, "last"], 23 | "constructor-super": 2, 24 | "curly": [2, "multi-line"], 25 | "dot-location": [2, "property"], 26 | "eol-last": 2, 27 | "eqeqeq": [2, "allow-null"], 28 | "generator-star-spacing": [2, { "before": true, "after": true }], 29 | "handle-callback-err": [2, "^(err|error)$" ], 30 | "indent": [2, 2, { "SwitchCase": 1 }], 31 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 32 | "keyword-spacing": [2, { "before": true, "after": true }], 33 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 34 | "new-parens": 2, 35 | "no-array-constructor": 2, 36 | "no-caller": 2, 37 | "no-class-assign": 2, 38 | "no-cond-assign": 2, 39 | "no-const-assign": 2, 40 | "no-control-regex": 2, 41 | "no-debugger": 2, 42 | "no-delete-var": 2, 43 | "no-dupe-args": 2, 44 | "no-dupe-class-members": 2, 45 | "no-dupe-keys": 2, 46 | "no-duplicate-case": 2, 47 | "no-empty-character-class": 2, 48 | "no-eval": 2, 49 | "no-ex-assign": 2, 50 | "no-extend-native": 2, 51 | "no-extra-bind": 2, 52 | "no-extra-boolean-cast": 2, 53 | "no-extra-parens": [2, "functions"], 54 | "no-fallthrough": 2, 55 | "no-floating-decimal": 2, 56 | "no-func-assign": 2, 57 | "no-implied-eval": 2, 58 | "no-inner-declarations": [2, "functions"], 59 | "no-invalid-regexp": 2, 60 | "no-irregular-whitespace": 2, 61 | "no-iterator": 2, 62 | "no-label-var": 2, 63 | "no-labels": 2, 64 | "no-lone-blocks": 2, 65 | "no-mixed-spaces-and-tabs": 2, 66 | "no-multi-spaces": 2, 67 | "no-multi-str": 2, 68 | "no-multiple-empty-lines": [2, { "max": 1 }], 69 | "no-native-reassign": 0, 70 | "no-negated-in-lhs": 2, 71 | "no-new": 2, 72 | "no-new-func": 2, 73 | "no-new-object": 2, 74 | "no-new-require": 2, 75 | "no-new-wrappers": 2, 76 | "no-obj-calls": 2, 77 | "no-octal": 2, 78 | "no-octal-escape": 2, 79 | "no-proto": 0, 80 | "no-redeclare": 2, 81 | "no-regex-spaces": 2, 82 | "no-return-assign": 2, 83 | "no-self-compare": 2, 84 | "no-sequences": 2, 85 | "no-shadow-restricted-names": 2, 86 | "no-spaced-func": 2, 87 | "no-sparse-arrays": 2, 88 | "no-this-before-super": 2, 89 | "no-throw-literal": 2, 90 | "no-trailing-spaces": 0, 91 | "no-undef": 2, 92 | "no-undef-init": 2, 93 | "no-unexpected-multiline": 2, 94 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 95 | "no-unreachable": 2, 96 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 97 | "no-useless-call": 0, 98 | "no-with": 2, 99 | "one-var": [0, { "initialized": "never" }], 100 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 101 | "padded-blocks": [0, "never"], 102 | "quotes": [2, "single", "avoid-escape"], 103 | "radix": 2, 104 | "semi": [2, "always"], 105 | "semi-spacing": [2, { "before": false, "after": true }], 106 | "space-before-blocks": [2, "always"], 107 | "space-before-function-paren": [2, "never"], 108 | "space-in-parens": [2, "never"], 109 | "space-infix-ops": 2, 110 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 111 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 112 | "use-isnan": 2, 113 | "valid-typeof": 2, 114 | "wrap-iife": [2, "any"], 115 | "yoda": [2, "never"] 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | *.* text eol=lf 3 | *.css text eol=lf 4 | *.html text eol=lf 5 | *.js text eol=lf 6 | *.json text eol=lf 7 | *.less text eol=lf 8 | *.md text eol=lf 9 | *.yml text eol=lf 10 | 11 | *.jpg binary 12 | *.gif binary 13 | *.png binary 14 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | package-lock.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '8' 9 | - '7' 10 | - '6' 11 | - '5' 12 | - '4' 13 | - '0.12' 14 | - '0.10' 15 | matrix: 16 | allow_failures: [] 17 | fast_finish: true 18 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## API 2 | 3 | ```js 4 | var markdown = require('helper'); 5 | ``` 6 | 7 | Returns a function that returns the helper, allowing an options object to be passed: 8 | 9 | ```js 10 | var hbs = require('handlebars'); 11 | hbs.registerHelper('markdown', markdown([options])); 12 | ``` 13 | 14 | **Example** 15 | 16 | Pass a custom `highlight` function for syntax highlighting to [Remarkable][], the markdown renderer: 17 | 18 | ```js 19 | var hljs = require('highlight.js'); 20 | var markdown = require('helper-markdown'); 21 | 22 | function highlight(code, lang) { 23 | try { 24 | try { 25 | return hljs.highlight(lang, code).value; 26 | } catch (err) { 27 | if (!/Unknown language/i.test(err.message)) { 28 | throw err; 29 | } 30 | return hljs.highlightAuto(code).value; 31 | } 32 | } catch (err) { 33 | return code; 34 | } 35 | } 36 | 37 | hbs.registerHelper('markdown', markdown({ 38 | highlight: highlight 39 | })); 40 | ``` 41 | 42 | 43 | ## Usage examples 44 | 45 | With Handlebars: 46 | 47 | ```handlebars 48 |
49 | {{#markdown}} 50 | # Heading 51 | 52 | > this is markdown 53 | 54 | foo bar baz 55 | {{/markdown}} 56 |
57 | ``` 58 | 59 | Results in: 60 | 61 | 62 | ```html 63 |

Heading

64 |
65 |

this is markdown

66 |
67 |

foo bar baz

68 | ``` 69 | 70 | ## Register the helper 71 | 72 | > This should work with any engine, here are a few examples 73 | 74 | ### templates 75 | 76 | The `templates` library supports any templates engine supported by consolidate. To register the helper with [templates][]: 77 | 78 | ```js 79 | var templates = require('templates'); 80 | var app = templates(); 81 | 82 | app.helper('markdown', require('helper-markdown')); 83 | ``` 84 | 85 | ### assemble 86 | 87 | To register the helper for use with [assemble][] v0.6.0 and higher: 88 | 89 | ```js 90 | assemble.helper('markdown', require('helper-markdown')); 91 | ``` 92 | 93 | ### verb 94 | 95 | Register the helper for use with [verb][]: 96 | 97 | ```js 98 | var verb = require('verb'); 99 | verb.helper('markdown', require('helper-markdown')); 100 | ``` 101 | 102 | ### handlebars 103 | 104 | To register the helper with [handlebars][]: 105 | 106 | ```js 107 | var handlebars = require('handlebars'); 108 | handlebars.registerHelper('markdown', require('helper-markdown')); 109 | ``` 110 | 111 | ### lodash 112 | 113 | To register the helper with [Lo-Dash][] or [underscore][]: 114 | 115 | ```js 116 | var markdown = require('helper-markdown'); 117 | 118 | // as a mixin 119 | _.mixin({markdown: markdown}); 120 | _.template('<%= _.markdown("# heading") %>', {}); 121 | //=> '

heading

\n' 122 | 123 | // passed on the context 124 | _.template('<%= markdown("# heading") %>', {markdown: markdown}); 125 | //=> '

heading

\n' 126 | 127 | // as an import 128 | var settings = {imports: {markdown: markdown}}; 129 | _.template('<%= markdown("# heading") %>', {}, settings); 130 | //=> '

heading

\n' 131 | ``` 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2017, Jon Schlinkert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # helper-markdown [![NPM version](https://img.shields.io/npm/v/helper-markdown.svg?style=flat)](https://www.npmjs.com/package/helper-markdown) [![NPM monthly downloads](https://img.shields.io/npm/dm/helper-markdown.svg?style=flat)](https://npmjs.org/package/helper-markdown) [![NPM total downloads](https://img.shields.io/npm/dt/helper-markdown.svg?style=flat)](https://npmjs.org/package/helper-markdown) [![Linux Build Status](https://img.shields.io/travis/helpers/helper-markdown.svg?style=flat&label=Travis)](https://travis-ci.org/helpers/helper-markdown) 2 | 3 | > Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions. 4 | 5 | - [Install](#install) 6 | - [API](#api) 7 | - [Usage examples](#usage-examples) 8 | - [Register the helper](#register-the-helper) 9 | * [templates](#templates) 10 | * [assemble](#assemble) 11 | * [verb](#verb) 12 | * [handlebars](#handlebars) 13 | * [lodash](#lodash) 14 | - [About](#about) 15 | 16 | _(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ 17 | 18 | ## Install 19 | 20 | Install with [npm](https://www.npmjs.com/): 21 | 22 | ```sh 23 | $ npm install --save helper-markdown 24 | ``` 25 | 26 | ## API 27 | 28 | ```js 29 | var markdown = require('helper'); 30 | ``` 31 | 32 | Returns a function that returns the helper, allowing an options object to be passed: 33 | 34 | ```js 35 | var hbs = require('handlebars'); 36 | hbs.registerHelper('markdown', markdown([options])); 37 | ``` 38 | 39 | **Example** 40 | 41 | Pass a custom `highlight` function for syntax highlighting to [Remarkable][], the markdown renderer: 42 | 43 | ```js 44 | var hljs = require('highlight.js'); 45 | var markdown = require('helper-markdown'); 46 | 47 | function highlight(code, lang) { 48 | try { 49 | try { 50 | return hljs.highlight(lang, code).value; 51 | } catch (err) { 52 | if (!/Unknown language/i.test(err.message)) { 53 | throw err; 54 | } 55 | return hljs.highlightAuto(code).value; 56 | } 57 | } catch (err) { 58 | return code; 59 | } 60 | } 61 | 62 | hbs.registerHelper('markdown', markdown({ 63 | highlight: highlight 64 | })); 65 | ``` 66 | 67 | ## Usage examples 68 | 69 | With Handlebars: 70 | 71 | ```handlebars 72 |
73 | {{#markdown}} 74 | # Heading 75 | 76 | > this is markdown 77 | 78 | foo bar baz 79 | {{/markdown}} 80 |
81 | ``` 82 | 83 | Results in: 84 | 85 | ```html 86 |

Heading

87 |
88 |

this is markdown

89 |
90 |

foo bar baz

91 | ``` 92 | 93 | ## Register the helper 94 | 95 | > This should work with any engine, here are a few examples 96 | 97 | ### templates 98 | 99 | The `templates` library supports any templates engine supported by consolidate. To register the helper with [templates](https://github.com/jonschlinkert/templates): 100 | 101 | ```js 102 | var templates = require('templates'); 103 | var app = templates(); 104 | 105 | app.helper('markdown', require('helper-markdown')); 106 | ``` 107 | 108 | ### assemble 109 | 110 | To register the helper for use with [assemble](https://github.com/assemble/assemble) v0.6.0 and higher: 111 | 112 | ```js 113 | assemble.helper('markdown', require('helper-markdown')); 114 | ``` 115 | 116 | ### verb 117 | 118 | Register the helper for use with [verb](https://github.com/verbose/verb): 119 | 120 | ```js 121 | var verb = require('verb'); 122 | verb.helper('markdown', require('helper-markdown')); 123 | ``` 124 | 125 | ### handlebars 126 | 127 | To register the helper with [handlebars](http://www.handlebarsjs.com/): 128 | 129 | ```js 130 | var handlebars = require('handlebars'); 131 | handlebars.registerHelper('markdown', require('helper-markdown')); 132 | ``` 133 | 134 | ### lodash 135 | 136 | To register the helper with [Lo-Dash][] or [underscore](http://underscorejs.org): 137 | 138 | ```js 139 | var markdown = require('helper-markdown'); 140 | 141 | // as a mixin 142 | _.mixin({markdown: markdown}); 143 | _.template('<%= _.markdown("# heading") %>', {}); 144 | //=> '

heading

\n' 145 | 146 | // passed on the context 147 | _.template('<%= markdown("# heading") %>', {markdown: markdown}); 148 | //=> '

heading

\n' 149 | 150 | // as an import 151 | var settings = {imports: {markdown: markdown}}; 152 | _.template('<%= markdown("# heading") %>', {}, settings); 153 | //=> '

heading

\n' 154 | ``` 155 | 156 | ## About 157 | 158 | ### Related projects 159 | 160 | * [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") 161 | * [handlebars](https://www.npmjs.com/package/handlebars): Handlebars provides the power necessary to let you build semantic templates effectively with no frustration | [homepage](http://www.handlebarsjs.com/ "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration") 162 | * [lodash](https://www.npmjs.com/package/lodash): Lodash modular utilities. | [homepage](https://lodash.com/ "Lodash modular utilities.") 163 | * [template](https://www.npmjs.com/package/template): Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… [more](https://github.com/jonschlinkert/template) | [homepage](https://github.com/jonschlinkert/template "Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template helpers, middleware, routes, loaders, and lots more. Powers assemble, verb and other node.js apps.") 164 | * [underscore](https://www.npmjs.com/package/underscore): JavaScript's functional programming helper library. | [homepage](http://underscorejs.org "JavaScript's functional programming helper library.") 165 | * [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") 166 | 167 | ### Contributing 168 | 169 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 170 | 171 | ### Contributors 172 | 173 | | **Commits** | **Contributor** | 174 | | --- | --- | 175 | | 14 | [jonschlinkert](https://github.com/jonschlinkert) | 176 | | 5 | [doowb](https://github.com/doowb) | 177 | | 2 | [almeidap](https://github.com/almeidap) | 178 | 179 | ### Building docs 180 | 181 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 182 | 183 | To generate the readme, run the following command: 184 | 185 | ```sh 186 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 187 | ``` 188 | 189 | ### Running tests 190 | 191 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 192 | 193 | ```sh 194 | $ npm install && npm test 195 | ``` 196 | 197 | ### Author 198 | 199 | **Jon Schlinkert** 200 | 201 | * [github/jonschlinkert](https://github.com/jonschlinkert) 202 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 203 | 204 | ### License 205 | 206 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 207 | Released under the [MIT License](LICENSE). 208 | 209 | *** 210 | 211 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 08, 2017._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var hljs = require('highlight.js'); 4 | var utils = require('handlebars-utils'); 5 | var Remarkable = require('remarkable'); 6 | var defaults = { html: true, breaks: true, highlight: highlight }; 7 | 8 | module.exports = function(config) { 9 | if (typeof config === 'string' || utils.isOptions(config)) { 10 | return markdown.apply(defaults, arguments); 11 | } 12 | 13 | function markdown(str, locals, options) { 14 | if (typeof str !== 'string') { 15 | options = locals; 16 | locals = str; 17 | str = true; 18 | } 19 | 20 | if (utils.isOptions(locals)) { 21 | options = locals; 22 | locals = {}; 23 | } 24 | 25 | var ctx = utils.context(this, locals, options); 26 | var opts = utils.options(this, locals, options); 27 | opts = Object.assign({}, defaults, config, opts); 28 | 29 | if (opts.hasOwnProperty('lang')) { 30 | opts.langPrefix = opts.lang; 31 | } 32 | 33 | var md = new Remarkable(opts); 34 | var val = utils.value(str, ctx, options); 35 | return md.render(val); 36 | } 37 | return markdown; 38 | }; 39 | 40 | function highlight(code, lang) { 41 | try { 42 | try { 43 | return hljs.highlight(lang, code).value; 44 | } catch (err) { 45 | if (!/Unknown language/i.test(err.message)) { 46 | throw err; 47 | } 48 | return hljs.highlightAuto(code).value; 49 | } 50 | } catch (err) { 51 | return code; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helper-markdown", 3 | "description": "Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/helpers/helper-markdown", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "contributors": [ 8 | "Brian Woodward (https://twitter.com/doowb)", 9 | "Jon Schlinkert (http://twitter.com/jonschlinkert)", 10 | "Pedro De almeida (www.almeida.ch)" 11 | ], 12 | "repository": "helpers/helper-markdown", 13 | "bugs": { 14 | "url": "https://github.com/helpers/helper-markdown/issues" 15 | }, 16 | "license": "MIT", 17 | "files": [ 18 | "index.js" 19 | ], 20 | "main": "index.js", 21 | "engines": { 22 | "node": ">=0.10.0" 23 | }, 24 | "scripts": { 25 | "test": "mocha" 26 | }, 27 | "dependencies": { 28 | "handlebars-utils": "^1.0.2", 29 | "highlight.js": "^9.12.0", 30 | "remarkable": "^1.7.1" 31 | }, 32 | "devDependencies": { 33 | "gulp-format-md": "^1.0.0", 34 | "handlebars": "^4.0.10", 35 | "lodash": "^4.17.4", 36 | "mocha": "^3.4.2" 37 | }, 38 | "keywords": [ 39 | "block", 40 | "compile", 41 | "engine", 42 | "expression", 43 | "function", 44 | "handlebars", 45 | "helper", 46 | "helpers", 47 | "lodash", 48 | "markdown", 49 | "md", 50 | "remarkable", 51 | "render", 52 | "template", 53 | "templates" 54 | ], 55 | "verb": { 56 | "toc": true, 57 | "layout": "default", 58 | "tasks": [ 59 | "readme" 60 | ], 61 | "plugins": [ 62 | "gulp-format-md" 63 | ], 64 | "related": { 65 | "list": [ 66 | "assemble", 67 | "handlebars", 68 | "lodash", 69 | "template", 70 | "underscore", 71 | "verb" 72 | ] 73 | }, 74 | "reflinks": [ 75 | "assemble", 76 | "handlebars", 77 | "templates", 78 | "underscore", 79 | "verb" 80 | ], 81 | "lint": { 82 | "reflinks": true 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test/fixtures/a.md: -------------------------------------------------------------------------------- 1 | # AAA 2 | 3 | > this is aaa -------------------------------------------------------------------------------- /test/fixtures/b.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helpers/helper-markdown/ae8a83ff7a6c16335321d3dc5a93ca0aa7296f06/test/fixtures/b.md -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var _ = require('lodash'); 5 | var assert = require('assert'); 6 | var handlebars = require('handlebars'); 7 | var markdown = require('..'); 8 | 9 | describe('helper-markdown', function() { 10 | describe('main export', function() { 11 | it('should render markdown:', function() { 12 | assert.equal(markdown('# heading'), '

heading

\n'); 13 | }); 14 | 15 | it('should highlight code blocks', function() { 16 | var html = markdown('```js\nvar foo = "bar";\n```\n', {}); 17 | assert.equal(html, '
var foo = "bar";\n
\n'); 18 | }); 19 | 20 | it('should pass options to remarkable', function() { 21 | var a = markdown('abc https://github.com/jonschlinkert/remarkable xyz', {linkify: true}); 22 | assert.equal(a, '

abc https://github.com/jonschlinkert/remarkable xyz

\n'); 23 | 24 | var b = markdown('abc https://github.com/jonschlinkert/remarkable xyz', {linkify: false}); 25 | assert.equal(b, '

abc https://github.com/jonschlinkert/remarkable xyz

\n'); 26 | }); 27 | 28 | it('should pass options to highlight.js:', function() { 29 | var html = markdown('```js\nvar foo = "bar";\n```\n', {langPrefix: 'language-'}); 30 | assert.equal(html, '
var foo = "bar";\n
\n'); 31 | }); 32 | }); 33 | 34 | describe('handlebars:', function() { 35 | it('should work as a handlebars helper:', function() { 36 | handlebars.registerHelper('markdown', markdown({})); 37 | assert.equal(handlebars.compile('{{#markdown}}# heading{{/markdown}}')(), '

heading

\n'); 38 | }); 39 | 40 | it('should pass hash options to remarkable:', function() { 41 | handlebars.registerHelper('markdown', markdown({})); 42 | 43 | // `linkify: true` 44 | var a = handlebars.compile('{{#markdown linkify=true}}abc https://github.com/jonschlinkert/remarkable xyz{{/markdown}}')(); 45 | assert.equal(a, '

abc https://github.com/jonschlinkert/remarkable xyz

\n'); 46 | 47 | // `linkify: false` 48 | var b = handlebars.compile('{{#markdown linkify=false}}abc https://github.com/jonschlinkert/remarkable xyz{{/markdown}}')(); 49 | assert.equal(b, '

abc https://github.com/jonschlinkert/remarkable xyz

\n'); 50 | }); 51 | 52 | it('should pass hash options to highlight.js:', function() { 53 | handlebars.registerHelper('markdown', markdown({})); 54 | 55 | // `langPrefix = language-` 56 | var a = handlebars.compile('{{#markdown}}```js\nvar foo = "bar";\n```\n{{/markdown}}')(); 57 | assert.equal(a, '
var foo = "bar";\n
\n'); 58 | 59 | // `langPrefix = language-` 60 | var b = handlebars.compile('{{#markdown langPrefix="language-"}}```js\nvar foo = "bar";\n```\n{{/markdown}}')(); 61 | assert.equal(b, '
var foo = "bar";\n
\n'); 62 | }); 63 | }); 64 | 65 | describe('lodash:', function() { 66 | it('should work as a lodash mixin:', function() { 67 | _.mixin({markdown: markdown}); 68 | assert.equal(_.template('<%= _.markdown("# heading") %>')({}), '

heading

\n'); 69 | }); 70 | 71 | it('should pass options to remarkable:', function() { 72 | _.mixin({markdown: markdown({})}); 73 | var a = _.template('<%= _.markdown("foo\\n```js\\nvar foo = {};\\n```\\nbar") %>')({}); 74 | assert.equal(a, '

foo

\n
var foo = {};\n
\n

bar

\n'); 75 | 76 | var b = _.template('<%= _.markdown("foo\\n```js\\nvar foo = {};\\n```\\nbar", {langPrefix: \'language-\'}) %>')({}); 77 | assert.equal(b, '

foo

\n
var foo = {};\n
\n

bar

\n'); 78 | }); 79 | 80 | it('should work when passed to lodash as a string:', function() { 81 | assert.equal(_.template('<%= markdown("# heading") %>')({markdown: markdown}), '

heading

\n'); 82 | }); 83 | 84 | it('should work as a lodash import:', function() { 85 | var settings = {imports: {markdown: markdown}}; 86 | assert.equal(_.template('<%= markdown("# heading") %>', settings)({}), '

heading

\n'); 87 | }); 88 | }); 89 | }); 90 | --------------------------------------------------------------------------------