Displaying HTML entities

Posted by AdInfinitum on Wed 09 May 2018 03:13 AM — 9 posts, 32,653 views.

#0
I'm attempting to convert a script from an old client to MUSHclient, and part of that script uses MXP to display things like headers and paragraph breaks using <h1> and <p>.

I know MUSHclient can use MXP, but how can I get it to display things as an HTML page would? For example, if I had:

<h2>Title</h2>


I'd want that "Title" to be at a size 2 header. Is this possible, or do I need to seek an alternate way of doing so?
Australia Forum Administrator #1

No, MUSHclient does not support rich text in the output window. The best you could do is make text bold/italic etc. And there are already MXP elements to do that. See here for what MUSHclient supports.

#2
Okay, that explains a bit then. h# seems to be supported, according to the page, but all it does is return the <bold> element instead, which I can understand.

How would I go about displaying these MXP elements, however? For instance, I have a code that displays a calendar, and I want it to display the current day in bold. I've not figured that out yet.
Australia Forum Administrator #3
AdInfinitum said:

How would I go about displaying these MXP elements, however?


I don't quite understand that question.
#4
Nick Gammon said:

AdInfinitum said:

How would I go about displaying these MXP elements, however?


I don't quite understand that question.


Well, forgive my ignorance with MXP, because it's a new project to tackle.

What I'm trying to figure out is of the MXP elements that are available to MUSH, how would I go about using them if, for instance, I wanted to make a certain text bold? I know that I can't do something like:

Note("<bold>Test</bold>")


because that doesn't work. I realize I can use NoteStyle for that particular instance, but I was under the impression that I could use the actual bold tags somehow to produce output. Am I wrong?
Australia Forum Administrator #5
Oh I see. MXP is really intended to be interpreted from the server, not when you just display notes in the output window.

For doing it client-side, see, for example:

Template:function=NoteStyle
NoteStyle

The documentation for the NoteStyle script function is available online. It is also in the MUSHclient help file.



You can also use ColourNote to do different colours.

Template:function=ColourNote
ColourNote

The documentation for the ColourNote script function is available online. It is also in the MUSHclient help file.

#6
Fair enough. I wasn't sure if it worked the same way CMUD did with MXP. I was hoping there was something like an MXPDisplay("<color = red><b>Testing</b></color>") to display a bold Testing in red.

I think it's mainly because to me, it's easier to remember rather than remembering NoteStyle(5) is bold italic, etc. Thanks for the explanations!
Australia Forum Administrator #7
You can make a simple coloured-line displayer. For example see this thread:

http://www.gammon.com.au/forum/?id=9529


To round that out to actually display them I take the code from reply #8 and add a display function:


-- copied from http://www.gammon.com.au/forum/?id=8947
local BLACK = 1
local RED = 2
local GREEN = 3  
local YELLOW = 4 
local BLUE = 5 
local MAGENTA = 6 
local CYAN = 7 
local WHITE = 8

-- colour styles (eg. @r is normal red, @R is bold red)

-- @- is shown as ~
-- @@ is shown as @

-- This table uses the colours as defined in the MUSHclient ANSI tab, however the
-- defaults are shown on the right if you prefer to use those.
local colour_conversion = {
   k = GetNormalColour (BLACK)   ,   -- 0x000000 
   r = GetNormalColour (RED)     ,   -- 0x000080 
   g = GetNormalColour (GREEN)   ,   -- 0x008000 
   y = GetNormalColour (YELLOW)  ,   -- 0x008080 
   b = GetNormalColour (BLUE)    ,   -- 0x800000 
   m = GetNormalColour (MAGENTA) ,   -- 0x800080 
   c = GetNormalColour (CYAN)    ,   -- 0x808000 
   w = GetNormalColour (WHITE)   ,   -- 0xC0C0C0 
   K = GetBoldColour   (BLACK)   ,   -- 0x808080 
   R = GetBoldColour   (RED)     ,   -- 0x0000FF 
   G = GetBoldColour   (GREEN)   ,   -- 0x00FF00 
   Y = GetBoldColour   (YELLOW)  ,   -- 0x00FFFF 
   B = GetBoldColour   (BLUE)    ,   -- 0xFF0000 
   M = GetBoldColour   (MAGENTA) ,   -- 0xFF00FF 
   C = GetBoldColour   (CYAN)    ,   -- 0xFFFF00 
   W = GetBoldColour   (WHITE)   ,   -- 0xFFFFFF 
   
   -- add custom colours here

  }  -- end conversion table


-----------
-- our code:  :)

local P, C, Ct, Cs, Cg, S, Cc = lpeg.P, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Cg, lpeg.S, lpeg.Cc

local tmpcolorkeys = {}
for k,v in pairs(colour_conversion) do tmpcolorkeys[#tmpcolorkeys+1] = k end

local Colors = P"@" * C(S( table.concat(tmpcolorkeys, "") ))
tmpcolorkeys = nil  -- Clean up on aisle tempvar!
local NotAt = P(1) - P"@"
local NotAColor = P(1) - Colors
local text = Cg(Cs( (NotAt + P"@-"/"~" + P"@@"/"@" + NotAColor )^1 ),"text") 
local color = Cg( (Colors + Cc('w')) / colour_conversion ,"textcolour") 
local res = Ct( Ct( color * text)^1) 


function ShowStyledLine (s)
 local styles = res:match(s)
  for k, v in ipairs (t) do
    ColourTell (RGBColourToName (v.textcolour), "", v.text)
  end -- for each style run
  print ()  -- finish off the line
end -- ShowStyledLine 


If you put that into your script file (language: Lua) then you can display colours like this using the same syntax that Aardwolf does:


ShowStyledLine ("an @RAardwolf @WAdventurer's Guide@w (type @Rread guide@w)")


Then you just use things like @R for bold red, and @r for normal red, and so on as you can see in the script near the top.
Amended on Wed 09 May 2018 08:32 PM by Nick Gammon
USA Global Moderator #8
If this is actually for Aardwolf, functions like that are already built https://github.com/fiendish/aardwolfclientpackage/wiki/Color-Functions