diff --git a/src/models/ContributionSurveyRowParser.ts b/src/models/ContributionSurveyRowParser.ts index 7ce20211..74e9be18 100644 --- a/src/models/ContributionSurveyRowParser.ts +++ b/src/models/ContributionSurveyRowParser.ts @@ -65,9 +65,16 @@ export interface RawContributionSurveyRow { * * $1 - Revision ID * $2 - Diff size - * $3 - Bold syntax (if any; "'''"). */ diffTemplate: string; + /** + * Template to use for rebuilding the entirety of the diffs section. + * + * $1 - Diff links + * + * @default "$1" + */ + diffsTemplate?: string; } /** @@ -118,6 +125,7 @@ export default class ContributionSurveyRowParser { this.eatUntil( /^(?:'''?)?\[\[Special:Diff\/\d+/, true ) ?? // {{dif|12345|6789}} this.eatUntil( /^(?:'''?)?{{dif\|\d+/, true ); + let diffsBolded = false; // At this point, `extras` is either a string or `null`. If it's a string, // extras exist, and we should add them. If not, there's likely no more @@ -143,9 +151,18 @@ export default class ContributionSurveyRowParser { // All diff links removed. Get diff of starting and current to get entire diff part. diffs = starting.slice( 0, starting.length - this.current.length ); - // Dawkeye support. + // Pre-2014 style support. if ( ( diffs ?? '' ).includes( '{{dif' ) ) { - diffTemplate = '$3{{dif|$1|$2}}$3'; + diffTemplate = '{{dif|$1|($2)}}'; + } + + // Bolded diffs support. + if ( + diffs.slice( 0, 3 ) === "'''" && + diffs.slice( -3 ) === "'''" && + !diffs.slice( 3, -3 ).includes( "'''" ) + ) { + diffsBolded = true; } // Comments should be empty, but just in case we do come across comments. @@ -180,7 +197,8 @@ export default class ContributionSurveyRowParser { diffs, comments, revids, - diffTemplate + diffTemplate, + diffsTemplate: diffsBolded ? "'''$1'''" : '$1' }; } diff --git a/src/ui/root/DeputyContributionSurveyRow.tsx b/src/ui/root/DeputyContributionSurveyRow.tsx index 7ad74a33..6f5b6764 100644 --- a/src/ui/root/DeputyContributionSurveyRow.tsx +++ b/src/ui/root/DeputyContributionSurveyRow.tsx @@ -257,16 +257,18 @@ export default class DeputyContributionSurveyRow extends EventTarget implements ) ) ?? []; + let diffsText = ''; if ( unfinishedDiffs.length > 0 ) { - result += unfinishedDiffs.map( ( v ) => { + diffsText += unfinishedDiffs.map( ( v ) => { return mw.format( this.row.data.diffTemplate, v.revision.revid, - v.revision.diffsize > 0 ? '+' + v.revision.diffsize : v.revision.diffsize, - Math.abs( v.revision.diffsize ) > 500 ? "'''" : '' + v.revision.diffsize > 0 ? '+' + v.revision.diffsize : v.revision.diffsize ); } ).join( '' ); + result += mw.format( this.row.data.diffsTemplate, diffsText ); + if ( this.row.data.comments ) { // Comments existed despite not being finished yet. Allow anyway. result += this.row.data.comments;