parser: poe markup in name lines

This commit is contained in:
Alexander Drozdov
2021-02-05 20:33:11 +02:00
parent 6106923021
commit b70afd0e28
+17 -2
View File
@@ -189,8 +189,8 @@ function parseNamePlate (section: string[]) {
const item: ParsedItem = {
rarity,
name: section[1].replace(/^(<<.*?>>|<.*?>)+/, ''), // Item from chat "<<set:MS>><<set:M>><<set:S>>Beast Grinder"
baseType: section[2]?.replace(/^(<<.*?>>|<.*?>)+/, ''),
name: markupConditionParser(section[1]),
baseType: (section.length >= 3) ? markupConditionParser(section[2]) : undefined,
props: {},
isUnidentified: false,
isCorrupted: false,
@@ -651,3 +651,18 @@ function parseHeistMission (section: string[], item: ParsedItem) {
return SECTION_PARSED
}
function markupConditionParser (text: string) {
// ignores state set by <<set:__>>
// always evaluates first condition to true <if:__>{...}
// full markup: https://gist.github.com/SnosMe/151549b532df8ea08025a76ae2920ca4
text = text.replace(/<<set:.+?>>/g, '')
text = text.replace(/<(if:.+?|elif:.+?|else)>{(.+?)}/g, (_, type: string, body: string) => {
return type.startsWith('if:')
? body
: ''
})
return text
}