
Unified
coding一月 30, 20221mins
Frontend
Unified生态专门处理不同格式内容的转换与处理,主要流程是
- 通过Parser将源文件的内容转换的AST
- 不同的AST之间进行转换
- 对AST进行修改
- 将AST进行Stringify转换成目标格式的内容
tsx
| ........................ process ........................... || .......... parse ... | ... run ... | ... stringify ..........|+--------+ +----------+Input ->- | Parser | ->- Syntax Tree ->- | Compiler | ->- Output+--------+ | +----------+X|+--------------+| Transformers |+--------------+
ASTH1
APIH1
[unified.parse()](https://github.com/unifiedjs/unified#processorparsefile) 只执行Parse过程
unified.run() 执行Parse以及Tranform过程
[unified.process()](https://github.com/unifiedjs/unified#processorprocessfile-done) 会执行完整个流程
模块H1
remarkH2
处理markdown格式
rehypeH2
处理html格式
示例H1
将markdown转换成html,并进行一些处理后输出HTML
bash
const file = await unified().use(remarkParse).use(remarkRehype).use(rehypeDocument, {title: '👋🌍'}).use(rehypeFormat).use(rehypeStringify).process('# Hello world!')---<!doctype html><html lang="en"><head><meta charset="utf-8"><title>👋🌍</title><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><h1>Hello world!</h1></body></html>
评论
新的评论
上一篇
基于Staticman的评论功能
概述 使用Staticman的大致工作流程是: 客户端向Staticman的实例发送HTTP请求,创建表单内容(即一系列字段) Staticman接收到请求后,根据当前的URL(URL中的参数对应仓库信息),读取对应仓库下的staticman配置文件 Staticman读取配置…
下一篇
Node多模块
npm link 在要被链接的模块目录执行 npm link 会将当前模块作为链接添加到 {prefix}/lib/node_modules/<package> 在要链接其他模块的项目目录执行 npm link package-name 会在当前目录的 node_modul…
