Skip to content

Commit c7cb958

Browse files
committed
Bug fixes: import this package in Typescript
1 parent d8734f7 commit c7cb958

File tree

16 files changed

+56
-51
lines changed

16 files changed

+56
-51
lines changed

.github/workflows/gitpage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: |
2020
npm ci
2121
tsc
22-
node dist/index.js -s ./example
22+
node dist/cli.js -s ./example
2323
- name: commit and push
2424
run: |
2525
cd output

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@
5454
+ Support render CSV as table
5555
+ Support PlantUML
5656
+ `v0.0.11`
57-
+ Support fretboard
57+
+ Support fretboard
58+
+ `v0.0.12`
59+
+ Change the exported class `Covert` to `Converter`
60+
+ Now we can import this package by `import { Converter } from 'hackmd-to-html-cli'`

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
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.
66

7-
+ See the example of input markdown: [./example/index.md](https://raw.githubusercontent.com/ksw2000/hackmd-to-html-cli/main/example/index.md)
7+
+ Example of input markdown: [./example/index.md](https://raw.githubusercontent.com/ksw2000/hackmd-to-html-cli/main/example/index.md)
88

9-
+ See the example of output html: [https://ksw2000.github.io/hackmd-to-html-cli/](https://ksw2000.github.io/hackmd-to-html-cli/)
9+
+ Example of output html: [https://ksw2000.github.io/hackmd-to-html-cli/](https://ksw2000.github.io/hackmd-to-html-cli/)
1010

1111
## Install
1212

@@ -56,10 +56,12 @@ $ hmd2html -s hello.md -l ./myLayout.html
5656
## Package (beta)
5757

5858
```js
59-
const {Convert} = require('hackmd-to-html-cli')
59+
// for TypeScript
60+
// import { Converter } from 'hackmd-to-html-cli'
61+
const { Converter } = require('hackmd-to-html-cli')
6062
const template = `{{main}}`
6163
const hardBreak = true
62-
const converter = new Convert(template, hardBreak)
64+
const converter = new Converter(template, hardBreak)
6365
const md = `
6466
# title
6567
hello world
@@ -69,23 +71,22 @@ console.log(converter.convert(md))
6971

7072
**output**
7173

72-
```
74+
```html
7375
<h1 id="title" tabindex="-1">title</h1>
7476
<p>hello world</p>
7577
```
7678

77-
If you want to get default layout
79+
Some features
7880

7981
```js
80-
convert.defaultLayout()
81-
```
82-
83-
If you want to get metadata after converting
82+
// get default layout
83+
converter.defaultLayout()
8484

85-
```js
85+
// get metadata after converting
8686
converter.getMetadata()
8787
```
8888

89+
8990
## Layout
9091

9192
See default layout here: https://github.com/ksw2000/hackmd-to-html-cli/blob/main/layout.html

lib/cli.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
import commander from 'commander'
3+
import fs from 'fs'
4+
import { Converter } from './converter'
5+
6+
commander.program.version('0.0.12', '-v, --version', 'output the current version')
7+
commander.program
8+
.requiredOption('-s, --source <files_or_dirs...>', 'specify the input markdown files or directories')
9+
.addOption(new commander.Option('-d, --destination <path>', 'specify the output directory').default('./output', './output'))
10+
.addOption(new commander.Option('-l, --layout <html_file>', 'specify the layout file').default('', '""'))
11+
.addOption(new commander.Option('-b, --hardBreak', 'use hard break instead of soft break'))
12+
.parse(process.argv)
13+
14+
const options = commander.program.opts()
15+
16+
const dest: string = options.destination === '' ? './output' : options.destination
17+
const layout: string | null = options.layout !== '' ? fs.readFileSync(options.layout, { encoding: 'utf-8' }) : null
18+
const hardBreak: boolean = options.hardBreak
19+
20+
const converter = new Converter(layout, hardBreak)
21+
22+
converter.convertFiles(options.source, dest)

lib/converter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import { MarkdownItYAMLMetadata, Metadata } from './yamlMetadata'
4-
import { MarkdownItContainer } from './container'
5-
import { MarkdownItCheckbox } from './checkbox'
6-
import { MarkdownItExternal } from './external'
7-
import { MarkdownItBlockquoteX } from './blockquotex'
8-
import { MarkdownItFenceX } from './fenceX'
3+
import { MarkdownItYAMLMetadata, Metadata } from './markdown/yamlMetadata'
4+
import { MarkdownItContainer } from './markdown/container'
5+
import { MarkdownItCheckbox } from './markdown/checkbox'
6+
import { MarkdownItExternal } from './markdown/external'
7+
import { MarkdownItBlockquoteX } from './markdown/blockquotex'
8+
import { MarkdownItFenceX } from './markdown/fencex'
99
import MarkdownIt from 'markdown-it/lib'
1010

1111
const MarkdownItSub = require('markdown-it-sub')
@@ -23,7 +23,7 @@ const MarkdownItAnchor = require('markdown-it-anchor')
2323
const MarkdownItRuby = require('markdown-it-ruby')
2424
const htmlEncode = require('htmlencode').htmlEncode;
2525

26-
export class Convert {
26+
export class Converter {
2727
private md: MarkdownIt
2828
private metadata: Metadata
2929
private layout: string
@@ -32,7 +32,7 @@ export class Convert {
3232
* @param layout set null if you want to use default layout,
3333
* @param hardBreak set true if want to use hardBread
3434
*/
35-
constructor(layout: string | null, hardBreak: boolean = false) {
35+
constructor(layout: string | null, hardBreak = false) {
3636
this.metadata = new Metadata()
3737
if (layout === null) {
3838
layout = this.defaultLayout()

lib/index.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
1-
#!/usr/bin/env node
2-
import commander from 'commander'
3-
import fs from 'fs'
4-
import { Convert } from './converter'
5-
6-
commander.program.version('0.0.11', '-v, --version', 'output the current version')
7-
commander.program
8-
.requiredOption('-s, --source <files_or_dirs...>', 'specify the input markdown files or directories')
9-
.addOption(new commander.Option('-d, --destination <path>', 'specify the output directory').default('./output', './output'))
10-
.addOption(new commander.Option('-l, --layout <html_file>', 'specify the layout file').default('', '""'))
11-
.addOption(new commander.Option('-b, --hardBreak', 'use hard break instead of soft break'))
12-
.parse(process.argv)
13-
14-
const options = commander.program.opts()
15-
16-
const dest: string = options.destination === '' ? './output' : options.destination
17-
const layout: string | null = options.layout !== '' ? fs.readFileSync(options.layout, { encoding: 'utf-8' }) : null
18-
const hardBreak: boolean = options.hardBreak
19-
20-
const converter = new Convert(layout, hardBreak)
21-
22-
converter.convertFiles(options.source, dest)
1+
export {Converter} from './converter'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)