@jaredwray/fumanchu 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +5 -3
- package/index.mjs +8 -3
- package/lib/markdown.js +2 -2
- package/lib/md.js +119 -0
- package/package.json +9 -6
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import HandlebarsLib from 'handlebars';
|
|
2
|
+
declare const handlebars: typeof HandlebarsLib;
|
|
3
|
+
declare let handlebarHelpers: any;
|
|
4
|
+
export default handlebars;
|
|
5
|
+
export { handlebarHelpers };
|
package/index.mjs
CHANGED
|
@@ -2,10 +2,15 @@ import HandlebarsLib from 'handlebars';
|
|
|
2
2
|
|
|
3
3
|
const handlebars = HandlebarsLib.create();
|
|
4
4
|
|
|
5
|
+
// Variable to hold the helpers function
|
|
6
|
+
let handlebarHelpers;
|
|
7
|
+
|
|
5
8
|
import('./helpers.js').then((module) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
handlebarHelpers = module.default;
|
|
10
|
+
handlebarHelpers({ handlebars: handlebars });
|
|
11
|
+
});
|
|
9
12
|
|
|
10
13
|
// Exporting for ESM
|
|
11
14
|
export default handlebars;
|
|
15
|
+
export { handlebarHelpers };
|
|
16
|
+
|
package/lib/markdown.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const hljs = require('highlight.js');
|
|
3
3
|
const utils = require('handlebars-utils');
|
|
4
|
-
const Remarkable = require('remarkable');
|
|
4
|
+
const {Remarkable} = require('remarkable');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Expose markdown `helpers` (for performance we're using getters so
|
|
@@ -55,7 +55,7 @@ Object.defineProperty(helpers, 'markdown', {
|
|
|
55
55
|
* @api public
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
|
-
helpers.md = require('
|
|
58
|
+
helpers.md = require('./md.js');
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
helpers.helpersForMarkdown = function(config) {
|
package/lib/md.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* helper-markdown <https://github.com/jonschlinkert/helper-markdown>
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2014 Jon Schlinkert, contributors.
|
|
5
|
+
* Licensed under the MIT license.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var path = require('path');
|
|
12
|
+
const { Remarkable } = require('remarkable');
|
|
13
|
+
var extend = require('extend-shallow');
|
|
14
|
+
var exists = require('fs-exists-sync');
|
|
15
|
+
var ent = require('ent');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Expose `md` helper
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var helper = module.exports = function(name, options, cb) {
|
|
22
|
+
if (typeof options === 'function') {
|
|
23
|
+
cb = options;
|
|
24
|
+
options = {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof cb !== 'function') {
|
|
28
|
+
return helper.sync.apply(this, arguments);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* c8 ignore next 3 */
|
|
32
|
+
if (typeof this === 'undefined' || typeof this.app === 'undefined') {
|
|
33
|
+
throw new Error('md async helper expects `app` to be exposed on the context');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var opts = extend({cwd: process.cwd()}, this.options, options);
|
|
37
|
+
opts = extend({}, opts, opts.hash);
|
|
38
|
+
var md = markdown(opts);
|
|
39
|
+
|
|
40
|
+
var filepath = path.resolve(opts.cwd, name);
|
|
41
|
+
var view;
|
|
42
|
+
var str = '';
|
|
43
|
+
|
|
44
|
+
if (exists(filepath)) {
|
|
45
|
+
// create a collection to ensure middleware is consistent
|
|
46
|
+
this.app.create('mdfiles');
|
|
47
|
+
str = fs.readFileSync(filepath, 'utf8');
|
|
48
|
+
view = this.app.mdfile(filepath, {path: filepath, content: str});
|
|
49
|
+
} else {
|
|
50
|
+
view = this.app.find(name);
|
|
51
|
+
}
|
|
52
|
+
/* c8 ignore next 4 */
|
|
53
|
+
if (typeof view === 'undefined') {
|
|
54
|
+
cb(null, '');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
view.content = ent.decode(md.render(view.content));
|
|
59
|
+
this.app.render(view, this.context, function(err, res) {
|
|
60
|
+
if (err) return cb(err);
|
|
61
|
+
cb(null, res.content);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
helper.sync = function(name, options) {
|
|
66
|
+
var ctx = this || {};
|
|
67
|
+
var app = ctx.app || {};
|
|
68
|
+
|
|
69
|
+
var opts = extend({cwd: process.cwd()}, ctx.options, options);
|
|
70
|
+
opts = extend({}, opts, opts.hash);
|
|
71
|
+
var md = markdown(opts);
|
|
72
|
+
|
|
73
|
+
var filepath = path.resolve(opts.cwd, name);
|
|
74
|
+
var view;
|
|
75
|
+
var html = '';
|
|
76
|
+
var str = '';
|
|
77
|
+
|
|
78
|
+
if (exists(filepath)) {
|
|
79
|
+
str = fs.readFileSync(filepath, 'utf8');
|
|
80
|
+
html = ent.decode(md.render(str));
|
|
81
|
+
} else if (app.views) {
|
|
82
|
+
view = app.find(name);
|
|
83
|
+
if (view) {
|
|
84
|
+
html = view.content = ent.decode(md.render(view.content));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (view && typeof view.compile === 'function') {
|
|
89
|
+
view.compile(opts);
|
|
90
|
+
var data = ctx.cache ? ctx.cache.data : {};
|
|
91
|
+
ctx = extend({}, data, view.data);
|
|
92
|
+
return view.fn(ctx);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof this.compile === 'function') {
|
|
96
|
+
var fn = this.compile(html);
|
|
97
|
+
return fn(this);
|
|
98
|
+
}
|
|
99
|
+
return html;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Shared settings for remarkable
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} `options`
|
|
106
|
+
* @return {Object}
|
|
107
|
+
* @api private
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
function markdown(options) {
|
|
111
|
+
let optsConfig = options || {};
|
|
112
|
+
optsConfig.breaks = true;
|
|
113
|
+
optsConfig.html = true;
|
|
114
|
+
optsConfig.langPrefix = 'lang-';
|
|
115
|
+
optsConfig.typographer = false;
|
|
116
|
+
optsConfig.xhtmlOut = false;
|
|
117
|
+
const md = new Remarkable(optsConfig);
|
|
118
|
+
return md;
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaredwray/fumanchu",
|
|
3
3
|
"description": "Handlebars + Helpers = Fumanchu",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"homepage": "https://github.com/jaredwray/fumanchu",
|
|
6
6
|
"author": "Jared Wray (me@jaredwray.com)",
|
|
7
7
|
"keywords": [
|
|
@@ -117,6 +117,7 @@
|
|
|
117
117
|
"array-sort": "^1.0.0",
|
|
118
118
|
"create-frame": "^1.0.0",
|
|
119
119
|
"define-property": "^2.0.2",
|
|
120
|
+
"ent": "^2.2.0",
|
|
120
121
|
"falsey": "^1.0.0",
|
|
121
122
|
"for-in": "^1.0.2",
|
|
122
123
|
"for-own": "^1.0.0",
|
|
@@ -127,7 +128,6 @@
|
|
|
127
128
|
"handlebars-utils": "^1.0.6",
|
|
128
129
|
"has-value": "^2.0.2",
|
|
129
130
|
"helper-date": "^1.0.1",
|
|
130
|
-
"helper-md": "^0.2.2",
|
|
131
131
|
"highlight.js": "^11.9.0",
|
|
132
132
|
"html-tag": "^2.0.0",
|
|
133
133
|
"is-even": "^1.0.0",
|
|
@@ -136,18 +136,21 @@
|
|
|
136
136
|
"kind-of": "^6.0.3",
|
|
137
137
|
"lazy-cache": "^2.0.2",
|
|
138
138
|
"logging-helpers": "^1.0.0",
|
|
139
|
-
"micromatch": "^4.0.
|
|
139
|
+
"micromatch": "^4.0.7",
|
|
140
140
|
"relative": "^3.0.2",
|
|
141
|
+
"remarkable": "^2.0.1",
|
|
141
142
|
"striptags": "^3.2.0",
|
|
142
143
|
"to-gfm-code-block": "^0.1.1",
|
|
143
144
|
"year": "^0.2.1"
|
|
144
145
|
},
|
|
145
146
|
"devDependencies": {
|
|
146
|
-
"c8": "^
|
|
147
|
+
"c8": "^10.1.2",
|
|
147
148
|
"chai": "^4.3.10",
|
|
149
|
+
"lodash": "^4.17.21",
|
|
148
150
|
"mocha": "^10.4.0",
|
|
149
|
-
"rimraf": "^5.0.
|
|
151
|
+
"rimraf": "^5.0.7",
|
|
150
152
|
"template-helpers": "^1.0.1",
|
|
151
|
-
"templates": "^1.2.9"
|
|
153
|
+
"templates": "^1.2.9",
|
|
154
|
+
"typescript": "^5.5.2"
|
|
152
155
|
}
|
|
153
156
|
}
|