dijs / infobox-parser

Parse Wikipedia Infoboxes
40 stars 18 forks source link

Unbulleted lists not parsed in most automobiles #43

Open jsilveira opened 4 months ago

jsilveira commented 4 months ago

When parsing unbulleted lists, it just returns "unbulleted list" instead of parsing the list.

For example:

const infoboxParser = require("infobox-parser")

const res = infoboxParser(`
{{Infobox automobile
| name = Infiniti QX30 (H15)
| image = 2017 Infiniti QX30 2.0t AWD front 2.10.19.jpg
| caption = Infiniti QX30 2.0t AWD (US)
| manufacturer = [[Infiniti]] ([[Nissan]])
| 
| production = 2016–2019<ref name="a">{{Cite web|url=https://www.caranddriver.com/news/a26800445/infiniti-qx30-dead-2019/|title=The Infiniti QX30 Gets the Axe as Nissan's Luxury Division Exits the Western European Market|work=[[Car and Driver]]|last=Capparella|first=Joey|date=12 March 2019|access-date=12 March 2019}}</ref>
| model_years = 2017–2019<ref name="a" />
| assembly = United Kingdom: [[Sunderland]] ([[Nissan Motor Manufacturing UK|NMUK]])<ref name="PressKit">{{cite web|title=2017 Infiniti QX30 Press Kit|date=13 July 2016 |url=http://infinitinews.com/en-US/infiniti/usa/presskits/us-2017-infiniti-qx30-press-kit}}</ref>
| designer = Hirohisa Ono (2010)<ref>{{cite web|last1=Woodward|first1=Lyn|title=10 Questions With Hirohisa Ono, Director of Infiniti Design|url=http://www.automobilemag.com/news/10-questions-hirohisa-ono-director-infiniti-design/|website=[[Automobile (magazine)|Automobile Magazine]]|date=19 April 2017 |access-date=11 October 2017}}</ref>
| class = [[Subcompact luxury crossover SUV]]
| body_style = 5-door [[SUV]]
| layout = {{unbulleted list
  | [[Front-engine, front-wheel-drive layout|Front-engine, front-wheel-drive]]
  | [[Front-engine, four-wheel-drive layout|Front-engine, all-wheel-drive]]
  }}
| platform = Modular Front Architecture<ref>[https://www.autonews.com/article/20160120/BLOG15/160129996 What Nissan learned from Mercedes for Infiniti Q30 production]</ref>
| related = {{unbulleted list
  | [[Infiniti Q30]]
  | [[Mercedes-Benz A-Class#W176|Mercedes-Benz A-Class (W176)]]
  | [[Mercedes-Benz GLA #X156|Mercedes-Benz GLA (X156)]]
  }}
| engine = {{unbulleted list
  | '''[[Petrol engine|Petrol]]:'''
  | 1.6&nbsp;L ''[[Mercedes-Benz M270/M274 engine#M270 engine|Mercedes-Benz M270]]'' [[Inline-four engine|I4]]-[[Turbocharger|T]]
  | 2.0&nbsp;L ''[[Mercedes-Benz M270/M274 engine#M270 engine|Mercedes-Benz M270]]'' I4-T
  | '''[[Diesel engine|Diesel]]:'''
  | 2.2&nbsp;L ''[[Mercedes-Benz OM651 engine|Mercedes-Benz OM651]]'' I4-T
  }}
| transmission = 7-speed [[Automatic transmission|automatic]]
| wheelbase = {{convert|2700|mm|in|1|abbr=on}}<ref name="PressKit" />
| length = {{convert|4425|mm|in|1|abbr=on}}
| width = {{convert|1815|mm|in|1|abbr=on}}
| height = {{convert|1470|–|1530|mm|in|1|abbr=on}}
| weight = {{convert|1490|–|1530|kg|lb|0|abbr=on}}
| sp = uk
}}`);

res.general.engine; // "unbulleted list"
jsilveira commented 4 months ago

After inspecting the code, I think the issue is that there is unexpected whitespace before the list items.

The fix seems as easy as changing the \s? for \s* to allow any number of whitespaces:

- const unbulletedListGlobalPattern = /\{\{(?:unbulleted list|ubl|ubt|ublist|unbullet)\s?\|([^\}\}]+)\}\}/gi;
+ const unbulletedListGlobalPattern = /\{\{(?:unbulleted list|ubl|ubt|ublist|unbullet)\s*\|([^\}\}]+)\}\}/gi;