md helper exports async by default
See original GitHub issueHi,
I’m using gulp with assemble 0.17.1 and handlebars-helpers 0.7.7 and the md helper isn’t working. We’re loading the helper module as described in the readme and other helpers are working (e.g. markdown, isnt, foreach).
Usage within the templates is as described in the docs:
{{md 'path/to/md/file.md'}}
The error message i get is:
Error: md async helper expects callback to be a function. Did you mean to use md.sync
?
I’m migrating a site from a very old grunt version of assemble and it uses the md helper quite heavily so I’m keen to get this working. I’ve managed to bodge around it for now by overriding the md helper, but it’s a bit of a bodge and it’d be great if it could work without this 😃
`app.helper(‘md’, function (fpath) {
var fs = require('fs'),
path = require('path'),
content = fs.readFileSync(fpath, 'utf8'),
Remarkable = require('remarkable');
var markd = new Remarkable({
html: true,
xhtmlOut: false,
breaks: true
});
return markd.render(content);
});`
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Misleading error that module does not provide export #32137
import { default as md } from '../lib/index.js'; console.log(md);. So your importing the default export (the module.exports object) from .
Read more >await is only valid in async function - Stack Overflow
await can only be used to CALL async functions. await can appear in any kind of function, synchronous or asynchronous. Change the error...
Read more >ES6 async/await | Developer Guide - Nightwatch.js
The async function enables the API commands to return a promise and makes it possible to use the await operator to retrieve the...
Read more >Configuration — Eleventy
module.exports = function(eleventyConfig) { ... Default, html,liquid,ejs,md,hbs,mustache,haml,pug,njk,11ty.js ... Can be sync or async eleventyConfig.
Read more >Creating Objectives | TwilioQuest Extensions
description.md,; example.js,; objective.json,; validator.js, ... module.exports = async function (helper) { let context; try { context = await helper.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jonschlinkert - title updated, hope this is sufficient… change it to something more appropriate if not 😃
Thanks to both you and @doowb for the extremely quick response to this!
hmm, I didn’t realize (or remember) that the
md
helper was exporting the async version by default. In handlebars-helpers we should just wrap it and return the sync function to avoid this issue.@blueowl0708 would you mind creating an issue
on handlebars-helpersregarding exporting the sync function? If not I’ll be back from codemash this weekend and can work on it then, thanksedit: lol I clicked on this from a link on my phone. since the title said “assemble” I thought it was on assemble. anyway, we can change the title of this issue I think. However, it might be better to do what @doowb mentioned, but try also doing: