Điểm qua storybookjs/marksy: 354 sao trên GitHub, viết chủ yếu bằng JavaScript. 📑 A markdown to custom VDOM components library
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
A markdown to custom components library. Supports any virtual DOM library.
Installation
npm install marksy
Usage
import React, {createElement} from 'React';
import marksy from 'marksy'
// const marksy = require('marksy').marksy
const compile = marksy({
// Pass in whatever creates elements for your
// virtual DOM library. h('h1', {})
createElement,
// You can override the default elements with
// custom VDOM trees
elements: {
h1 ({id, children}) {
return <h1 className="my-custom-class">{children}</h1>
},
h2 ({id, children}) {},
h3 ({id, children}) {},
h4 ({id, children}) {},
blockquote ({children}) {},
hr () {},
ol ({children}) {},
ul ({children}) {},
p ({children}) {},
table ({children}) {},
thead ({children}) {},
tbody ({children}) {},
tr ({children}) {},
th ({children}) {},
td ({children}) {},
a ({href, title, target, children}) {},
strong ({children}) {},
em ({children}) {},
br () {},
del ({children}) {},
img ({src, alt}) {},
code ({language, code}) {},
codespan ({children}) {},
},
});
const compiled = compile('# hello', {
// Options passed to "marked" (https://www.npmjs.com/package/marked)
});
compiled.tree // The React tree of components
compiled.toc // The table of contents, based on usage of headers
Components
You can also add your own custom components:
import React, {createElement} from 'react'
import marksy from 'marksy'
const compile = marksy({
createElement,
components: {
MyCustomComponent (props) {
return <h1>{props.children}</h1>
}
}
})
/* CREATE MARKDOWN USING MARKSY LANGUAGE:
# Just a test
```marksy
h(MyCustomComponent, {}, "Some text")
```
*/
This will be converted to the component above. You can pass in any kind of props, as if it was normal code. If you are not familiar with h, this is a convention for creating elements and components in virtual dom implementations.
Jsx
You can take one step further and create components wherever you want in the markdown, using jsx. You will have to import marksy/jsx. This build of marksy includes babel transpiler which will convert any HTML to elements and allow for custom components. Note that this will increase your bundle size significantly:
import React, {createElement} from 'react'
import marksy from 'marksy/jsx'
const compile = marksy({
createElement,
components: {
MyCustomComponent (props) {
return <h1>{props.children}</h1>
}
}
})
/* MARKDOWN:
# Just a test
<MyCustomComponent>some text</MyCustomComponent>
*/
/* WITH LANGUAGE FOR GENERIC SUPPORT:
# Just a test
```marksy
<MyCustomComponent>some text</MyCustomComponent>
```
*/
Context
You might need to pass in general information to your custom elements and components. You can pass in a context to do so:
To enable code highlighting you just need to add a method that does the transformation. Here is an example with Highlight.js, but you could also use Prism. Both of them support server side rendering. For example:
import {createElement} from 'react'
import 'highlight.js/styles/github.css';
import hljs from 'highlight.js/lib/highlight';
import hljsJavascript from 'highlight.js/lib/languages/javascript';
import marksy from 'marksy/jsx'
hljs.registerLanguage('javascript', hljsJavascript);
const compile = marksy({
createElement,
highlight(language, code) {
return hljs.highlight(language, code).value
}
})
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/storybookjs/marksy là nguồn chính thức.
storybookjs/marksy có phải mã nguồn mở không?
Có — storybookjs/marksy phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/storybookjs/marksy.
storybookjs/marksy có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho storybookjs/marksy. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
storybookjs/marksy có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho storybookjs/marksy. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
storybookjs/marksy còn đang phát triển không?
Commit gần nhất trên storybookjs/marksy là 2.0 năm trước (theo timestamp GitHub). Repo có 47 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
storybookjs/marksy dùng license gì?
storybookjs/marksy phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về marksy?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về marksy.