Skip to content

use jscreole natively on node #11

@DinisCruz

Description

@DinisCruz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions