w-md2docx 1.0.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.
Files changed (69) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +83 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +16 -0
  9. package/dist/w-md2docx.umd.js +7 -0
  10. package/dist/w-md2docx.umd.js.map +1 -0
  11. package/docs/ApiClient.mjs.html +539 -0
  12. package/docs/ApiServer.mjs.html +516 -0
  13. package/docs/WMd2docx.mjs.html +101 -0
  14. package/docs/cvMdTo.mjs.html +288 -0
  15. package/docs/cvMdToDocx.mjs.html +243 -0
  16. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  22. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  23. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  32. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  33. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  34. package/docs/global.html +5453 -0
  35. package/docs/index.html +84 -0
  36. package/docs/scripts/collapse.js +39 -0
  37. package/docs/scripts/commonNav.js +28 -0
  38. package/docs/scripts/linenumber.js +25 -0
  39. package/docs/scripts/nav.js +12 -0
  40. package/docs/scripts/polyfill.js +4 -0
  41. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  42. package/docs/scripts/prettify/lang-css.js +2 -0
  43. package/docs/scripts/prettify/prettify.js +28 -0
  44. package/docs/scripts/search.js +99 -0
  45. package/docs/styles/jsdoc.css +776 -0
  46. package/docs/styles/prettify.css +80 -0
  47. package/docs/utils.mjs.html +520 -0
  48. package/g.mjs +34 -0
  49. package/package.json +32 -0
  50. package/script.txt +18 -0
  51. package/src/ApiClient.mjs +467 -0
  52. package/src/ApiServer.mjs +444 -0
  53. package/src/WMd2docx.mjs +29 -0
  54. package/src/cvMdTo.mjs +216 -0
  55. package/src/cvMdToDocx.mjs +171 -0
  56. package/src/templates/temp_tpc.docx +0 -0
  57. package/src/utils.mjs +448 -0
  58. package/test/api-ApiClient.test.mjs +221 -0
  59. package/test/api-ApiServer.test.mjs +191 -0
  60. package/test/cocktail.svg +3 -0
  61. package/test/report.md +257 -0
  62. package/test/unit-cvMdTo.test.mjs +132 -0
  63. package/test/unit-cvMdToDocx.test.mjs +185 -0
  64. package/test/unit-utils.test.mjs +370 -0
  65. package/toolg/addVersion.mjs +4 -0
  66. package/toolg/cleanFolder.mjs +5 -0
  67. package/toolg/gDistRollup.mjs +56 -0
  68. package/toolg/gDocsExams.mjs +51 -0
  69. package/toolg/modifyReadme.mjs +4 -0
