@jaredwray/fumanchu 1.3.0 → 1.4.1

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 CHANGED
@@ -1,3 +1,4 @@
1
- // index.d.ts
2
1
  import * as Handlebars from 'handlebars';
2
+ import { handlebarHelpers } from './handlebarHelpers';
3
3
  export = Handlebars;
4
+ 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
- const helpers = module.default;
7
- helpers({ handlebars: handlebars });
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('helper-md');
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.3.0",
4
+ "version": "1.4.1",
5
5
  "homepage": "https://github.com/jaredwray/fumanchu",
6
6
  "author": "Jared Wray (me@jaredwray.com)",
7
7
  "keywords": [
@@ -117,9 +117,12 @@
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.1",
121
+ "extend-shallow": "^3.0.2",
120
122
  "falsey": "^1.0.0",
121
123
  "for-in": "^1.0.2",
122
124
  "for-own": "^1.0.0",
125
+ "fs-exists-sync": "^0.1.0",
123
126
  "get-object": "^0.2.0",
124
127
  "get-value": "^3.0.1",
125
128
  "handlebars": "^4.7.8",
@@ -127,7 +130,6 @@
127
130
  "handlebars-utils": "^1.0.6",
128
131
  "has-value": "^2.0.2",
129
132
  "helper-date": "^1.0.1",
130
- "helper-md": "^0.2.2",
131
133
  "highlight.js": "^11.9.0",
132
134
  "html-tag": "^2.0.0",
133
135
  "is-even": "^1.0.0",
@@ -136,18 +138,22 @@
136
138
  "kind-of": "^6.0.3",
137
139
  "lazy-cache": "^2.0.2",
138
140
  "logging-helpers": "^1.0.0",
139
- "micromatch": "^4.0.5",
141
+ "micromatch": "^4.0.7",
142
+ "path": "^0.12.7",
140
143
  "relative": "^3.0.2",
144
+ "remarkable": "^2.0.1",
141
145
  "striptags": "^3.2.0",
142
146
  "to-gfm-code-block": "^0.1.1",
143
147
  "year": "^0.2.1"
144
148
  },
145
149
  "devDependencies": {
146
- "c8": "^9.1.0",
150
+ "c8": "^10.1.2",
147
151
  "chai": "^4.3.10",
152
+ "lodash": "^4.17.21",
148
153
  "mocha": "^10.4.0",
149
- "rimraf": "^5.0.5",
154
+ "rimraf": "^5.0.7",
150
155
  "template-helpers": "^1.0.1",
151
- "templates": "^1.2.9"
156
+ "templates": "^1.2.9",
157
+ "typescript": "^5.5.2"
152
158
  }
153
159
  }