Skip to content

Commit ca1feed

Browse files
committed
docs: update README.md
1 parent f938a4d commit ca1feed

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

README.md

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,54 +62,64 @@ $ hmd2html -i file1.md -k
6262
$ hmd2html -i hello.md -l ./myLayout.html
6363
```
6464
65-
## Package (beta)
65+
## Layouts
6666
67-
```js
68-
// for TypeScript
69-
// import { Converter } from 'hackmd-to-html-cli'
70-
const { Converter } = require('hackmd-to-html-cli')
71-
const template = `{{main}}`
72-
const hardBreak = true
73-
const converter = new Converter(template, hardBreak)
74-
const md = `
75-
# title
76-
hello world
77-
`
78-
console.log(converter.convert(md))
79-
```
67+
We provide the two default layouts. Please see layouts here: [https://github.com/ksw2000/hackmd-to-html-cli/blob/main/layouts/](./layouts/)
68+
69+
+ `{{main}}` renders main content of markdown.
70+
+ `{{lang}}` renders lang property if there are yaml metadata about `lang` in markdown file. e.g. `lang="zh-TW"`
71+
+ `{{dir}}` renders dir property if there are yaml metadata about `dir` in markdown file. e.g. `dir="ltr"`
72+
+ `{{meta}}` renders meta tag if there are yaml metadata about `title`, `description`, `robots` or`image`. e.g. `<meta name="robots" content="noindex">`
8073
81-
**output**
74+
Example:
8275
8376
```html
84-
<h1 id="title" tabindex="-1">title</h1>
85-
<p>hello world</p>
77+
<!DOCTYPE html>
78+
<html {{lang}} {{dir}}>
79+
<head>
80+
{{metas}}
81+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
82+
<meta charset="utf-8">
83+
<body>
84+
{{main}}
85+
</body>
86+
</html>
8687
```
8788
88-
Some features
89+
There are some features rendered by other dependencies. Thus, in our default layout, we include those dependencies.
90+
91+
## Example
92+
93+
### CommonJS
8994
9095
```js
91-
// get default layout
92-
converter.defaultLayout()
96+
const { Converter } = require('hackmd-to-html-cli')
9397
94-
// get metadata after converting
95-
converter.getMetadata()
98+
const converter = new Converter();
99+
const res = converter.render("# hello");
100+
101+
console.log(res.main);
96102
```
97103
98104
99-
## Layout
105+
### ES Module
100106
101-
See default layout here: https://github.com/ksw2000/hackmd-to-html-cli/blob/main/layout.html
107+
```ts
108+
import { Converter } from "hackmd-to-html-cli"
102109
103-
+ `{{main}}` renders main content of markdown.
104-
+ `{{lang}}` renders lang property if there are yaml metadata about `lang` in markdown file. e.g. `lang="zh-TW"`
105-
+ `{{dir}}` renders dir property if there are yaml metadata about `dir` in markdown file. e.g. `dir="ltr"`
106-
+ `{{meta}}` renders meta tag if there are yaml metadata about `title`, `description`, `robots` or`image`. e.g. `<meta name="robots" content="noindex">`
110+
const converter = new Converter();
111+
const res = converter.render("# hello");
107112
108-
## Develop
113+
console.log(res.main);
114+
```
109115
110-
1. `npm run lint` to check the format of source code.
111-
2. `npm run example` runs example for this package, which generates result from `./example` and places them in `./output`.
112-
3. `npm test` runs unit test files whose filenames end with `.test.ts`
116+
### Web
117+
118+
```js
119+
const converter = new window.hmd2html.Converter();
120+
const res = converter.render("# hello");
121+
console.log(res.main);
122+
```
113123
114124
## Support
115125
@@ -195,3 +205,13 @@ HackMD fully supports syntax: [features](https://hackmd.io/features-tw?both)
195205
| others || Hide the metadata by html comment |
196206
197207
HackMD sets the `lang` tag and `dir` tag at the beginning of `<body>`. hmd2html sets the the `lang` tag and `dir` tag at `<html>` when using default layout.
208+
209+
## Development
210+
211+
1. `npm run lint` to check the format of source code.
212+
2. `npm run example` runs example for this package, which generates result from `./example` and places them in `./output`.
213+
3. `npm test` runs unit test files whose filenames end with `.spec.ts`
214+
215+
## Contributing
216+
217+
Contributions to **hackmd-to-html-cli** are welcome and highly appreciated. Please run lint `npm run lint` and test `npm run test` before pull requesting.

0 commit comments

Comments
 (0)