package/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_style = space
6
+ indent_size = 4
7
+ end_of_line = crlf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ /build/
2
+ /config/
3
+ /dist/
package/.eslintrc.js ADDED
@@ -0,0 +1,55 @@
1
+ module.exports = {
2
+ 'env': {
3
+ 'browser': true,
4
+ 'es6': true,
5
+ 'mocha': true
6
+ },
7
+ 'extends': ['plugin:vue/base', 'plugin:vue/essential', 'standard'],
8
+ 'plugins': [
9
+ 'vue'
10
+ ],
11
+ 'globals': {
12
+ 'Atomics': 'readonly',
13
+ 'SharedArrayBuffer': 'readonly'
14
+ },
15
+ 'parser': 'vue-eslint-parser',
16
+ 'parserOptions': {
17
+ 'parser': '@babel/eslint-parser',
18
+ 'ecmaVersion': 2019,
19
+ 'sourceType': 'module',
20
+ },
21
+ 'rules': {
22
+ 'generator-star-spacing': 'off',
23
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
24
+ 'indent': ['error', 4],
25
+ 'no-console': 'off',
26
+ 'comma-dangle': ['error', {
27
+ 'arrays': 'ignore',
28
+ 'objects': 'ignore',
29
+ 'imports': 'never',
30
+ 'exports': 'never',
31
+ 'functions': 'ignore'
32
+ }],
33
+ 'no-multiple-empty-lines': ['error', { 'max': 2, 'maxEOF': 2 }],
34
+ //'space-before-function-paren': ['error', { 'anonymous': 'always', 'named': 'never' }],
35
+ 'space-before-function-paren': 'off',
36
+ 'spaced-comment': 'off',
37
+ 'brace-style': ['error', 'stroustrup'],
38
+ 'padded-blocks': 'off',
39
+ 'no-constant-condition': 'off',
40
+ 'camelcase': 'off',
41
+ 'no-new': 'off',
42
+ 'prefer-const': 'off',
43
+ 'quote-props': ['error', 'consistent'],
44
+ 'dot-notation': 'off',
45
+ 'standard/no-callback-literal': 'off',
46
+ 'quotes': ['error', 'single', { 'allowTemplateLiterals': true }],
47
+ 'prefer-promise-reject-errors': 'off',
48
+ 'no-unused-vars': ['error', { 'args': 'none', 'ignoreRestSiblings': true, 'argsIgnorePattern': '^_' }],
49
+ 'node/no-callback-literal': 'off',
50
+ 'prefer-regex-literals': 'off',
51
+ 'array-callback-return': 'off',
52
+ 'no-unreachable-loop': 'off',
53
+ 'vue/multi-word-component-names': 'off',
54
+ }
55
+ }
package/.jsdoc ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "tags": {
3
+ "allowUnknownTags": true
4
+ },
5
+ "source": {
6
+ "include": ["src/"],
7
+ "includePattern": ".+\\.(js(doc|x)?|mjs|vue)$",
8
+ "excludePattern": "(node_modules/|docs)"
9
+ },
10
+ "plugins": [
11
+ "plugins/markdown",
12
+ "node_modules/jsdoc-vuejs"
13
+ ],
14
+ "opts": {
15
+ "template": "node_modules/docdash",
16
+ "encoding": "utf8",
17
+ "destination": "docs/",
18
+ "recurse": true,
19
+ "verbose": true
20
+ },
21
+ "templates": {
22
+ "cleverLinks": false,
23
+ "monospaceLinks": false
24
+ }
25
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 semisphere(yu-da, lyu 呂昱達)
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 all
13
+ 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 THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # w-md2docx
2
+ A tool for Markdown to Docx.
3
+
4
+ ![language](https://img.shields.io/badge/language-JavaScript-orange.svg)
5
+ [![npm version](http://img.shields.io/npm/v/w-md2docx.svg?style=flat)](https://npmjs.org/package/w-md2docx)
6
+ [![license](https://img.shields.io/npm/l/w-md2docx.svg?style=flat)](https://npmjs.org/package/w-md2docx)
7
+ [![npm download](https://img.shields.io/npm/dt/w-md2docx.svg)](https://npmjs.org/package/w-md2docx)
8
+ [![npm download](https://img.shields.io/npm/dm/w-md2docx.svg)](https://npmjs.org/package/w-md2docx)
9
+ [![jsdelivr download](https://img.shields.io/jsdelivr/npm/hm/w-md2docx.svg)](https://www.jsdelivr.com/package/npm/w-md2docx)
10
+
11
+ ## Documentation
12
+ To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-md2docx/global.html).
13
+
14
+ ## Core
15
+ > `w-md2docx` is based on `w-md2html` (Markdown to Html) and `w-html2docx` (Html to Docx via `win32com` of `Microsoft Word`), so the docx conversion only runs in `Windows` with `Microsoft Word` installed.
16
+
17
+ It provides four entries:
18
+ - `cvMdToDocx`: convert a Markdown file to a Docx file.
19
+ - `cvMdTo`: convert Markdown content (with attached assets) to Html/Docx content in base64.
20
+ - `ApiServer`: a hapi service (`GET /api/health`, `GET /api/selftest`, `POST /api/convert`) that wraps `cvMdTo`, so machines without Word can convert through it.
21
+ - `ApiClient`: a client for `ApiServer`, reading a local Markdown file with its images and writing back the converted files.
22
+
23
+ ## Installation
24
+
25
+ ### Using npm(ES6 module):
26
+ ```alias
27
+ npm i w-md2docx
28
+ ```
29
+
30
+ #### Example:
31
+ > **Link:** [[dev source code](https://github.com/yuda-lyu/w-md2docx/blob/master/g.mjs)]
32
+ ```alias
33
+ import w from 'wsemi'
34
+ import WMd2docx from './src/WMd2docx.mjs'
35
+ //import WMd2docx from 'w-md2docx/src/WMd2docx.mjs'
36
+ //import WMd2docx from 'w-md2docx'
37
+
38
+
39
+ async function test() {
40
+
41
+ let fpIn = `./test/report.md`
42
+ let fpOut = `./test/report.docx`
43
+ let opt = {
44
+ fpInTemp: './src/templates/temp_tpc.docx', //docx模板, 未給則用w-html2docx內建模板
45
+ optMd2html: {
46
+ imgWidthMax: '500px',
47
+ },
48
+ optHtml2docx: {
49
+ imgRatioWidthMax: 0.5,
50
+ },
51
+ }
52
+
53
+ let r = await WMd2docx.cvMdToDocx(fpIn, fpOut, opt)
54
+ console.log(r)
55
+ // => { fpOutDocx: '...\\test\\report.docx', sizeDocx: 40960, sizeHtml: 61785, ms: 6532 }
56
+
57
+ w.fsDeleteFile(fpOut)
58
+
59
+ }
60
+ test()
61
+ .catch((err) => {
62
+ console.log('catch', err)
63
+ })
64
+ ```
65
+
66
+ #### API service and client:
67
+ ```alias
68
+ import WMd2docx from 'w-md2docx/src/WMd2docx.mjs'
69
+
70
+ //server (Windows with Microsoft Word)
71
+ let { server } = await WMd2docx.ApiServer({ port: 22000, token: '' })
72
+ console.log(`listening on ${server.info.uri}`)
73
+
74
+ //client (any machine)
75
+ let r = await WMd2docx.ApiClient.cvMdTo({
76
+ host: '127.0.0.1',
77
+ port: 22000,
78
+ fpInMd: './test/report.md',
79
+ fpOutDocx: './test/report.docx',
80
+ })
81
+ console.log(r)
82
+ // => { ms: 6532, nAssets: 1, template: 'default', docx: { fp: '...', size: 40960 } }
83
+ ```
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Please report security issues to `firsemisphere@gmail.com`
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ 'presets': [
3
+ ['@babel/preset-env', {
4
+ 'useBuiltIns': 'entry',
5
+ 'corejs': 3
6
+ }]
7
+ ],
8
+ 'plugins': [
9
+ '@babel/plugin-transform-runtime',
10
+ '@babel/plugin-proposal-export-default-from',
11
+ // '@babel/plugin-syntax-import-assertions', //已被棄用
12
+ // '@babel/plugin-proposal-nullish-coalescing-operator', //browser與nodejs已支援
13
+ // '@babel/plugin-proposal-object-rest-spread', //browser與nodejs已支援
14
+ // '@babel/plugin-proposal-optional-chaining', //browser與nodejs已支援
15
+ ]
16
+ }