@@ -139,29 +139,45 @@ const ROUTE_FILES = ['page.tsx', 'page.ts', 'route.tsx', 'route.ts']
139139const COUNT_CLAIM = / \b ( \d { 1 , 3 } (?: , \d { 3 } ) + | \d + ) \+ ? \s + ( i n t e g r a t i o n s | a c t i o n s | t r i g g e r s ) \b / gi
140140/** Inline emphasis and code markers, which would otherwise split "**1,000+** integrations". */
141141const INLINE_MARKERS = / \* \* | _ _ | [ * ` ] / g
142+ /** A Markdown link, read as its visible text so "[Zapier](https://zapier.com)'s" names Zapier. */
143+ const LINK_TEXT = / \[ ( [ ^ \] \n ] * ) \] \( [ ^ ) \n ] * \) / g
144+ /** List, heading, and quote markers, or a quoted YAML key such as `a: "`, ahead of the sentence. */
145+ const LINE_PREFIX = / ^ \s * (?: (?: [ - * + > ] | \d + [ . ) ] | # { 1 , 6 } ) \s + ) * (?: \w + : \s * [ " ' ] ) ? /
142146const SIM_NAME = / \b S i m \b /
143- /** A table row's label cell naming Sim, plain or linked: "Sim" or "[Sim](https://www.sim.ai)". */
144- const SIM_LABEL = / ^ \[ ? S i m \b /
145- /** Words that turn a sentence toward another product: "while Zapier lists...", "Unlike Sim, ...". */
147+ /** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
146148const CONTRAST = String . raw `(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
147- /** A sentence end, or a contrast that hands the rest of the sentence to another subject. */
148- const CLAUSE_BREAK = new RegExp ( String . raw `(?<=[.!?;:])\s+|,?\s+${ CONTRAST } \s+` , 'i' )
149- /** An opening comparison ("Unlike Sim, ...", "Like Sim, ...") whose main clause is about another product. */
150- const LEADING_CONTRAST = new RegExp ( String . raw `^(?:like|${ CONTRAST } )\b[^,]*,\s*` , 'i' )
149+ /** A comparison set off by commas inside a sentence, as in "Sim, unlike Zapier, has ...". */
150+ const PARENTHETICAL_COMPARISON = new RegExp ( String . raw `,\s+(?:like|${ CONTRAST } )\s+[^,\d]*,` , 'gi' )
151+ /**
152+ * A sentence end, a contrast that hands the rest of the sentence to another subject, or a
153+ * relative clause about a product other than Sim ("Zapier, which has ...").
154+ */
155+ const CLAUSE_BREAK = new RegExp (
156+ String . raw `(?<=[.!?;])\s+|,?\s+${ CONTRAST } \s+|(?<!\bSim),\s+(?:which|who)\s+` ,
157+ 'i'
158+ )
159+ /** An opening comparison ("Unlike Sim, ...") whose main clause is about another product. */
160+ const LEADING_COMPARISON = new RegExp ( String . raw `^(?:like|${ CONTRAST } )\b[^,]*,\s*` , 'i' )
151161/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
152162const POSSESSIVE_OWNER = / ( [ \w . - ] + ) [ ' ’ ] s \s * $ /
153163/** A Sim count below this share of the catalog total is left from an older catalog. */
154164const SIM_COUNT_FLOOR = 0.9
155165
156166/** Every count in a table row whose first cell names Sim. */
157167function simTableRowCounts ( row : string ) : RegExpMatchArray [ ] {
158- return SIM_LABEL . test ( row . split ( '|' ) [ 1 ] ?. trim ( ) ?? '' ) ? [ ...row . matchAll ( COUNT_CLAIM ) ] : [ ]
168+ return SIM_NAME . test ( row . split ( '|' ) [ 1 ] ?. trim ( ) . split ( / \s / ) [ 0 ] ?? '' )
169+ ? [ ...row . matchAll ( COUNT_CLAIM ) ]
170+ : [ ]
159171}
160172
161173/** Each count whose clause names Sim before it, unless another product's possessive owns it. */
162174function simProseCounts ( text : string ) : RegExpMatchArray [ ] {
163- return text . split ( CLAUSE_BREAK ) . flatMap ( ( sentence ) => {
164- const clause = sentence . replace ( LEADING_CONTRAST , '' )
175+ const sentences = text
176+ . replace ( LINE_PREFIX , '' )
177+ . replace ( PARENTHETICAL_COMPARISON , '' )
178+ . split ( CLAUSE_BREAK )
179+ return sentences . flatMap ( ( sentence ) => {
180+ const clause = sentence . replace ( LEADING_COMPARISON , '' )
165181 return [ ...clause . matchAll ( COUNT_CLAIM ) ] . filter ( ( match ) => {
166182 const before = clause . slice ( 0 , match . index )
167183 const owner = POSSESSIVE_OWNER . exec ( before ) ?. [ 1 ]
@@ -172,7 +188,7 @@ function simProseCounts(text: string): RegExpMatchArray[] {
172188
173189/** The counts on one line of text that belong to Sim, with the claim as written. */
174190function simCountClaims ( line : string ) : { claim : string ; count : number ; unit : SimCountUnit } [ ] {
175- const text = line . replace ( INLINE_MARKERS , '' )
191+ const text = line . replace ( INLINE_MARKERS , '' ) . replace ( LINK_TEXT , '$1' )
176192 const matches = text . trimStart ( ) . startsWith ( '|' ) ? simTableRowCounts ( text ) : simProseCounts ( text )
177193 return matches . map ( ( match ) => ( {
178194 claim : match [ 0 ] ,
0 commit comments