Configuration
The Inline Links Previewing plugin currently provides configuration options related to Internationalization and Popup.
Configure in VitePress
Since VitePress doesn't provide more functionality for the default theme to extend the default theme configuration, it is not friendly to the type checking and maintenance of the configuration if we directly modify the major VitePress configuration object to provide options for the plugin.
Therefore we offer a way with Vue's dependency injection to provide options and configuration for the plugin:
If you've never seen a colored diff before
This is a markup rule for displaying diff in the user interface (UI).
Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.
Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.
To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation
import type { as ThemeConfig } from 'vitepress'
import from 'vitepress/theme'
import { } from '@nolebase/vitepress-plugin-inline-link-preview/client'
export const : ThemeConfig = {
: ,
: () => {
// Rest of the code...
},
({ }) {
// Rest of the code...
.(, {
// Configuration...
})
// Rest of the code...
},
}
For more information on internationalization configuration, see Internationalization.
Options inside
Complete configurable options
/**
* Options
*/
export interface Options {
/**
* The width and height of the popup of link preview
*/
?: number
/**
* The height of the popup of link preview
*/
?: number
/**
* Toggle previewAllHostNames to true to preview all host names.
* When set to true, all the other options related to host names will be ignored, including
* `handleShouldPreviewHostNames` option.
*
* @default false
*/
?: boolean
/**
* Toggle `previewLocalHostName` to true to preview local (deployed location, or `window.location.host`) host name.
*
* @default true
*/
?: boolean
/**
* The host names allowed to be previewed.
* When specified, only the host names in this array that exact matched will be previewed.
*
* @default []
*/
?: string[]
/**
* The host names blocked to be previewed.
* When specified, the host names in this array will that exact matched not be previewed.
*
* @default []
*/
?: string[]
/**
* Programmatically handle whether the host name should be previewed.
* When specified, this function will be called to determine whether the host name should be previewed and before the `previewHostNamesAllowed` and `previewHostNamesBlocked` options.
*
* @param href The href of the link
* @returns Whether the host name should be previewed
* @default undefined
*/
?: (: string) => boolean
/**
* The selectors of the elements to be hided inside of the iframe when the popup is opened.
* This is useful when you have a lot of classes of customized elements that you don't want to be shown in the popup.
*/
?: string[]
/**
* Programmatically handle the iframe loaded event, you can use this handling function
* to programmatically change the iframe content inside, e.g. add a class to the body element.
* or hide some elements inside of the iframe.
*
* @param hostWindow The window object of the host window
* @param element The iframe element
* @returns Either a Promise that resolves when the handling is done or plain void
* @default undefined
*/
?: (: Window, : HTMLIFrameElement) => <void> | void
/**
* The selector of the element to be used as the teleport target of the popup.
* By default, the popup will be appended to the body element since VitePress supports to
* teleport elements to the body element only currently.
*
* @default 'body'
*/
?: string
/**
* The delay of the popup after the mouse enter event of the link.
*
* @default 1000
*/
?: number
/**
* Internationalization options
*
* @example { 'zh-CN': { popup: { loading: '加载中...', loadingAriaLabel: '加载中' } }
*/
?: <string, Locale>
}
Internationalization
Caution
The Inline Links Previewing plugin does not use vue-i18n as an i18n toolkit since most of VitePress probably uses VitePress's internationalization features for internationalization, so it is impossible to override the fields of the localized text of the Inline Links Previewing plugin with vue-i18n
, but you can achieve it with the locales
field in Configuration.
The same as other VitePress plugins, Inline Links Previewing plugin supports internationalization by default, with English and Simplified Chinese as supported languages.
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. The Inline Links Previewing 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.
Configure in VitePress
In the Configuration section, we've learned how to provide configuration options for the Inline Links Previewing plugin in VitePress, and we can configure internationalization by adding the locales
field to the configuration options:
If you've never seen a colored diff before
This is a markup rule for displaying diff in the user interface (UI).
Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.
Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.
To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation
import type { as ThemeConfig } from 'vitepress'
import from 'vitepress/theme'
import { } from '@nolebase/vitepress-plugin-inline-link-preview/client'
// Rest of code...
export const : ThemeConfig = {
: ,
: () => {
// Rest of code...
},
({ }) {
// Rest of code...
.(, {
: { // i18n
'zh-CN': { // configure for Simplified Chinese
: {
: '加载中...',
: '加载中',
}
},
'en': { // configure for English
: {
: 'Loading...',
: 'Loading',
}
}
}
})
// Rest of code...
},
}
Locales options
Complete internationalization field options
/**
* Locale
*/
interface Locale {
/**
* Popup options
*/
?: {
/**
* The text to be shown when the popup is loading
*/
?: string
/**
* The aria-label of the popup when the popup is loading
*/
?: string
/**
* The text to be shown when the popup is failed to load
*/
?: string
/**
* The aria-label of the popup when the popup is failed to load
*/
?: string
/**
* The aria-label of the iframe popup
*/
?: string
}
}
Accessibility
The Inline Links Previewing plugin provides accessibility support by default. You can override accessible labels (aria-label) via Configuration in the same way as Internationalization, see Locales Options for a description of what labels can be configured for accessibility.
More customizations?
It is possible though.
Caution
Configure on your own is for those who know and understand what they are doing. If you don't know what you are doing or encounter problems during configuration, please read and follow the Integrate with VitePress section.
The Inline Links Previewing plugin exports the components it uses internally, so if you don't like the style and encapsulation of the default components, you can always create your own components and use them instead.
Install as a Vue plugin
import {
} from '@nolebase/vitepress-plugin-inline-link-preview/client'
If you are working on a VitePress and wanted to install it into Vue instance, you can do it like this:
import type { as ThemeConfig } from 'vitepress'
import from 'vitepress/theme'
import { } from '@nolebase/vitepress-plugin-inline-link-preview/client'
// Rest of the code...
export const : ThemeConfig = {
: ,
: () => {
// Rest of the code...
},
({ }) {
.()
},
}
export default
Import popup iframe wrapper components on demand
import {
,
} from '@nolebase/vitepress-plugin-inline-link-preview/client'
After configured the plugin or component, you will need to customize how the markdown-it
plugin transforms the []()
link markup or <a>
elements into your custom components instead of the default ones.
Customize the markdown-it
plugin
import { } from 'vitepress'
import {
,
} from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
export default ({
: 'en',
: 'Site Name',
: {
// rest of the options...
},
: {
() {
// other markdown-it configurations...
.(, { : 'YourComponentName' })
}
}
})