jscreole
jscreole copied to clipboard
use jscreole natively on node
Hi, we use jscreole on our app to parse the Wiki into HTML, and on the new version, we need to do the parsing on the server (vs the client), and jscreole would be the perfect api (since we already use it and have written wiki text that parses ok with it).
So my first question is: 'Is there an easy way to run jscreole on node?'
I noticed that there isn't an npm package for jscreole (which would make that easier), if you want I'm happy to help in making that happen (https://www.npmjs.com/package/jscreole is waiting for you :) )
Here is how I was able to get it to work:
jscreole = require '../../poc/jscreole'
jsdom = require('jsdom').jsdom()
window = jsdom.parentWindow
describe '| poc | Wiki-Service.test |', ->
it.only 'render wiki', ->
wikitext = "== A title\n
\n
some text\n
\n
* a point"
div = window.document.createElement('div')
global.document = window.document
new jscreole().parse(div, wikitext)
delete global.document
log div.innerHTML
That uses jsdom to create an temp div (to hold the parsing text. I also had to temporarily polute the global
variable with a reference to document
because jscrole looks for that global object.
On that topic another question is "Is there a way to render the wiki text without an active dom?"
Sorry to be a bit proactive here, but I wanted to move and add jscreole to my project, and didn't really wanted to be importing js files directly.
... so ... I just created a fork and added the package.json required to make it work, I hope you don't mind (btw, let me know how/when do you want me to pass the ownership of this npm package to you).
You can see it at https://www.npmjs.com/package/jscreole
(I think the formatting issue on that page is because you used Wiki for the readme (https://github.com/codeholic/jscreole/blob/master/README.pod) instead of the expected markdown :)
This means that jscreole can now be used directly by using npm install jscreole --save
I will send a PR with the changes next
See https://github.com/codeholic/jscreole/pull/12
I just added an test and configure it to run on travis.
Note that at the moment only the node tests are running on travis (but it is possible to also run the existing tests)
Is there an easy way to run jscreole on node?
Honestly, I have no clue. I'm mostly a Ruby on Rails developer now :blush:
Is there a way to render the wiki text without an active dom?
Sure, there is (though it's not implemented yet). This library is almost 7 years old. DOM was considered funky at that time :wink:
There has been a proposal to implement pluggable builders #10
If you just want to get a string, you can do it somehow along these lines. (It is a port of this library to PHP.) I'd be more than happy to accept your pull request. (But please instrument it with some tests.)