Skip to content

Commit 9f66cfd

Browse files
authored
feat(inline-link-preview): migrated to unbuild, wrapped with standalone markdown-it plugin, added fancy documentations (#155)
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
1 parent e397c8b commit 9f66cfd

45 files changed

Lines changed: 1488 additions & 212 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ jobs:
5151
- name: Install dependencies
5252
run: pnpm install --frozen-lockfile
5353

54+
- name: Build packages
55+
run: pnpm run packages:build
56+
5457
- name: Test
5558
run: pnpm run test:run
5659

docs/.vitepress/config.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import MarkdownItFootnote from 'markdown-it-footnote'
66
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
77

88
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links'
9-
import { ElementTransform } from '@nolebase/markdown-it-element-transform'
9+
import { InlineLinkPreviewElementTransform } from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
1010
import { buildEndGenerateOpenGraphImages } from '@nolebase/vitepress-plugin-og-image'
1111
import { UnlazyImages } from '@nolebase/markdown-it-unlazy-img'
1212

@@ -310,6 +310,15 @@ export default defineConfig({
310310
codeTransformers: [
311311
transformerTwoslash({
312312
errorRendering: 'hover',
313+
twoslashOptions: {
314+
compilerOptions: {
315+
target: 99,
316+
moduleResolution: 100,
317+
esModuleInterop: true,
318+
isolatedModules: true,
319+
verbatimModuleSyntax: true,
320+
},
321+
},
313322
}),
314323
],
315324
preConfig(md) {
@@ -322,29 +331,7 @@ export default defineConfig({
322331
},
323332
config(md) {
324333
md.use(MarkdownItFootnote)
325-
md.use(ElementTransform, (() => {
326-
let transformNextLinkCloseToken = false
327-
328-
return {
329-
transform(token) {
330-
switch (token.type) {
331-
case 'link_open':
332-
if (token.attrGet('class') !== 'header-anchor') {
333-
token.tag = 'VPNolebaseInlineLinkPreview'
334-
transformNextLinkCloseToken = true
335-
}
336-
break
337-
case 'link_close':
338-
if (transformNextLinkCloseToken) {
339-
token.tag = 'VPNolebaseInlineLinkPreview'
340-
transformNextLinkCloseToken = false
341-
}
342-
343-
break
344-
}
345-
},
346-
}
347-
})())
334+
md.use(InlineLinkPreviewElementTransform)
348335
},
349336
},
350337
async buildEnd(siteConfig) {

docs/.vitepress/theme/components/HomeContent.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
1515
@media (min-width: 640px) {
1616
.container {
17-
padding: 0 48px;
17+
padding: 0 24px;
1818
}
1919
}
2020
2121
@media (min-width: 960px) {
2222
.container {
2323
width: 100%;
24-
padding: 0 64px;
24+
padding: 0 48px;
2525
}
2626
}
2727
</style>

docs/.vitepress/theme/components/IntegrationCard.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,28 @@ const data = useData()
3030
class="text-$vp-c-text-1!"
3131
>
3232
<span v-if="props.type === IntegrationType.markdownIt || props.type === IntegrationType.vitepress" flex="~ col 1" gap-2>
33-
<span>
33+
<span text="<sm:sm">
3434
<template v-if="$slots.title">
3535
<slot name="title" />
3636
</template>
3737
<template v-else>
3838
{{ props.title }}
3939
</template>
40-
<slot name="badge" /></span>
41-
<span text="sm zinc-400 dark:zinc-600">@nolebase/{{ props.package }}</span>
40+
<slot name="badge" />
41+
</span>
42+
<span text="sm <sm:xs zinc-400 dark:zinc-600">@nolebase/{{ props.package }}</span>
4243
</span>
4344
<span v-if="props.type === IntegrationType.obsidian" flex="~ col 1" gap-2>
44-
<span>
45+
<span text="<sm:sm">
4546
<template v-if="$slots.title">
4647
<slot name="title" />
4748
</template>
4849
<template v-else>
4950
{{ props.title }}
5051
</template>
51-
<slot name="badge" /></span>
52-
<span text="sm zinc-400 dark:zinc-600">{{ props.package }}</span>
52+
<slot name="badge" />
53+
</span>
54+
<span text="sm <sm:xs zinc-400 dark:zinc-600">{{ props.package }}</span>
5355
</span>
5456
<template v-if="props.type === IntegrationType.markdownIt">
5557
<span class="i-octicon:markdown-16" h-15 w-15 text-5xl />

docs/.vitepress/theme/styles/main.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ html, body {
3232
.footnotes > .footnotes-list > .footnote-item > p {
3333
line-height: 18px;
3434
}
35+
36+
@media (max-width: 640px) {
37+
.VPBadge {
38+
font-size: 8px;
39+
padding: 0px 6px;
40+
}
41+
}
42+
43+
@media (max-width: 960px) {
44+
.VPBadge {
45+
font-size: 10px;
46+
padding: 0px 8px;
47+
}
48+
}

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@nolebase/vitepress-plugin-enhanced-readabilities": "workspace:^",
2121
"@nolebase/vitepress-plugin-git-changelog": "workspace:^",
2222
"@nolebase/vitepress-plugin-highlight-targeted-heading": "workspace:^",
23+
"@nolebase/vitepress-plugin-inline-link-preview": "workspace:^",
2324
"@nolebase/vitepress-plugin-og-image": "workspace:^",
2425
"@nolebase/vitepress-plugin-page-properties": "workspace:^",
2526
"@nolebase/vitepress-plugin-thumbnail-hash": "workspace:^",

docs/pages/en/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Nólëbase Integrations project provides a variety of integrations, plugins, com
6363

6464
<IntegrationCard type="vitepress" title="Inline Link Previewing" package="vitepress-plugin-inline-link-preview">
6565
<template v-slot:badge>
66-
<Badge type="warning" text="Beta" />
66+
<Badge type="tip" text="v1.28.0" />
6767
</template>
6868
</IntegrationCard>
6969

docs/pages/en/integrations/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Nólëbase Integrations project provides a variety of integrations, plugins, com
4040

4141
<IntegrationCard type="vitepress" title="Inline Link Previewing" package="vitepress-plugin-inline-link-preview">
4242
<template v-slot:badge>
43-
<Badge type="warning" text="Beta" />
43+
<Badge type="tip" text="v1.28.0" />
4444
</template>
4545
</IntegrationCard>
4646

docs/pages/en/integrations/markdown-it-element-transform/index.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a low-level plugin that is intended to be used by advanced users who wan
44

55
::: warning Before you start
66

7-
This plugin primarily is a helper utility markdown-it plugin for [Inline Links Previewing](/pages/en/integrations/vitepress-plugin-inline-link-preview/) to help to transform all the `<a>` elements to `<NolebaseInlineLinkPreview>` components.
7+
This plugin primarily is a helper utility markdown-it plugin for [Inline Links Previewing](/pages/en/integrations/vitepress-plugin-inline-link-preview/) to help to transform all the `<a>` elements to `<VPNolebaseInlineLinkPreview>` components.
88

99
When using this plugin directly, you may encounter errors like `Invalid tag`, or `Element missing end tag` errors when integrating with VitePress or Vue markdown plugins after transforming [tokens](https://markdown-it.github.io/markdown-it/#Token) and elements,
1010
or other markdown-it plugins that are not compatible with the transformed elements. Please use it when you understand how the [Token API](https://markdown-it.github.io/markdown-it/#Token) of `markdown-it` works.
@@ -52,15 +52,7 @@ Check out install instructions in the [`vite-plugin-inspect` docs](https://githu
5252

5353
:::
5454

55-
### Use with [Inline Links Previewing](/pages/en/integrations/vitepress-plugin-inline-link-preview/)
56-
57-
Use this plugin with [Inline Links Previewing](/pages/en/integrations/vitepress-plugin-inline-link-preview/) to replace all the `<a>` elements to `<NolebaseInlineLinkPreview>` components to enable the abilities to preview the links.
58-
59-
::: danger Implementation may change in the future for [Inline Links Previewing](/pages/en/integrations/vitepress-plugin-inline-link-preview/)
60-
61-
Such usage is a temporary workaround due to the fact that we haven't had time to refactor [Inline Links Previewing](/pages/en/integrations/vitepress-plugin-inline-link-preview/) plugin to listen the mouse hovering event of all the `<a>` elements as singleton instance across all pages for both better accessibility and compatibilities (since it replaces all the `<a>` elements and may break the markdown processing pipelines for advanced users).
62-
63-
:::
55+
### Change the tag of the elements
6456

6557
This is the living example code where we use it as references:
6658

@@ -79,11 +71,13 @@ markdownIt.use(ElementTransform, (() => {
7971
transform(token) {
8072
switch (token.type) {
8173
case 'link_open':
74+
// You can have some conditions here to skip the transformation
75+
//
8276
// Skip the transformation if the token is a header anchor
83-
// because the header anchor doesn't need to be previewed
77+
// since usually the header anchor is not quite the same as the normal link
8478
if (token.attrGet('class') !== 'header-anchor') {
8579
// Modify the tag of the token
86-
token.tag = 'NolebaseInlineLinkPreview'
80+
token.tag = 'YourLinkComponentName'
8781
// Set the flag to transform the next link_close token
8882
transformNextLinkCloseToken = true
8983
}
@@ -92,7 +86,7 @@ markdownIt.use(ElementTransform, (() => {
9286
// Transform the token if the flag is set
9387
if (transformNextLinkCloseToken) {
9488
// Modify the tag of the token
95-
token.tag = 'NolebaseInlineLinkPreview'
89+
token.tag = 'YourLinkComponentName'
9690
// Reset the flag
9791
transformNextLinkCloseToken = false
9892
}

docs/pages/en/integrations/vitepress-plugin-enhanced-readabilities/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ import {
241241
If you are working on a VitePress and wanted to install it into Vue instance, you can do it like this:
242242

243243
```typescript twoslash
244-
import { Theme as ThemeConfig } from 'vitepress'
244+
import type { Theme as ThemeConfig } from 'vitepress'
245245
import DefaultTheme from 'vitepress/theme'
246246

247247
import { NolebaseEnhancedReadabilitiesPlugin } from '@nolebase/vitepress-plugin-enhanced-readabilities' // [!code ++]
@@ -264,7 +264,7 @@ export default Theme
264264
Of course you can also provide the relevant configuration directly when installing the plugin:
265265

266266
```typescript twoslash
267-
import { Theme as ThemeConfig } from 'vitepress'
267+
import type { Theme as ThemeConfig } from 'vitepress'
268268
import DefaultTheme from 'vitepress/theme'
269269

270270
import type { Options } from '@nolebase/vitepress-plugin-enhanced-readabilities'
@@ -318,7 +318,7 @@ import {
318318

319319
## Configuration
320320

321-
The Reading Enhancements plugin currently provides configuration options related to **Internationalization** and **Help Tooltip**.
321+
The Enhanced Readabilities plugin currently provides configuration options related to **Internationalization** and **Help Tooltip**.
322322

323323
### Configure in VitePress
324324

@@ -329,7 +329,7 @@ Therefore we offer a way with [Vue's dependency injection](https://vuejs.org/api
329329
<!--@include: @/pages/en/snippets/details-colored-diff.md-->
330330

331331
```typescript twoslash
332-
import { Theme as ThemeConfig } from 'vitepress'
332+
import type { Theme as ThemeConfig } from 'vitepress'
333333
import DefaultTheme from 'vitepress/theme'
334334

335335
import type { Options } from '@nolebase/vitepress-plugin-enhanced-readabilities' // [!code ++]
@@ -493,16 +493,16 @@ The Enhanced Readabilities plugin does not use [vue-i18n](https://vue-i18n.intli
493493

494494
The Enhanced Readabilities plugin supports internationalization by default, with English and Simplified Chinese as supported languages by default.
495495

496-
You can override the plugin's localized text through configuration, and before you start, you need to understand how VitePress is internationalized: [Internationalization of VitePress](https://vitepress.dev/guide/i18n). The Reading Enhancement plugin reads the VitePress language field by default, so you'll need to be careful to keep the internationalized language code the same as the VitePress language code when configuring it.
496+
You can override the plugin's localized text through configuration, and before you start, you need to understand how VitePress is internationalized: [Internationalization of VitePress](https://vitepress.dev/guide/i18n). The Enhanced Readabilities plugin reads the VitePress language field by default, so you'll need to be careful to keep the internationalized language code the same as the VitePress language code when configuring it.
497497

498498
### Configure in VitePress
499499

500-
In the [Configuration](#configuration) section, we've learned how to provide configuration options for the Reading Enhancement plugin in VitePress, and we can configure internationalization by adding the `locales` field to the configuration options:
500+
In the [Configuration](#configuration) section, we've learned how to provide configuration options for the Enhanced Readabilities plugin in VitePress, and we can configure internationalization by adding the `locales` field to the configuration options:
501501

502502
<!--@include: @/pages/en/snippets/details-colored-diff.md-->
503503

504504
```typescript twoslash
505-
import { Theme as ThemeConfig } from 'vitepress'
505+
import type { Theme as ThemeConfig } from 'vitepress'
506506
import DefaultTheme from 'vitepress/theme'
507507

508508
import type { Options } from '@nolebase/vitepress-plugin-enhanced-readabilities'

0 commit comments

Comments
 (0)