asciidoctor / asciidoctor-browser-extension

:white_circle: An extension for web browsers that converts AsciiDoc files to HTML using Asciidoctor.js.
https://chrome.google.com/webstore/detail/asciidoctorjs-live-previe/iaalpfgpbocpdfblpnhhgllgbdbchmia
MIT License
218 stars 50 forks source link

Using asciidoctor js into java Nashorn #44

Closed lordofthejars closed 9 years ago

lordofthejars commented 10 years ago

Hi today I have tried again the integration between asciidoctor js and Java, I think it has been improved so much since last time I tried.

For example rendering Chrome extension README.adoc it has been improved 2 seconds, from 3.5s to 1.5s, JRuby implementation takes 256ms, but I think that with time we will be able to improve a bit more. This time only is rendering time no startup time.

So I decided to open an issue here because I have some questions about opal/asciidoctorjs that I think that may become issues.

So the questions are:

javax.script.ScriptException: TypeError: Cannot call undefined in at line number 12263

Basically it is that input.$readLines doesn't exists.

Well that's all for now we are on the good path :).

Thanks.

ggrossetie commented 10 years ago

Hi @lordofthejars can you post the full stack trace ? If input is undefined the error should be something like TypeError: cannot call method '$readlines' of undefined. Are you using the latest version of Asciidoctor.js (1.5.0.preview.7) and Opal (0.6.2) ?

if there is a way to get the converted html file as full html (that is with html tag, embedded css, ...) when we pass content as string instead of a file?

I don't think so... but we can maybe expose an utility method in Asciidoctor to do that ?

lordofthejars commented 10 years ago

Versions:

Opal: 0.6.2 Asciidoctorjs: 1.5.0.preview.7

Look, this is my code:

File f = new File("src/test/resources/README.adoc");
        asciidoctorScriptCompilerCtx.getBindings(ScriptContext.ENGINE_SCOPE).put("asciiDocument", f.getAbsolutePath());
        System.out.println(engine.eval("Opal.Asciidoctor.$convert_file(asciiDocument)", asciidoctorScriptCompilerCtx));

The file is correct because if I read the file into a String and I pass to convert method then it all works as expected.

And the exception thrown:

javax.script.ScriptException: TypeError: Cannot call undefined in <eval> at line number 12263
    at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:564)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:548)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:528)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:524)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:194)
    at NashornTest.test2(NashornTest.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: <eval>:12263 TypeError: Cannot call undefined
    at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:56)
    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:212)
    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:184)
    at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:171)
    at jdk.nashorn.internal.runtime.Undefined.lookupTypeError(Undefined.java:128)
    at jdk.nashorn.internal.runtime.Undefined.lookup(Undefined.java:100)
    at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:98)
    at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176)
    at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124)
    at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:144)
    at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:232)
    at jdk.nashorn.internal.scripts.Script$\^eval\_$32._L11882$_L11900$_L12217$_L12220(<eval>:12263)
    at jdk.nashorn.internal.scripts.Script$\^eval\_$34._L11882$_L11900$_L12217$_L12303(<eval>:12329)
    at jdk.nashorn.internal.scripts.Script$\^eval\_$33._L11882$_L11900$_L12217$_L12429(<eval>:12435)
    at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:498)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:206)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:546)
    ... 30 more
ggrossetie commented 10 years ago

I think input can't be undefined because we are inside an if input['$is_a?'] : https://github.com/asciidoctor/asciidoctor-chrome-extension/blob/master/js/asciidoctor.js#L12262

The stack trace doesn't give much information :disappointed: ... Could you try to comment out line 12263 to see if the error changes ?

ggrossetie commented 10 years ago

@lordofthejars Any news on this issue ? Did you try with v1.5.0.preview.8 ?

lordofthejars commented 10 years ago

Not tried with the preview8 yet but I have found a way to do it with an option. I will keep you informed about this issue because currently I am implementing the core of integration with asciidoctor js and then I will focus in specific problems.

:)

Enviat des del meu iPhone

El 29/06/2014, a les 14.02, Guillaume Grossetie notifications@github.com va escriure:

@lordofthejars Any news on this issue ? Did you try with v1.5.0.preview.8 ?

— Reply to this email directly or view it on GitHub.

ggrossetie commented 10 years ago

@lordofthejars Any news with the latest release candidate ? Can we move this issue to Asciidoctor.js ?

jxxcarlson commented 9 years ago

I wonder whether it would be possible for you to implement a feature in Chrome extension that I use both in noteshare.io and AsciidocEdit? This is an option that maps $foo$ to stem:[foo]. Mathematicians (and physicists etc) use $...$ and [..] - anything even a keystroke longer to produce just won't work for them.

I was at a math meeting this week and got several people interested in using Asciidoc in their work. I showed them noteshare, but my friend, who uses Linux, wants also to work offline. I recommended a text editor and Chrome extension. The above mapping will be important for this to succeed. (As will be your forthcoming incision of the fonts)

I can send you some regular expressions that I use for this when I get home tonight. @mojavelinux improved these for me.

-- @jxxcarlson

PS. AsciidocEdit runs only under Yosemite, the version of MacOs that was released today. I hope to get version of AE in good enough shape for people to use in the next few weeks. I hope that someone will make PC and Linux versions.

Sent from my iPhone

On Oct 15, 2014, at 1:30 PM, Guillaume Grossetie notifications@github.com wrote:

Closed #44.

— Reply to this email directly or view it on GitHub.

ggrossetie commented 9 years ago

Can you open a new issue ? I think we can do it with an extension (see https://github.com/asciidoctor/asciidoctor.js/issues/64)

jxxcarlson commented 9 years ago

Will post later this evening. Thanks!

(I'm still learning the protocol:-)

Sent from my iPhone

On Oct 17, 2014, at 5:40 PM, Guillaume Grossetie notifications@github.com wrote:

Can you open a new issue ? I think we can do it with an extension (see asciidoctor/asciidoctor.js#64)

— Reply to this email directly or view it on GitHub.

jxxcarlson commented 9 years ago

Done — see https://github.com/asciidoctor/asciidoctor-extensions-lab/issues/15 https://github.com/asciidoctor/asciidoctor-extensions-lab/issues/15

On Oct 17, 2014, at 5:40 PM, Guillaume Grossetie notifications@github.com wrote:

Can you open a new issue ? I think we can do it with an extension (see asciidoctor/asciidoctor.js#64 https://github.com/asciidoctor/asciidoctor.js/issues/64)

— Reply to this email directly or view it on GitHub https://github.com/asciidoctor/asciidoctor-chrome-extension/issues/44#issuecomment-59580258.

mojavelinux commented 9 years ago

Thanks @jxxcarlson!

(I'm still learning the protocol:-)

Trust me, I'm still learning the protocol too :-) As they say, we're in this together ;)