koishi-plugin-mediawiki-fix 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +10 -7
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -271,13 +271,14 @@ var PluginMediawiki = class {
271
271
  const label = escapeMarkdownText(text);
272
272
  if (!this.config.enableQQInlineCmd) return `\`${label}\``;
273
273
  const commandText = this.getCommandText(session, command);
274
- return ` [${label}](mqqapi://aio/inlinecmd?command=${encodeURIComponent(commandText)}&enter=true&reply=false)`;
274
+ return ` [${label}](mqqapi://aio/inlinecmd?command=${encodeURIComponent(commandText)}&enter=true&reply=false) `;
275
275
  }
276
- formatAutoFillWikilink(session, title, text) {
276
+ formatAutoFillWikilink(session, title, text, missing = false) {
277
277
  const label = escapeMarkdownText(text);
278
- if (!this.config.enableQQInlineCmd) return label;
278
+ const display = missing ? `${label} (未创建)` : label;
279
+ if (!this.config.enableQQInlineCmd) return display;
279
280
  const commandText = `[[${title}]]`;
280
- return ` [${label}](mqqapi://aio/inlinecmd?command=${encodeURIComponent(commandText)}&enter=false&reply=false)`;
281
+ return ` [${display}](mqqapi://aio/inlinecmd?command=${encodeURIComponent(commandText)}&enter=false&reply=false) `;
281
282
  }
282
283
  formatLink(text, url) {
283
284
  return ` [${escapeMarkdownText(text)}](${url})`;
@@ -305,13 +306,15 @@ var PluginMediawiki = class {
305
306
  }
306
307
  convertHtmlExtractToMarkdown(session, mwApi, extract) {
307
308
  const replaced = extract.replace(
308
- /<a\b[^>]*href="([^"]+)"[^>]*>(.*?)<\/a>/gis,
309
- (_, href, inner) => {
309
+ /<a\b([^>]*)href="([^"]+)"([^>]*)>(.*?)<\/a>/gis,
310
+ (_, beforeHref, href, afterHref, inner) => {
310
311
  const text = decodeHtmlEntities(inner.replace(/<[^>]+>/g, "")).trim();
311
312
  if (!text) return "";
313
+ const attrs = `${beforeHref} ${afterHref}`;
314
+ const isMissing = /\bnew\b/i.test(attrs) || /(?:\?|&)redlink=1\b/i.test(href);
312
315
  const wikiTitle = this.resolveWikiTitleFromHref(mwApi, href);
313
316
  if (wikiTitle) {
314
- return this.formatAutoFillWikilink(session, wikiTitle, text);
317
+ return this.formatAutoFillWikilink(session, wikiTitle, text, isMissing);
315
318
  }
316
319
  try {
317
320
  return this.formatLink(text, new URL(href, getUrl(mwApi)).href);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-mediawiki-fix",
3
3
  "description": "Koishi.js 的 MediaWiki 插件,将您的群聊与 wiki 站点紧密连接!(修复版)",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [