Skip to content

Commit

Permalink
新增 MDParser 轉換 Markdown 至 HTML。
Browse files Browse the repository at this point in the history
  • Loading branch information
pardnchiu committed Jan 14, 2025
1 parent 120019a commit 1ee80a4
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 10 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ npm i @pardnchiu/nanomd
#### ES Module version
```javascript
// Version 1.8.0 and above
import { MDEditor, MDViewer } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";
import { MDEditor, MDViewer, MDParser } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";

// Version 1.6.0-1.7.1
import { editor, viewer } from "https://cdn.jsdelivr.net/npm/pdmarkdownkit@[VERSION]/dist/PDMarkdownKit.module.js";
Expand Down Expand Up @@ -145,6 +145,12 @@ const domViewer = new MDViewer({
(...).appendChild(domEditor.body);
(...).appendChild(domViewer.body);

// Version 1.10.0 and above
const domParser = new MDParser({
standard: 1 // Support only standard syntax, default: 1 | true
});

console.log(domParser.parse("**Text to parse**"));
```

## License
Expand Down
9 changes: 8 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ npm i @pardnchiu/nanomd
#### ES Module 版本
```javascript
// 1.8.0 版本以上
import { MDEditor, MDViewer } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";
import { MDEditor, MDViewer, MDParser } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";

// 1.6.0-1.7.1 版本
import { editor, viewer } from "https://cdn.jsdelivr.net/npm/pdmarkdownkit@[VERSION]/dist/PDMarkdownKit.module.js";
Expand Down Expand Up @@ -144,6 +144,13 @@ const domViewer = new MDViewer({
// 若無指定元件,需手動將播放器加入至 DOM 中
(...).appendChild(domEditor.body);
(...).appendChild(domViewer.body);

// 1.10.0 版本以上
const domParser = new MDParser({
standard: 1 // 僅支持標準語法,預設值:1 | true
});

console.log(domParser.parse("**欲解析的文字**"))
```

## 授權條款
Expand Down
2 changes: 1 addition & 1 deletion dist/NanoMD.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/NanoMD.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@
npm
</a>
<span></span>
<a href="https://github.com/pardnchiu/NanoMD-App" title="Mac application" target="_blank">
<i class="fa-brands fa-apple"></i>
Mac (Beta)
</a>
<span></span>
<a :href="/page/agreement.html?lang={{ lang }}">
<i class="fa-solid fa-scale-balanced"></i>
LICENSE
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@pardnchiu/nanomd",
"version": "1.9.6",
"version": "1.10.0",
"description": "NanoMD is a lightweight Markdown editing and viewing library built on pure JavaScript and native APIs. Can be easily embedded into websites, offers rich features, and supports real-time previewing.",
"main": "dist/NanoMD.js",
"module": "dist/NanoMD.esm.js",
"types": "src/interface.ts",
"scripts": {
"minify": "npx terser src/*.js src/function/*.js src/model/*.js -c -m -o dist/NanoMD.js --config-file terser.config.json --name-cache terser.cache.json && npx terser src/*.js src/function/*.js src/model/*.js -c -m -o dist/NanoMD.esm.js --config-file terser.config.json --name-cache terser.cache.json && echo 'export const editor = window.MDEditor; export const MDEditor = window.MDEditor; export const viewer = window.MDViewer; export const MDViewer = window.MDViewer;' >> dist/NanoMD.esm.js",
"minify": "npx terser src/*.js src/function/*.js src/model/*.js -c -m -o dist/NanoMD.js --config-file terser.config.json --name-cache terser.cache.json && npx terser src/*.js src/function/*.js src/model/*.js -c -m -o dist/NanoMD.esm.js --config-file terser.config.json --name-cache terser.cache.json && echo 'export const editor = window.MDEditor; export const MDEditor = window.MDEditor; export const viewer = window.MDViewer; export const MDViewer = window.MDViewer; export const MDParser = window.MDParser;' >> dist/NanoMD.esm.js",
"minify-w": "chokidar src/*.js src/function/*.js src/model/*.js -c 'npm run minify'",
"sass": "sass src/sass:dist/ -w --style compressed --no-source-map",
"sass-index": "sass static/sass/:static/css/ -w --style compressed --no-source-map"
Expand Down
13 changes: 13 additions & 0 deletions page/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,19 @@
console.error(error);
});


const parser1 = new MDParser({
standard: true,
text: pre
});

const parser2 = new MDParser({
standard: false,
text: pre
});
console.log(parser1.parse())
console.log(parser2.parse())

url.searchParams.set("tag", title);
window.history.replaceState({}, document.title, url.href);

Expand Down
Binary file modified src/data.js
Binary file not shown.
Binary file modified src/function/setBlockquote.js
Binary file not shown.
Binary file modified src/function/setFont.js
Binary file not shown.
Binary file modified src/function/setLink.js
Binary file not shown.
Binary file modified src/function/setMedia.js
Binary file not shown.
Binary file modified src/function/transToHTML.js
Binary file not shown.
Binary file modified src/model/editor.js
Binary file not shown.
Binary file added src/model/parser.js
Binary file not shown.
8 changes: 7 additions & 1 deletion static/md/en/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- **ES Module version**
```javascript
// Version 1.8.0 and above
import { MDEditor, MDViewer } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";
import { MDEditor, MDViewer, MDParser } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";
// Version 1.6.0-1.7.1
import { editor, viewer } from "https://cdn.jsdelivr.net/npm/pdmarkdownkit@[VERSION]/dist/PDMarkdownKit.module.js";
Expand Down Expand Up @@ -92,4 +92,10 @@
(...).appendChild(domEditor.body);
(...).appendChild(domViewer.body);
// Version 1.10.0 and above
const domParser = new MDParser({
standard: 1 // Support only standard syntax, default: 1 | true
});
console.log(domParser.parse("**Text to parse**"));
```
13 changes: 10 additions & 3 deletions static/md/zh/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- **ES Module 版本**
```javascript
// 1.8.0 版本以上
import { MDEditor, MDViewer } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";
import { MDEditor, MDViewer, MDParser } from "https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@[VERSION]/dist/NanoMD.esm.js";
// 1.6.0-1.7.1 版本
import { editor, viewer } from "https://cdn.jsdelivr.net/npm/pdmarkdownkit@[VERSION]/dist/PDMarkdownKit.module.js";
Expand All @@ -31,7 +31,7 @@
## 使用方法
- **初始化 `MDEditor``MDViewer`**
- **初始化 `MDEditor``MDViewer``MDParser`**
```Javascript
// 1.8.0 版本以上
// 統一使用: MDEditor, MDViewer
Expand Down Expand Up @@ -74,7 +74,7 @@
emptyContent: "", // 預設內容,當編輯器為空時顯示
style: {
mode: "", // auto | light | dark, 預設: auto
fill: "", // 隨父元素大小調整,預設值:1 | true
fill: 1, // 隨父元素大小調整,預設值:1 | true
fontFamily: "", // 預設:'Noto Sans TC', sans-serif
},
sync: {
Expand All @@ -91,4 +91,11 @@
// 若無指定元件,需手動將播放器加入至 DOM 中
(...).appendChild(domEditor.body);
(...).appendChild(domViewer.body);
// 1.10.0 版本以上
const domParser = new MDParser({
standard: 1 // 僅支持標準語法,預設值:1 | true
});
console.log(domParser.parse("**欲解析的文字**"))
```

0 comments on commit 1ee80a4

Please sign in to comment.