Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use jscreole natively on node #11

Open
DinisCruz opened this issue Feb 3, 2015 · 4 comments
Open

use jscreole natively on node #11

DinisCruz opened this issue Feb 3, 2015 · 4 comments

Comments

@DinisCruz
Copy link
Contributor

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?"

@DinisCruz
Copy link
Contributor Author

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

@DinisCruz
Copy link
Contributor Author

See #12

@DinisCruz
Copy link
Contributor Author

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)

image
image

@codeholic
Copy link
Owner

Is there an easy way to run jscreole on node?

Honestly, I have no clue. I'm mostly a Ruby on Rails developer now 😊

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 😉

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants