diff --git a/.github/workflows/gitpage.yml b/.github/workflows/gitpage.yml
index f0499df..16bba5f 100644
--- a/.github/workflows/gitpage.yml
+++ b/.github/workflows/gitpage.yml
@@ -19,7 +19,7 @@ jobs:
run: |
npm ci
tsc
- node dist/index.js -s ./example
+ node dist/cli.js -s ./example
- name: commit and push
run: |
cd output
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dd8e2b0..7278b5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,4 +54,7 @@
+ Support render CSV as table
+ Support PlantUML
+ `v0.0.11`
- + Support fretboard
\ No newline at end of file
+ + Support fretboard
++ `v0.0.12`
+ + Change the exported class `Covert` to `Converter`
+ + Now we can import this package by `import { Converter } from 'hackmd-to-html-cli'`
\ No newline at end of file
diff --git a/README.md b/README.md
index cbba414..9aea605 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,9 @@
Not only is this a CLI tool, but it is also an importable package for converting standard Markdown and even [HackMD](https://hackmd.io/)-supported Markdown into HTML.
-+ See the example of input markdown: [./example/index.md](https://raw.githubusercontent.com/ksw2000/hackmd-to-html-cli/main/example/index.md)
++ Example of input markdown: [./example/index.md](https://raw.githubusercontent.com/ksw2000/hackmd-to-html-cli/main/example/index.md)
-+ See the example of output html: [https://ksw2000.github.io/hackmd-to-html-cli/](https://ksw2000.github.io/hackmd-to-html-cli/)
++ Example of output html: [https://ksw2000.github.io/hackmd-to-html-cli/](https://ksw2000.github.io/hackmd-to-html-cli/)
## Install
@@ -56,10 +56,12 @@ $ hmd2html -s hello.md -l ./myLayout.html
## Package (beta)
```js
-const {Convert} = require('hackmd-to-html-cli')
+// for TypeScript
+// import { Converter } from 'hackmd-to-html-cli'
+const { Converter } = require('hackmd-to-html-cli')
const template = `{{main}}`
const hardBreak = true
-const converter = new Convert(template, hardBreak)
+const converter = new Converter(template, hardBreak)
const md = `
# title
hello world
@@ -69,23 +71,22 @@ console.log(converter.convert(md))
**output**
-```
+```html
title
hello world
```
-If you want to get default layout
+Some features
```js
-convert.defaultLayout()
-```
-
-If you want to get metadata after converting
+// get default layout
+converter.defaultLayout()
-```js
+// get metadata after converting
converter.getMetadata()
```
+
## Layout
See default layout here: https://github.com/ksw2000/hackmd-to-html-cli/blob/main/layout.html
diff --git a/lib/cli.ts b/lib/cli.ts
new file mode 100644
index 0000000..e0be699
--- /dev/null
+++ b/lib/cli.ts
@@ -0,0 +1,22 @@
+#!/usr/bin/env node
+import commander from 'commander'
+import fs from 'fs'
+import { Converter } from './converter'
+
+commander.program.version('0.0.12', '-v, --version', 'output the current version')
+commander.program
+ .requiredOption('-s, --source ', 'specify the input markdown files or directories')
+ .addOption(new commander.Option('-d, --destination ', 'specify the output directory').default('./output', './output'))
+ .addOption(new commander.Option('-l, --layout ', 'specify the layout file').default('', '""'))
+ .addOption(new commander.Option('-b, --hardBreak', 'use hard break instead of soft break'))
+ .parse(process.argv)
+
+const options = commander.program.opts()
+
+const dest: string = options.destination === '' ? './output' : options.destination
+const layout: string | null = options.layout !== '' ? fs.readFileSync(options.layout, { encoding: 'utf-8' }) : null
+const hardBreak: boolean = options.hardBreak
+
+const converter = new Converter(layout, hardBreak)
+
+converter.convertFiles(options.source, dest)
diff --git a/lib/converter.ts b/lib/converter.ts
index d2620be..28c3b21 100644
--- a/lib/converter.ts
+++ b/lib/converter.ts
@@ -1,11 +1,11 @@
import fs from 'fs'
import path from 'path'
-import { MarkdownItYAMLMetadata, Metadata } from './yamlMetadata'
-import { MarkdownItContainer } from './container'
-import { MarkdownItCheckbox } from './checkbox'
-import { MarkdownItExternal } from './external'
-import { MarkdownItBlockquoteX } from './blockquotex'
-import { MarkdownItFenceX } from './fenceX'
+import { MarkdownItYAMLMetadata, Metadata } from './markdown/yamlMetadata'
+import { MarkdownItContainer } from './markdown/container'
+import { MarkdownItCheckbox } from './markdown/checkbox'
+import { MarkdownItExternal } from './markdown/external'
+import { MarkdownItBlockquoteX } from './markdown/blockquotex'
+import { MarkdownItFenceX } from './markdown/fencex'
import MarkdownIt from 'markdown-it/lib'
const MarkdownItSub = require('markdown-it-sub')
@@ -23,7 +23,7 @@ const MarkdownItAnchor = require('markdown-it-anchor')
const MarkdownItRuby = require('markdown-it-ruby')
const htmlEncode = require('htmlencode').htmlEncode;
-export class Convert {
+export class Converter {
private md: MarkdownIt
private metadata: Metadata
private layout: string
@@ -32,7 +32,7 @@ export class Convert {
* @param layout set null if you want to use default layout,
* @param hardBreak set true if want to use hardBread
*/
- constructor(layout: string | null, hardBreak: boolean = false) {
+ constructor(layout: string | null, hardBreak = false) {
this.metadata = new Metadata()
if (layout === null) {
layout = this.defaultLayout()
diff --git a/lib/index.ts b/lib/index.ts
index 92b784e..58b7625 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,22 +1 @@
-#!/usr/bin/env node
-import commander from 'commander'
-import fs from 'fs'
-import { Convert } from './converter'
-
-commander.program.version('0.0.11', '-v, --version', 'output the current version')
-commander.program
- .requiredOption('-s, --source ', 'specify the input markdown files or directories')
- .addOption(new commander.Option('-d, --destination ', 'specify the output directory').default('./output', './output'))
- .addOption(new commander.Option('-l, --layout ', 'specify the layout file').default('', '""'))
- .addOption(new commander.Option('-b, --hardBreak', 'use hard break instead of soft break'))
- .parse(process.argv)
-
-const options = commander.program.opts()
-
-const dest: string = options.destination === '' ? './output' : options.destination
-const layout: string | null = options.layout !== '' ? fs.readFileSync(options.layout, { encoding: 'utf-8' }) : null
-const hardBreak: boolean = options.hardBreak
-
-const converter = new Convert(layout, hardBreak)
-
-converter.convertFiles(options.source, dest)
+export {Converter} from './converter'
\ No newline at end of file
diff --git a/lib/blockquotex.ts b/lib/markdown/blockquotex.ts
similarity index 100%
rename from lib/blockquotex.ts
rename to lib/markdown/blockquotex.ts
diff --git a/lib/checkbox.ts b/lib/markdown/checkbox.ts
similarity index 100%
rename from lib/checkbox.ts
rename to lib/markdown/checkbox.ts
diff --git a/lib/container.ts b/lib/markdown/container.ts
similarity index 100%
rename from lib/container.ts
rename to lib/markdown/container.ts
diff --git a/lib/external.ts b/lib/markdown/external.ts
similarity index 100%
rename from lib/external.ts
rename to lib/markdown/external.ts
diff --git a/lib/fenceX.ts b/lib/markdown/fencex.ts
similarity index 97%
rename from lib/fenceX.ts
rename to lib/markdown/fencex.ts
index ffc8a83..73af23b 100644
--- a/lib/fenceX.ts
+++ b/lib/markdown/fencex.ts
@@ -180,9 +180,9 @@ export function MarkdownItFenceX(md: MarkdownIt, _options: MarkdownIt.Options) {
state.tokens = md.utils.arrayReplaceAt(state.tokens, i, newTokens)
} else if (params[0] === 'fretboard') {
const config = parseUserDefinedConfig(params.slice(1).join(' '))
- let title = config.get('title') as string
- let type = config.get('type') as string
- let rendered = renderFretBoard(token.content, { title: title, type: type })
+ const title = config.get('title') as string
+ const type = config.get('type') as string
+ const rendered = renderFretBoard(token.content, { title: title, type: type })
const fret = new Token('html_block', 'div', 0)
fret.content = rendered
diff --git a/lib/fretboard.ts b/lib/markdown/fretboard.ts
similarity index 100%
rename from lib/fretboard.ts
rename to lib/markdown/fretboard.ts
diff --git a/lib/plantUML.ts b/lib/markdown/plantUML.ts
similarity index 100%
rename from lib/plantUML.ts
rename to lib/markdown/plantUML.ts
diff --git a/lib/yamlMetadata.ts b/lib/markdown/yamlMetadata.ts
similarity index 100%
rename from lib/yamlMetadata.ts
rename to lib/markdown/yamlMetadata.ts
diff --git a/package.json b/package.json
index d15ebf6..a9dd3a0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "hackmd-to-html-cli",
- "version": "0.0.11",
+ "version": "0.0.12",
"description": "A node.js CLI tool for converting HackMD markdown to HTML.",
"keywords": [
"hackmd",
@@ -15,10 +15,10 @@
"url": "https://github.com/ksw2000/hackmd-to-html-cli.git"
},
"bin": {
- "hmd2html": "dist/index.js"
+ "hmd2html": "dist/cli.js"
},
- "main": "dist/converter.js",
- "types": "types/converter.d.ts",
+ "main": "dist/index.js",
+ "types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "tsc & npx hmd2html -s ./example",
diff --git a/tsconfig.json b/tsconfig.json
index 143a513..96246f8 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -53,7 +53,7 @@
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
- "sourceRoot": "./lib", /* Specify the root path for debuggers to find the reference source code. */
+ "sourceRoot": "./lib/**/*", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
"inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */