Skip to content

Commit 752d13a

Browse files
authored
feat(bi-link): support image size (#486)
* feat(bi-link): support image size * docs(bi-link): refactor bi-link syntax docs * feat(bi-link): support size without height
1 parent ea492fa commit 752d13a

File tree

7 files changed

+184
-40
lines changed

7 files changed

+184
-40
lines changed

docs/pages/en/integrations/markdown-it-bi-directional-links/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ This plugin is a fully featured compatible implementation version of [Obsidian](
2828
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
2929
<span>Images</span>
3030
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
31+
<span>Images size</span>
32+
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
3133
<span>Custom text</span>
3234
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
3335
<span>Custom HTML attributes</span>

docs/pages/en/integrations/markdown-it-bi-directional-links/syntax.md

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The following syntaxes are supported:
1818
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
1919
<span>Images</span>
2020
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
21+
<span>Images size</span>
22+
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
2123
<span>Custom text</span>
2224
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
2325
<span>Custom HTML attributes</span>
@@ -27,9 +29,7 @@ The following syntaxes are supported:
2729
<span>Absolute path</span>
2830
</div>
2931

30-
## Syntax Reference
31-
32-
### Basic
32+
## Basic Syntax
3333

3434
The syntax is the same as what [Internal links - Obsidian Help](https://help.obsidian.md/Linking+notes+and+files/Internal+links) supported and simple to write:
3535

@@ -41,6 +41,8 @@ The `Bi-directional Links Example Page` is the file name of the target page. The
4141

4242
[[Bi-directional Links Example Page]]
4343

44+
## link url
45+
4446
### Hash tags
4547

4648
::: info What is the targeted title? How does this feature work?
@@ -81,6 +83,10 @@ The rendered result will be:
8183

8284
[[Bi-directional Links Example Page#section-2]]
8385

86+
Or leave the page section blank and directly fill in `#<heading>` to indicate a jump to the specified heading of the current page, such as:
87+
88+
[[#basic-syntax]]
89+
8490
### Query strings
8591

8692
Beyond the default behaviors that Obsidian supported, we also support query strings in the link target. This is useful when you have a inner Vue component or JavaScript logic that can handle the query strings as part of the automation:
@@ -93,7 +99,19 @@ The rendered result will be:
9399

94100
[[Bi-directional Links Example Page?query=string]]
95101

96-
### Image
102+
### Absolute path
103+
104+
```markdown
105+
[[Some Full Path Reference to Your Page]]
106+
```
107+
108+
Demo
109+
110+
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page]]
111+
112+
### Show Image
113+
114+
Adding `!` in front of `[[...]]` can display the picture, video, audio.
97115

98116
```markdown
99117
![[foxtail field.jpg]]
@@ -103,6 +121,24 @@ Demo
103121

104122
![[foxtail field.jpg]]
105123

124+
## Additional attributes
125+
126+
This part is optional.
127+
128+
### Media Size
129+
130+
(It takes effect for pictures and video links)
131+
132+
```markdown
133+
![[foxtail field.jpg|pic alt(option)|200x200]]
134+
```
135+
136+
Among them, `200x0` or `0x200` respectively indicate setting only the width or heigh.
137+
138+
Demo
139+
140+
![[foxtail field.jpg|pic alt(option)|200x200]]
141+
106142
### Custom Text
107143

108144
```markdown
@@ -113,6 +149,10 @@ Demo
113149

114150
[[Bi-directional Links Example Page|Custom Text]]
115151

152+
For jump links, this is the displayed text.
153+
For the display of pictures or videos, etc., this is the alt attribute.
154+
(It is displayed when the object cannot be rendered)
155+
116156
#### Use Markdown markup in custom text
117157

118158
```markdown
@@ -169,17 +209,9 @@ Demo
169209

170210
[[Bi-directional Links Example Page]]{.custom-class}
171211

172-
### Absolute path
212+
## More demo
173213

174-
```markdown
175-
[[Some Full Path Reference to Your Page]]
176-
```
177-
178-
Demo
179-
180-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page]]
181-
182-
#### Image with absolute path
214+
### Image with absolute path
183215

184216
```markdown
185217
![[en/integrations/markdown-it-bi-directional-links/images/railway near by beach same name.jpg]]
@@ -199,7 +231,7 @@ Demo
199231

200232
![[pages/en/integrations/markdown-it-bi-directional-links/images/same-name/railway near by beach same name.jpg]]
201233

202-
#### Audio with absolute path
234+
### Audio with absolute path
203235

204236
```markdown
205237
![[pages/en/integrations/markdown-it-bi-directional-links/audios/Applause.mp3]]
@@ -209,7 +241,7 @@ Demo
209241

210242
![[pages/en/integrations/markdown-it-bi-directional-links/audios/Applause.mp3]]
211243

212-
#### Video with absolute path
244+
### Video with absolute path
213245

214246
```markdown
215247
![[pages/en/integrations/markdown-it-bi-directional-links/videos/Big rabbit came out of the hutch.mp4]]
@@ -219,7 +251,7 @@ Demo
219251

220252
![[pages/en/integrations/markdown-it-bi-directional-links/videos/Big rabbit came out of the hutch.mp4]]
221253

222-
#### Absolute path with custom text
254+
### Absolute path with custom text
223255

224256
```markdown
225257
[[Some Full Path Reference to Your Page|Custom Text]]
@@ -228,5 +260,3 @@ Demo
228260
Demo
229261

230262
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|Custom Text]]
231-
232-

docs/pages/zh-CN/integrations/markdown-it-bi-directional-links/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import packageJSON from '~/packages/markdown-it-bi-directional-links/package.jso
2929
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
3030
<span>图片双链</span>
3131
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
32+
<span>图片尺寸</span>
33+
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
3234
<span>自定义文案</span>
3335
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
3436
<span>自定义 HTML 属性</span>

docs/pages/zh-CN/integrations/markdown-it-bi-directional-links/syntax.md

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ sidebarTitle: 语法
1818
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
1919
<span>图片双链</span>
2020
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
21+
<span>图片尺寸</span>
22+
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
2123
<span>自定义文案</span>
2224
<div h=[1rem]><div i-icon-park-outline:check-one text="green-600" /></div>
2325
<span>自定义 HTML 属性</span>
@@ -27,9 +29,7 @@ sidebarTitle: 语法
2729
<span>绝对路径语法</span>
2830
</div>
2931

30-
## 用法示例
31-
32-
### 基本语法
32+
## 基本语法
3333

3434
其语法与 [Internal links - Obsidian Help](https://help.obsidian.md/Linking+notes+and+files/Internal+links)支持的语法相同,编写起来也很简单:
3535

@@ -43,6 +43,8 @@ sidebarTitle: 语法
4343

4444
[[双向链接示例页面]]
4545

46+
## 链接 url
47+
4648
### Hash tag(标题选择器)
4749

4850
::: info 目标标题是什么?这样的功能是如何工作的?
@@ -83,6 +85,10 @@ document.querySelector('#为什么')
8385

8486
[[双向链接示例页面#章节-2]]
8587

88+
或者不写页面部分,直接填写 `#<heading>` 表示跳转到当前页面的指定标题,如:
89+
90+
[[#基本语法]]
91+
8692
### 查询字符串
8793

8894
除了 Obsidian 支持的默认行为外,我们还支持「查询字符串」。
@@ -97,7 +103,19 @@ document.querySelector('#为什么')
97103

98104
[[双向链接示例页面?query=string]]
99105

100-
### 图片
106+
### 绝对路径
107+
108+
```markdown
109+
[[某个完整路径]]
110+
```
111+
112+
效果
113+
114+
[[pages/zh-CN/integrations/markdown-it-bi-directional-links/双向链接示例页面]]
115+
116+
### 显示图片
117+
118+
`[[...]]` 前面添加 `!` 可以显示图片、视频、音频等。
101119

102120
```markdown
103121
![[一片 狗尾草.jpg]]
@@ -107,6 +125,24 @@ document.querySelector('#为什么')
107125

108126
![[一片 狗尾草.jpg]]
109127

128+
## 额外属性
129+
130+
这部分是可选的。
131+
132+
### 显示大小
133+
134+
(对图片和视频链接生效)
135+
136+
```markdown
137+
![[一片 狗尾草.jpg|图片名(可省略)|200x200]]
138+
```
139+
140+
其中 `200x0``0x200` 分别表示仅设置宽或高。
141+
142+
效果
143+
144+
![[一片 狗尾草.jpg|图片名(可省略)|200x200]]
145+
110146
### 自定义显示的文案
111147

112148
```markdown
@@ -117,6 +153,9 @@ document.querySelector('#为什么')
117153

118154
[[双向链接示例页面|自定义文案]]
119155

156+
对于跳转链接来说,这是显示的文字。对于图片或视频等显示来说,这是 alt 属性
157+
(用于对象无法渲染时显示)
158+
120159
#### 自定义文案中使用 Markdown 语法
121160

122161
```markdown
@@ -175,17 +214,9 @@ document.querySelector('#为什么')
175214

176215
[[双向链接示例页面]]{.some-class}
177216

178-
### 绝对路径
179-
180-
```markdown
181-
[[某个完整路径]]
182-
```
183-
184-
效果
185-
186-
[[pages/zh-CN/integrations/markdown-it-bi-directional-links/双向链接示例页面]]
217+
## 更多案例
187218

188-
#### 图片配合绝对路径
219+
### 图片配合绝对路径
189220

190221
```markdown
191222
![[zh-CN/integrations/markdown-it-bi-directional-links/images/海滩铁轨 同名图片.jpg]]
@@ -205,7 +236,7 @@ document.querySelector('#为什么')
205236

206237
![[pages/zh-CN/integrations/markdown-it-bi-directional-links/images/same-name/海滩铁轨 同名图片.jpg]]
207238

208-
#### 音频配合绝对路径
239+
### 音频配合绝对路径
209240

210241
```markdown
211242
![[pages/zh-CN/integrations/markdown-it-bi-directional-links/audios/鼓掌声.mp3]]
@@ -215,7 +246,7 @@ document.querySelector('#为什么')
215246

216247
![[pages/zh-CN/integrations/markdown-it-bi-directional-links/audios/鼓掌声.mp3]]
217248

218-
#### 视频配合绝对路径
249+
### 视频配合绝对路径
219250

220251
```markdown
221252
![[pages/zh-CN/integrations/markdown-it-bi-directional-links/videos/大兔子从兔窝中钻出.mp4]]
@@ -225,7 +256,7 @@ document.querySelector('#为什么')
225256

226257
![[pages/zh-CN/integrations/markdown-it-bi-directional-links/videos/大兔子从兔窝中钻出.mp4]]
227258

228-
#### 绝对路径和自定义文案
259+
### 绝对路径和自定义文案
229260

230261
```markdown
231262
[[某个文件夹|自定义文案]]

packages/markdown-it-bi-directional-links/src/index.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,46 @@ describe('markdown-it-bi-directional-links', () => {
9191
expect(rendered).toBe('<p><img src="/foo.png" alt="alt text"></p>\n')
9292
})
9393

94+
it('image size', () => {
95+
const rendered = new MarkdownIt({ html: true })
96+
.use(BiDirectionalLinks({ dir: testdataDir }))
97+
.render('[[foo.png|300x200]]')
98+
99+
expect(rendered).toBe('<p><img src="/foo.png" alt="" width="300" height="200"></p>\n')
100+
})
101+
102+
it('image size, without height', () => {
103+
const rendered = new MarkdownIt({ html: true })
104+
.use(BiDirectionalLinks({ dir: testdataDir }))
105+
.render('[[foo.png|300]]')
106+
107+
expect(rendered).toBe('<p><img src="/foo.png" alt="" width="300"></p>\n')
108+
})
109+
110+
it('image size, with zero height', () => {
111+
const rendered = new MarkdownIt({ html: true })
112+
.use(BiDirectionalLinks({ dir: testdataDir }))
113+
.render('[[foo.png|300x0]]')
114+
115+
expect(rendered).toBe('<p><img src="/foo.png" alt="" width="300"></p>\n')
116+
})
117+
118+
it('image size, with zero width', () => {
119+
const rendered = new MarkdownIt({ html: true })
120+
.use(BiDirectionalLinks({ dir: testdataDir }))
121+
.render('[[foo.png|0x200]]')
122+
123+
expect(rendered).toBe('<p><img src="/foo.png" alt="" height="200"></p>\n')
124+
})
125+
126+
it('image size, with alt', () => {
127+
const rendered = new MarkdownIt({ html: true })
128+
.use(BiDirectionalLinks({ dir: testdataDir }))
129+
.render('[[foo.png|alt text|300x200]]')
130+
131+
expect(rendered).toBe('<p><img src="/foo.png" alt="alt text" width="300" height="200"></p>\n')
132+
})
133+
94134
it('should render simple form with custom html texts', () => {
95135
const inlineHTML = `<span style="color: red;">Custom HTML (Before)</span> Middle <span style="color: blue;">Custom HTML (After)</span>`
96136

0 commit comments

Comments
 (0)