2020-11-05 18:58:23 +02:00
|
|
|
import { RuleOptions } from '../../MdToHtml';
|
2020-11-20 18:04:47 +02:00
|
|
|
import linkReplacement from '../linkReplacement';
|
|
|
|
import utils from '../../utils';
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
const urlUtils = require('../../urlUtils.js');
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function plugin(markdownIt: any, ruleOptions: RuleOptions) {
|
|
|
|
markdownIt.renderer.rules.link_open = function(tokens: any[], idx: number) {
|
2020-01-30 23:05:23 +02:00
|
|
|
const token = tokens[idx];
|
2020-11-20 18:04:47 +02:00
|
|
|
const href = utils.getAttr(token.attrs, 'href');
|
2020-01-30 23:05:23 +02:00
|
|
|
const resourceHrefInfo = urlUtils.parseResourceUrl(href);
|
2020-07-15 00:27:12 +02:00
|
|
|
const isResourceUrl = ruleOptions.resources && !!resourceHrefInfo;
|
2020-11-20 18:04:47 +02:00
|
|
|
const title = utils.getAttr(token.attrs, 'title', isResourceUrl ? '' : href);
|
|
|
|
|
|
|
|
return linkReplacement(href, {
|
|
|
|
title,
|
|
|
|
resources: ruleOptions.resources,
|
|
|
|
ResourceModel: ruleOptions.ResourceModel,
|
|
|
|
linkRenderingType: ruleOptions.linkRenderingType,
|
|
|
|
plainResourceRendering: ruleOptions.plainResourceRendering,
|
|
|
|
postMessageSyntax: ruleOptions.postMessageSyntax,
|
|
|
|
enableLongPress: ruleOptions.enableLongPress,
|
|
|
|
});
|
2020-01-30 23:05:23 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
export default { plugin };
|