Skip to content

Commit

Permalink
Merge branch 'mini' into browser
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Jun 4, 2024
2 parents bc370a8 + 3953c51 commit fa617dd
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 37 deletions.
42 changes: 21 additions & 21 deletions bundle/bundle.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions extensions/dist/gh-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const keys = new Set(['type', 'childNodes', 'range']);
var _a;
const entries = Object.entries(ast).filter(([key]) => !keys.has(key)), dl = document.createElement('dl'), dt = document.createElement('dt'), childNodes = document.createElement('dd'), dds = entries.map(([key, value]) => {
const dd = document.createElement('dd'), code = document.createElement('code');
code.textContent = typeof value === 'string' ? `"${value.replace(/[\\"]/gu, '\\$&')}"` : String(value);
code.textContent = typeof value === 'string'
? `"${value.replace(/[\\"]/gu, String.raw `\$&`)}"`
: String(value);
code.className = typeof value;
dd.textContent = `${key}: `;
dd.append(code);
Expand Down Expand Up @@ -190,9 +192,9 @@ const keys = new Set(['type', 'childNodes', 'range']);
for (const button of buttons.slice(0, -1)) {
button.addEventListener('click', switchTab);
}
const hashchange = () => {
const hashchange = (e) => {
var _a;
(_a = buttons.find(({ value }) => value === location.hash.slice(1))) === null || _a === void 0 ? void 0 : _a.click();
(_a = buttons.find(({ value }) => value === (location.hash.slice(1) || e === undefined && 'editor'))) === null || _a === void 0 ? void 0 : _a.click();
};
hashchange();
window.addEventListener('hashchange', hashchange);
Expand Down
9 changes: 6 additions & 3 deletions extensions/gh-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ const keys = new Set(['type', 'childNodes', 'range']);
button.addEventListener('click', switchTab);
}

/** hashchange事件处理 */
const hashchange = (): void => {
buttons.find(({value}) => value === location.hash.slice(1))?.click();
/**
* hashchange事件处理
* @param e 事件
*/
const hashchange = (e?: HashChangeEvent): void => {
buttons.find(({value}) => value === (location.hash.slice(1) || e === undefined && 'editor'))?.click();
};
hashchange();
window.addEventListener('hashchange', hashchange);
Expand Down
14 changes: 12 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ declare interface Parser extends ParserBase {
* @param include 是否嵌入
*/
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config): Title;
/** @private */
normalizeTitle(
title: string,
defaultNs?: number,
include?: boolean,
config?: Config,
halfParsed?: boolean,
decode?: boolean,
selfLink?: boolean, // eslint-disable-line @typescript-eslint/unified-signatures
): Title;

parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
}
Expand Down Expand Up @@ -53,8 +63,8 @@ const Parser: Parser = {
include?: boolean,
config = Parser.getConfig(),
halfParsed?: boolean,
decode = false,
selfLink = false,
decode: boolean = false,
selfLink: boolean = false,
) {
const {Title}: typeof import('./lib/title') = require('./lib/title');
if (halfParsed) {
Expand Down
1 change: 0 additions & 1 deletion parser/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const parseLinks = (wikitext: string, config: Config, accum: Token[]): st
s += `[[${x}`;
continue;
}
// @ts-expect-error private arguments
const title = Parser.normalizeTitle(link, 0, false, config, true, true, true),
{ns, valid, interwiki} = title;
if (!valid) {
Expand Down
1 change: 0 additions & 1 deletion parser/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const parseRedirect = (text: string, config: Config, accum: Token[]): str
config.redirection.join('|')
})\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)`, 'iu'),
mt = re.exec(text);
// @ts-expect-error private arguments
if (mt && Parser.normalizeTitle(mt[3]!, 0, false, config, true, true).valid) {
text = `\0${accum.length}c\x7F${text.slice(mt[0].length)}`;
// @ts-expect-error abstract class
Expand Down
1 change: 0 additions & 1 deletion src/imageParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function validate(
} else if (value.startsWith('[[') && value.endsWith(']]')) {
value = value.slice(2, -2);
}
// @ts-expect-error private arguments
const title = Parser.normalizeTitle(value, 0, false, config, halfParsed, true, true);
return title.valid && title;
}
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ export class Token extends AstElement {
decode?: boolean,
selfLink?: boolean,
): Title {
// @ts-expect-error private arguments
return Parser.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
}

Expand Down
3 changes: 1 addition & 2 deletions src/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export abstract class TableToken extends TrBaseToken {
} else if (max < high) {
high = max;
}
const {colspan} = this.getNthCell(row[row.length - 1]!)!,
min = max - colspan + 1;
const min = row.indexOf(row[max - 1]!) + 1;
if (min > high) {
break;
} else if (min > low) {
Expand Down
9 changes: 8 additions & 1 deletion src/table/td.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? numb
export abstract class TdToken extends TableBaseToken {
override readonly type = 'td';
#innerSyntax = '';
#syntax: TdSyntax | undefined;

declare readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
abstract override get parentNode(): TrToken | TableToken | undefined;
Expand Down Expand Up @@ -83,6 +84,12 @@ export abstract class TdToken extends TableBaseToken {

/** 表格语法信息 */
#getSyntax(): TdSyntax {
this.#syntax ??= this.#computeSyntax();
return this.#syntax;
}

/** 表格语法信息 */
#computeSyntax(): TdSyntax {
const syntax = this.firstChild.text(),
char = syntax.slice(-1);
let subtype: TdSubtypes = 'td';
Expand All @@ -97,7 +104,7 @@ export abstract class TdToken extends TableBaseToken {
};
}
const {previousSibling} = this;
const result = (previousSibling as TdToken).#getSyntax();
const result = {...(previousSibling as TdToken).#getSyntax()};
return result;
}

Expand Down
5 changes: 4 additions & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const title = process.argv[2]?.toLowerCase();
for (const file of fs.readdirSync(path.join(__dirname, '..', '..', 'wiki'))) {
const lcFile = file.toLowerCase();
if (file.endsWith('.md') && (!title || (title.endsWith('.md') ? lcFile === title : lcFile.includes(title)))) {
info(file);
const md = fs.readFileSync(path.join(__dirname, '..', '..', 'wiki', file), 'utf8');
let logging = true;
// eslint-disable-next-line es-x/no-string-prototype-matchall, es-x/no-regexp-lookbehind-assertions
for (const [code] of md.matchAll(/(?<=```js\n).*?(?=\n```)/gsu)) {
const lines = code.split('\n') as [string, ...string[]],
Expand All @@ -23,6 +23,9 @@ for (const file of fs.readdirSync(path.join(__dirname, '..', '..', 'wiki'))) {
first.endsWith(' (main)') || /^\/\/ (?:config|i18n)(?!\S)/u.test(first)
) {
continue;
} else if (logging) {
info(file);
logging = false;
}
try {
Parser.i18n = undefined;
Expand Down

0 comments on commit fa617dd

Please sign in to comment.