Skip to content

Commit 70b40a7

Browse files
authored
feat(bi-directional-links): support hash tags, query strings for bi-directional links (#152)
1 parent a4caf2f commit 70b40a7

19 files changed

Lines changed: 1050 additions & 293 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,48 @@ env:
1212
STORE_PATH: ''
1313

1414
jobs:
15+
unittest:
16+
strategy:
17+
matrix:
18+
node-version: ['18.x', '20.x']
19+
20+
name: Unit tests - ${{ matrix.node-version }}
21+
runs-on: 'ubuntu-latest'
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
27+
- name: Install Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
32+
- name: Install pnpm
33+
uses: pnpm/action-setup@v2
34+
with:
35+
run_install: false
36+
version: 8
37+
38+
- name: Obtain pnpm store directory
39+
shell: bash
40+
run: |
41+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
42+
43+
- name: Obtain pnpm store cache
44+
uses: actions/cache@v3
45+
with:
46+
path: ${{ env.STORE_PATH }}
47+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
48+
restore-keys: |
49+
${{ runner.os }}-pnpm-store-
50+
51+
- name: Install dependencies
52+
run: pnpm install --frozen-lockfile
53+
54+
- name: Test
55+
run: pnpm run test:run
56+
1557
lint:
1658
strategy:
1759
matrix:

docs/.vitepress/config.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
4242
{
4343
text: 'Markdown It Plugins',
4444
items: [
45-
{ text: 'Bi-directional links', link: '/pages/en/integrations/markdown-it-bi-directional-links/' },
45+
{
46+
text: 'Bi-directional links',
47+
collapsed: true,
48+
items: [
49+
{ text: 'Getting Started', link: '/pages/en/integrations/markdown-it-bi-directional-links/' },
50+
{ text: 'Syntax', link: '/pages/en/integrations/markdown-it-bi-directional-links/syntax' },
51+
],
52+
},
4653
{ text: 'Elements Transformation', link: '/pages/en/integrations/markdown-it-element-transform/' },
4754
{ text: 'Lazy loading blurred thumbnails', link: '/pages/en/integrations/markdown-it-unlazy-img/' },
4855
],
@@ -59,6 +66,7 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
5966
{ text: 'Enhanced mark elements', link: '/pages/en/integrations/vitepress-plugin-enhanced-mark/' },
6067
{
6168
text: 'Thumbnail hashing for images',
69+
collapsed: true,
6270
items: [
6371
{ text: 'Usage', link: '/pages/en/integrations/vitepress-plugin-thumbnail-hash/' },
6472
{ text: 'Try ThumbHash', link: '/pages/en/integrations/vitepress-plugin-thumbnail-hash/thumbhash' },
@@ -132,7 +140,14 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
132140
{
133141
text: 'Markdown It 插件',
134142
items: [
135-
{ text: '双向链接', link: '/pages/zh-CN/integrations/markdown-it-bi-directional-links/' },
143+
{
144+
text: '双向链接',
145+
collapsed: true,
146+
items: [
147+
{ text: '快速上手', link: '/pages/zh-CN/integrations/markdown-it-bi-directional-links/' },
148+
{ text: '语法', link: '/pages/zh-CN/integrations/markdown-it-bi-directional-links/syntax' },
149+
],
150+
},
136151
{ text: '元素转换', link: '/pages/zh-CN/integrations/markdown-it-element-transform/' },
137152
{ text: '懒加载模糊缩略图', link: '/pages/zh-CN/integrations/markdown-it-unlazy-img/' },
138153
],
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# Bi-directional Links Example Page
22

33
Hi! This is a linked internal page.
4+
5+
## Section 2
6+
7+
Section 2 content.
8+
9+
### Subsection 2.1
10+
11+
Subsection 2.1 content.
12+
13+
## Section 3
14+
15+
Section 3 content.
16+
17+
### Subsection 3.1
18+
19+
Subsection 3.1 content.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# Bi-directional Links Example Same Name Page
22

33
Hi! This is a linked internal page.
4+
5+
## Section 2
6+
7+
Section 2 content.
8+
9+
### Subsection 2.1
10+
11+
Subsection 2.1 content.
12+
13+
## Section 3
14+
15+
Section 3 content.
16+
17+
### Subsection 3.1
18+
19+
Subsection 3.1 content.

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

Lines changed: 33 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
# Bi-directional Links <Badge type="tip" text="v1.27.2" />
22

3-
## Demo
4-
5-
[[Bi-directional Links Example Page]]
6-
7-
Custom text: [[Bi-directional Links Example Page|Custom Text]]
8-
9-
Compatible to modify the HTML attributes [[Bi-directional Links Example Page|Custom Attrs]]{style="color: red;"}
10-
11-
Obsidian same name pages: [[pages/en/integrations/markdown-it-bi-directional-links/same-name/Bi-directional Links Example Same Name Page|Bi-directional Links Example Same Name Page]][[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Same Name Page|Bi-directional Links Example Same Name Page]]
12-
13-
Absolute Path: [[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page]]
14-
15-
Images are supported:
16-
17-
![[foxtail field.jpg]]
18-
193
## Introduction
204

215
**Bi-directional links** (also known as internal links), and another concept you may know and hear about [WikiLinks](https://en.wikipedia.org/wiki/Help:Link), holds a important place in the document engineering area. It is usually used to quickly establish a connection (or link) from one page to another page, and widely used in Wiki pages such as [Wikipedia](https://wikipedia.org), and now days popular tools such as [Obsidian](https://obsidian.md/) and [Logseq](https://logseq.com/).
@@ -25,135 +9,47 @@ This plugin is a fully featured compatible implementation version of [Obsidian](
259
1. A page's file name (without extension) can be used as a link target, for example: `[[Bi-directional Links Example Page]]` will be parsed as a link to the globally unique `Bi-directional Links Example Page.md` file.
2610
2. A link target can be an absolute path, for example: `[[Some Folder/Bi-directional Links Example Page]]` will be parsed as a link to `Some Folder/Bi-directional Links Example Page.md`, usually appears when you have multiple files with the same name.
2711

28-
### Examples
12+
## Demo
2913

30-
<br>
14+
::: info Syntax supporting matrix
15+
16+
<div grid="~ cols-[auto_1fr] gap-1" items-center my-1>
17+
<span i-icon-park-outline:check-one text="green-600" />
18+
<span>Basic syntax</span>
19+
<span i-icon-park-outline:check-one text="green-600" />
20+
<span>Able to handle hash tags <code>#</code></span>
21+
<span i-icon-park-outline:check-one text="green-600" />
22+
<span>Able to handle query strings <code>?</code></span>
23+
<span i-icon-park-outline:check-one text="green-600" />
24+
<span>Images</span>
25+
<span i-icon-park-outline:check-one text="green-600" />
26+
<span>Custom text</span>
27+
<span i-icon-park-outline:check-one text="green-600" />
28+
<span>Custom HTML attributes</span>
29+
<span i-icon-park-outline:check-one text="green-600" />
30+
<span>Same name pages</span>
31+
<span i-icon-park-outline:check-one text="green-600" />
32+
<span>Absolute path</span>
33+
</div>
34+
35+
You can discover more syntaxes and features in the [Syntax](/pages/en/integrations/markdown-it-bi-directional-links/syntax).
36+
:::
3137

32-
#### Basic
38+
Basic: [[Bi-directional Links Example Page]]
3339

34-
```markdown
35-
[[Target Page File Name]]
36-
```
37-
38-
Demo
40+
Custom text: [[Bi-directional Links Example Page|Custom Text]]
3941

40-
[[Bi-directional Links Example Page]]
42+
Compatible to modify the HTML attributes [[Bi-directional Links Example Page|Custom Attrs]]{style="color: red;"}
4143

42-
##### Image
44+
Obsidian same name pages: [[pages/en/integrations/markdown-it-bi-directional-links/same-name/Bi-directional Links Example Same Name Page|Bi-directional Links Example Same Name Page]][[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Same Name Page|Bi-directional Links Example Same Name Page]]
4345

44-
```markdown
45-
![[foxtail field.jpg]]
46-
```
46+
Absolute Path: [[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page]]
4747

48-
Demo
48+
Images are supported:
4949

5050
![[foxtail field.jpg]]
5151

52-
#### Custom Text
53-
54-
```markdown
55-
[[Target Page File Name|Custom Text]]
56-
```
57-
58-
Demo
59-
60-
[[Bi-directional Links Example Page|Custom Text]]
61-
62-
#### Compatible with [`markdown-it-attrs`](https://github.com/arve0/markdown-it-attrs) to modify HTML attributes
63-
64-
<br>
65-
66-
##### Change color
67-
68-
```markdown
69-
[[Target Page File Name]]{style="color: red;"}
70-
```
71-
72-
Demo
73-
74-
[[Bi-directional Links Example Page]]{style="color: red;"}
75-
76-
##### Change class name
77-
78-
```markdown
79-
[[Target Page File Name]]{.custom-class}
80-
```
81-
82-
Demo
83-
84-
[[Bi-directional Links Example Page]]{.custom-class}
85-
86-
### Absolute path
87-
88-
```markdown
89-
[[Some Full Path Reference to Your Page]]
90-
```
91-
92-
Demo
93-
94-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page]]
95-
96-
#### Image
97-
98-
```markdown
99-
![[en/integrations/markdown-it-bi-directional-links/images/railway near by beach same name.jpg]]
100-
```
101-
102-
Demo
103-
104-
![[pages/en/integrations/markdown-it-bi-directional-links/images/railway near by beach same name.jpg]]
105-
106-
And it is distinguishable to the pictures with the same name:
107-
108-
```markdown
109-
![[en/integrations/markdown-it-bi-directional-links/images/same-name/railway near by beach same name.jpg]]
110-
```
111-
112-
Demo
113-
114-
![[pages/en/integrations/markdown-it-bi-directional-links/images/same-name/railway near by beach same name.jpg]]
115-
116-
### Absolute path with custom text
117-
118-
```markdown
119-
[[Some Full Path Reference to Your Page|Custom Text]]
120-
```
121-
122-
Demo
123-
124-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|Custom Text]]
125-
126-
### Use Markdown markup in custom text
127-
128-
```markdown
129-
[[Some Full Path Reference to Your Page|`Code Block (Before)` Middle `Code Block (After)`]]
130-
131-
[[Some Full Path Reference to Your Page|**Bold Before** Middle **Bold After**]]
132-
133-
[[Some Full Path Reference to Your Page|*Italic Before* Middle *After*]]
134-
135-
[[Some Full Path Reference to Your Page|~~Strikethrough Before~~ Middle ~~Strikethrough After~~]]
136-
137-
[[Some Full Path Reference to Your Page|<span style="color: red;">Custom HTML</span>]]
138-
139-
[[Some Full Path Reference to Your Page|<span style="color: red;">Custom HTML (Before)</span> Middle <span style="color: blue;">Custom HTML (After)</span>]]
140-
```
141-
142-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|`Code Block (Before)` Middle `Code Block (After)`]]
143-
144-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|**Bold (Before)** Middle **Bold (After)**]]
145-
146-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|*Italic (Before)* Middle *Italic (After)*]]
147-
148-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|~~Strikethrough (Before)~~ Middle ~~Strikethrough (After)~~]]
149-
150-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|<span style="color: red;">Custom HTML</span>]]
151-
152-
[[pages/en/integrations/markdown-it-bi-directional-links/Bi-directional Links Example Page|<span style="color: red;">Custom HTML</span> Middle <span style="color: blue;">Custom HTML</span>]]
153-
154-
## How to use
155-
156-
### Installation
52+
## Installation
15753

15854
Install `@nolebase/markdown-it-bi-directional-links` to your project dependencies by running the following command:
15955

@@ -173,6 +69,8 @@ yarn add @nolebase/markdown-it-bi-directional-links -D
17369

17470
:::
17571

72+
## Configuration
73+
17674
### Integrate with VitePress
17775

17876
In the VitePress configuration file (usually `docs/.vitepress/config.ts`, the file path and extension may be different), import `@nolebase/markdown-it-bi-directional-links` as a plugin, and use it as a `markdown-it` plugin in the `markdown` option:

0 commit comments

Comments
 (0)