一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
33 行
1.3 KiB
TypeScript
33 行
1.3 KiB
TypeScript
// This rule is used to add a media player for certain resource types below
|
|
// the link.
|
|
|
|
import { LinkRenderingType, RuleOptions } from '../../MdToHtml';
|
|
import renderMedia, { Options as RenderMediaOptions } from '../renderMedia';
|
|
import type * as MarkdownIt from 'markdown-it';
|
|
import type Token = require('markdown-it/lib/token');
|
|
import type Renderer = require('markdown-it/lib/renderer');
|
|
|
|
|
|
export interface LinkIndexes {
|
|
[key: string]: number;
|
|
}
|
|
|
|
function plugin(markdownIt: MarkdownIt, ruleOptions: RuleOptions) {
|
|
const defaultRender: Renderer.RenderRule = markdownIt.renderer.rules.link_close || function(tokens, idx, options, _env, self) {
|
|
return self.renderToken(tokens, idx, options);
|
|
};
|
|
|
|
const linkIndexes: LinkIndexes = {};
|
|
|
|
markdownIt.renderer.rules.link_close = function(tokens: Token[], idx: number, options: MarkdownIt.Options, env: unknown, self: Renderer) {
|
|
const defaultOutput = defaultRender(tokens, idx, options, env, self);
|
|
const link = ruleOptions.context.currentLinks.pop();
|
|
|
|
if (!link || ruleOptions.plainResourceRendering || (ruleOptions.linkRenderingType === LinkRenderingType.HrefHandler && !ruleOptions.renderMedia)) return defaultOutput;
|
|
|
|
return [defaultOutput, renderMedia(link, ruleOptions as RenderMediaOptions, linkIndexes)].join('');
|
|
};
|
|
}
|
|
|
|
export default { plugin };
|