hdoc-tools 0.7.6 → 0.7.7
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/hdoc-stats.js +25 -21
- package/package.json +1 -3
package/hdoc-stats.js
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
const path = require('path');
|
|
9
9
|
const dree = require('dree');
|
|
10
10
|
const html2text = require('html-to-text');
|
|
11
|
-
const { markdownToTxt } = require('markdown-to-txt');
|
|
12
11
|
const wordsCount = require('words-count').default;
|
|
13
12
|
|
|
14
13
|
// Regex to remove Hornbill-specific tags
|
|
@@ -21,32 +20,19 @@
|
|
|
21
20
|
mdFiles: {},
|
|
22
21
|
staticHTMLFiles: {}
|
|
23
22
|
};
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
let markdownFiles = [];
|
|
25
|
+
|
|
26
|
+
// File callback for scan
|
|
25
27
|
const fileCallback = function(element) {
|
|
26
28
|
if (element.extension === 'md' ) {
|
|
27
|
-
|
|
28
|
-
// Read markdown file as string
|
|
29
|
-
const md = fs.readFileSync(element.path, 'utf8');
|
|
30
|
-
|
|
31
|
-
// Strip out standard MD tags
|
|
32
|
-
let text = markdownToTxt(md);
|
|
33
|
-
|
|
34
|
-
// Strip out any Hornbill Docs specific markdown tags
|
|
35
|
-
text = text.replaceAll(hbMDTagRegex, '');
|
|
36
|
-
|
|
37
|
-
// Do the wordcount and add to status
|
|
38
|
-
const wordCount = wordsCount(text);
|
|
39
|
-
stats.totalWordCount += wordCount;
|
|
40
|
-
stats.mdFiles[element.relativePath] = {
|
|
41
|
-
wordCount: wordCount,
|
|
42
|
-
sizeInBytes: element.sizeInBytes
|
|
43
|
-
};
|
|
29
|
+
markdownFiles.push(element);
|
|
44
30
|
stats.totalMDFiles++;
|
|
45
31
|
} else {
|
|
46
32
|
// file must be html
|
|
47
33
|
const mdFilePath = element.path.slice(0, element.path.lastIndexOf('.')) + '.md';
|
|
34
|
+
//Do we have a matching MD file - if not, then word count the HTML
|
|
48
35
|
if (!fs.existsSync(mdFilePath)) {
|
|
49
|
-
//Do we have a matching MD file - if not, then word count the HTML
|
|
50
36
|
stats.totalStaticHTMLFiles++;
|
|
51
37
|
const html = fs.readFileSync(element.path, 'utf8');
|
|
52
38
|
const text = html2text.convert(html, {
|
|
@@ -120,7 +106,25 @@
|
|
|
120
106
|
|
|
121
107
|
// Scan content path directory, send file info to callback for processing
|
|
122
108
|
dree.scan(bookPath, dreeOptions, fileCallback);
|
|
123
|
-
|
|
109
|
+
markdownFiles.forEach(function(element){
|
|
110
|
+
// Load markdown file
|
|
111
|
+
let md_txt = fs.readFileSync(element.path, 'utf8');
|
|
112
|
+
|
|
113
|
+
// Render markdown into HTML
|
|
114
|
+
var html_txt = md.render(md_txt.toString());
|
|
115
|
+
const text = html2text.convert(html_txt, {
|
|
116
|
+
wordwrap: null
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Do the wordcount and add to status
|
|
120
|
+
const wordCount = wordsCount(text);
|
|
121
|
+
stats.totalWordCount += wordCount;
|
|
122
|
+
stats.mdFiles[element.relativePath] = {
|
|
123
|
+
wordCount: wordCount,
|
|
124
|
+
sizeInBytes: element.sizeInBytes
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
|
|
124
128
|
if (verbose) {
|
|
125
129
|
// Output verbose stats
|
|
126
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hdoc-tools",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
|
5
5
|
"main": "hdoc.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,11 +33,9 @@
|
|
|
33
33
|
"highlight.js": "^11.6.0",
|
|
34
34
|
"html-to-text": "^8.2.1",
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
|
-
"lodash": "^4.17.21",
|
|
37
36
|
"markdown-it": "^13.0.1",
|
|
38
37
|
"markdown-it-container": "^3.0.0",
|
|
39
38
|
"markdown-it-front-matter": "^0.2.3",
|
|
40
|
-
"markdown-to-txt": "^2.0.1",
|
|
41
39
|
"multer": "^1.4.5-lts.1",
|
|
42
40
|
"prompt": "^1.3.0",
|
|
43
41
|
"stream": "0.0.2",
|