Page 1 of 1
Yet another ManiaPlanet style javascript parser
Posted: 02 Jun 2016, 12:01
by zocka
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.
Re: Yet another ManiaPlanet style javascript parser
Posted: 02 Jun 2016, 13:02
by magnetik
By curiosity, what's not working ? I've not watched it for a long time, it might require an update
Re: Yet another ManiaPlanet style javascript parser
Posted: 02 Jun 2016, 17:24
by toffe
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
Re: Yet another ManiaPlanet style javascript parser
Posted: 02 Jun 2016, 21:24
by zocka
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

Re: Yet another ManiaPlanet style javascript parser
Posted: 02 Jun 2016, 21:38
by magnetik
I definitively need to put some time into it to at least fix it

Re: Yet another ManiaPlanet style javascript parser
Posted: 04 Jun 2016, 19:04
by magnetik
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
Re: Yet another ManiaPlanet style javascript parser
Posted: 21 Jan 2017, 23:02
by zocka
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>'
Re: Yet another ManiaPlanet style javascript parser
Posted: 14 Feb 2017, 19:40
by toffe
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.
Re: Yet another ManiaPlanet style javascript parser
Posted: 14 Feb 2017, 23:07
by zocka
I actually never really worked with TS so I was confident, when my editor knew, what I wanted to say with my type definitions

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.