@@ -73,4 +73,79 @@ docsify 4.6 开始支持嵌入任何类型的文件到文档里。你可以将
73
73
74
74
[ ] ( ../_media/example.html ' :include :type=code text ')
75
75
76
- ?> 如何高亮代码?你可以查看[ 这份文档] ( zh-cn/language-highlight.md ) .
76
+ ?> 如何高亮代码?你可以查看[ 这份文档] ( zh-cn/language-highlight.md ) 。
77
+
78
+ ## 嵌入Gist
79
+
80
+ 你可以将 Gist 作为 Markdown 内容或代码块嵌入。这是基于[ 嵌入文件] ( #embed-files ) 部分开头的方法,不过是嵌入一个原始的 Gist URL。
81
+
82
+ ?> 这里** 不需要** 插件或修改配置来使其工作。事实上,即使你使用插件或修改配置来允许加载外部脚本,从 Gist 复制的 "Embed" ` script ` 标签也无法加载。
83
+
84
+ ### 确定Gist的元数据
85
+
86
+ 从查看` gist.github.com ` 上的 Gist 开始。在本指南中,我们使用这个 Gist:
87
+
88
+ - https://gist.github.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15
89
+
90
+ 从 Gist 中找出以下内容:
91
+
92
+ | 字段 | 示例 | 说明 |
93
+ | ------------ | ---------------------------------- | ------------------------------------------------------------------- |
94
+ | ** Username** | ` anikethsaha ` | Gist 的作者 |
95
+ | ** Gist ID** | ` c2bece08f27c4277001f123898d16a7c ` | Gist 的标识符。该标识在 Gist 的有效期内是固定的 |
96
+ | ** Filename** | ` content.md ` | 在 Gist 中选择一个文件名。即使是单文件的 Gist,也需要这样做才能嵌入 |
97
+
98
+ 你将需要这些来为目标文件建立 _ raw gist URL_ 。它的格式如下:
99
+
100
+ - ` https://gist.githubusercontent.com/USERNAME/GIST_ID/raw/FILENAME `
101
+
102
+ 下面是根据示例 Gist 举出的两个例子:
103
+
104
+ - https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/content.md
105
+ - https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/script.js
106
+
107
+ ?> 另外你也可以直接点击 Gist 文件上的 _ Raw_ 按钮来获取原始 URL。但是如果你使用这种方法,请确保** 删除** ` raw/ ` 和文件名之间的修订号,这样 URL 就会与上面的模式一致。否则当更新 Gist 时,你嵌入的 Gist 将** 不会** 显示最新的内容。
108
+
109
+ 继续下面的一个部分,将 Gist 嵌入到 Docsify 页面上。
110
+
111
+ ### 渲染 Gist 中的 Markdown 内容
112
+
113
+ 这是一个很好的方法,可以将内容** 无缝** 地嵌入到你的文档中,而不需要将别人发送到外部链接。这种方法很适合在多个仓库的文档网站上重复使用一个 Gist,比如安装说明。这种方法同样适用于您的账户或其他用户拥有的 Gist。
114
+
115
+ 格式:
116
+
117
+ ``` markdown
118
+ [LABEL](https://gist.githubusercontent.com/USERNAME/GIST_ID/raw/FILENAME ':include')
119
+ ```
120
+
121
+ 例如:
122
+
123
+ ``` markdown
124
+ [gist: content.md](https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/content.md ':include')
125
+ ```
126
+
127
+ 你会看到:
128
+
129
+ [ gist: content.md] ( https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/content.md ' :include ')
130
+
131
+ ` LABEL ` 可以是任何你想要的文本。如果链接被破坏,它可以作为一个 _ fallback_ 信息。所以在这里重复文件名是很有用的,万一你需要修复一个破坏的链接。它还可以使嵌入的元素一目了然。
132
+
133
+ ### 渲染 Gist 中的代码块
134
+
135
+ 格式与上一节相同,但是在alt文本中添加了` :type=code ` 。与[ 嵌入的类型] ( #embedded-file-type ) 部分一样,语法高亮将从扩展名(如` .js ` 或` .py ` )中** 推断** ,所以你可以将` type ` 设置为` code ` 。
136
+
137
+ 格式:
138
+
139
+ ``` markdown
140
+ [LABEL](https://gist.githubusercontent.com/USERNAME/GIST_ID/raw/FILENAME ':include :type=code')
141
+ ```
142
+
143
+ 例如:
144
+
145
+ ``` markdown
146
+ [gist: script.js](https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/script.js ':include :type=code')
147
+ ```
148
+
149
+ 你会看到:
150
+
151
+ [ gist: script.js] ( https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/script.js ' :include :type=code ')
0 commit comments