Yet another ManiaPlanet style javascript parser

Moderators: Xymph, NADEO

Post Reply
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Yet another ManiaPlanet style javascript parser

Post by zocka » 02 Jun 2016, 12:01

Unfortunately magnetik's script didn't work for me, so I made my own version:
https://github.com/PRGfx/maniaplanet-style-parser/

EDIT: now a npm-module: https://www.npmjs.com/package/zocka-man ... -formatter

It just produces html from the ManiaPlanet text input, optionally omitting given tags to ensure a homogenous type face:

Code: Select all

MPStyle(input, {stripTags: ['w', 'n']})
Optionally it can set classes instead of inline styles, so you can do a custom styling.
Last edited by zocka on 21 Jan 2017, 23:03, edited 1 time in total.
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

User avatar
magnetik
Nadeo
Nadeo
Posts: 1643
Joined: 01 Feb 2012, 19:13
Location: Paris
Contact:

Re: Yet another ManiaPlanet style javascript parser

Post by magnetik » 02 Jun 2016, 13:02

:thumbsup:

By curiosity, what's not working ? I've not watched it for a long time, it might require an update
ManiaPlanet technical documentation portal (Dedicated, ManiaLink, ManiaScript, Titles...) -- contribute!

User avatar
toffe
Posts: 660
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: Yet another ManiaPlanet style javascript parser

Post by toffe » 02 Jun 2016, 17:24

I think it would be great to make a universal js parser, for both Node and browser.
It's already in the planning to be made by me at some time to include it in the ManiaJS project. (Not for HTML rendering but more for like stripping styles and stuff).

With a universe project you are able to generate browser .js and node package (npm) from a single source with some build tools (grunt/gulp) and browserify for example.

Edit: Maybe it would be nice to make one single topic with all the style parsers in all languages. This would be better for the overview.

Toffe

zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: Yet another ManiaPlanet style javascript parser

Post by zocka » 02 Jun 2016, 21:24

Links don't stop properly. I'm not sure about other features, but it is pretty obvious if the whole rest of your text is blue and underlined ;)
I had some maniaflash messages with multiple $(l|h)[...] links and although the link text ends properly with $l/$h, everything until the next link was turned into an anchor tag.
Another thing is that $h tags are missing any protocol, most likely resulting in relative HTTP URLs.

I like the idea of a list of available implementations :thumbsup:
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

User avatar
magnetik
Nadeo
Nadeo
Posts: 1643
Joined: 01 Feb 2012, 19:13
Location: Paris
Contact:

Re: Yet another ManiaPlanet style javascript parser

Post by magnetik » 02 Jun 2016, 21:38

I definitively need to put some time into it to at least fix it :)
ManiaPlanet technical documentation portal (Dedicated, ManiaLink, ManiaScript, Titles...) -- contribute!

User avatar
magnetik
Nadeo
Nadeo
Posts: 1643
Joined: 01 Feb 2012, 19:13
Location: Paris
Contact:

Re: Yet another ManiaPlanet style javascript parser

Post by magnetik » 04 Jun 2016, 19:04

I've posted an update, with some integrated tests and a few fixes

It lives in the maniaplanet repo : https://github.com/maniaplanet/maniapla ... -js-parser
ManiaPlanet technical documentation portal (Dedicated, ManiaLink, ManiaScript, Titles...) -- contribute!

zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: Yet another ManiaPlanet style javascript parser

Post by zocka » 21 Jan 2017, 23:02

I now fixed some issues I was aware of and some my test-cases found:
- correct base style when $z-resetting styles within $< $> blocks
- merging spans with the same style
- $w, $n and $t was only half-way implemented

I originally wanted to try this whole js module flow, thus made my script a node module, got myself a testing suite, and a whole bunch of additional files.
My script is 7kb big, 6kb tests and now I have more than 180 node_modules. JS pls
/rant

Anyway - here it is: https://www.npmjs.com/package/zocka-man ... -formatter

Another thing with MP formatting: $w and $n override each other, which is fine, but they can't be turned off by reactivation - like any other tag?

@magnetik: I tested the applicable testcases from my project with your approach and the main "faults" were these:

Code: Select all

  it 'reset with $z', ->
    assert.equal(Parser.toHTML('some $iitalic$z text'), 'some <span style="font-style:italic;">italic</span> text')
    // 'some <span style="font-style:italic;">italic</span><span style=""> text</span>'

  it 'formatting stacks (modified base style)', ->
    assert.equal(Parser.toHTML('$o$f00base $<$z$iother style$> back again'), '<span style="color: #ff0000; font-weight:bold;">base </span><span style="color: #ff0000; font-weight:bold;font-style:italic;">other style</span><span style="color: #ff0000; font-weight:bold;"> back again</span>')
    //  '<span style="color: #ff0000; font-weight:bold;">base </span><span style="font-style:italic;">other style</span><span style="color: #ff0000; font-weight:bold;"> back again</span>'
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

User avatar
toffe
Posts: 660
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: Yet another ManiaPlanet style javascript parser

Post by toffe » 14 Feb 2017, 19:40

Hey Zocka, Could you please test your module for TypeScript 2.0 compatibility. I would really like to use your module in a Angular2 project (wink wink).
Currently I'm already using it, but needed to copy pastino because typescript complains that the .d.ts is not a module. Haven't found a solution to that issue in the short time I searched for it. You can easily setup a test project with Angular2 CLI of course.

zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: Yet another ManiaPlanet style javascript parser

Post by zocka » 14 Feb 2017, 23:07

I actually never really worked with TS so I was confident, when my editor knew, what I wanted to say with my type definitions :D
I haven't found any doc or example that worked for me yet. I will update my package if I get it to work, but feel free to open a PR if you got something that works before I do.
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

Post Reply

Return to “General Tools”

Who is online

Users browsing this forum: No registered users and 2 guests