Thread Tools Display Modes
01-31-17, 10:39 AM   #1
Oniya
A Wyrmkin Dreamwalker
Join Date: Feb 2015
Posts: 57
Question Get pure text from formated text from lua

Strings from wow api, for example class hall talents description, sometimes contained already formatted text:

Enables the Vengeful Retreat ability for all missions, which increases success chance of missions with |C00b3ffffMinions|R by 10%.
Newly recruited Illidari Adepts become Transformed Illidari Adepts which gain:

|TInterface\ICONS\ABILITY_WARLOCK_SHADOWFURYTGA.BLP:20:20:0:0|t |CffffffffDemon Form|R
Increases success chance of missions with |C00b3ffffMinions|R or |C00b3ffffHazards|R by 15%.
Is there a way to get pure text from it without formatting? Maybe there is some built-in function i not aware about. To get from it like:

Enables the Vengeful Retreat ability for all missions, which increases success chance of missions with Minions by 10%.
Newly recruited Illidari Adepts become Transformed Illidari Adepts which gain: Demon Form.
Increases success chance of missions with Minions or Hazards by 15%.
  Reply With Quote
01-31-17, 04:57 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
Lua contains string pattern matching functions that could easily strip out the UI escape tags shown.
Lua Code:
  1. local EscapePatterns={
  2.     "|[cC]%x%x%x%x%x%x";
  3.     "|T[^|]+|t";
  4.     "|H[^|]+|h%[(.-)%]|h";
  5. };
  6.  
  7. local function StripEscapes(str)
  8.     for _,pattern in ipairs(EscapePatterns) do
  9.         str=str:gsub(pattern,pattern:find("%(.-[^%%]%)") and "%1" or "");
  10.     end
  11.     return str:gsub("^%s*(.-)%s*$","%1"):gsub("%s+"," ");-- Strip extra spaces
  12. end
This is expandable so we can add more patterns later. Just put them in the EscapePatterns table.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
01-31-17, 05:00 PM   #3
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
I also remember some workaround to set the text on a frame and get it back again
Lua Code:
  1. local b = CreateFrame("Button")
  2.  
  3. local function PlainText(s)
  4.     return b:GetText(b:SetText(s))
  5. end
Edit: nvm, only seems to work for the ui escape sequences with format strings :s
http://www.wowinterface.com/forums/s...php?t=36884#12

Last edited by Ketho : 01-31-17 at 06:06 PM.
  Reply With Quote
02-09-17, 01:18 PM   #4
Oniya
A Wyrmkin Dreamwalker
Join Date: Feb 2015
Posts: 57
Thank you both! I will try out! <3
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Get pure text from formated text from lua

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off