Git Product home page Git Product logo

Comments (12)

nawroth avatar nawroth commented on July 19, 2024

We should make that work -- I'll have a look at it.

from docgist.

mojavelinux avatar mojavelinux commented on July 19, 2024

If you know you're rendering a file from GitHub in docgist (which I'm pretty sure is true), you can set the imagesdir to a qualified URL. Though, you'd need to read in the imagesdir from the header (just like we do with source-highlighter), prepend the URL to that value, then pass the new attribute value to the API. This way, you respect the relative imagesdir path set in the document.

from docgist.

nawroth avatar nawroth commented on July 19, 2024

I did an attempt at it, see: http://nawroth.github.io/docgist/?github-asciidoctor%2Fasciidoctor-maven-examples%2F%2Fasciidoc-to-html-example%2Fsrc%2Fdocs%2Fasciidoc%2Fexample-manual.adoc

@mojavelinux Could you check if I got the logic around imagesdir right?

from docgist.

nawroth avatar nawroth commented on July 19, 2024

In the case where the imagesdir attribute hasn't been set in the document things work fine: http://nawroth.github.io/docgist/?github-nawroth%2Fdocgist%2F%2Fgists%2Fexample.adoc
But as soon as it has been set in the document I'm failing to override it:
http://nawroth.github.io/docgist/?github-nawroth%2Fdocgist%2F%2Fgists%2Fimages.adoc
The code is here: https://github.com/nawroth/docgist/blob/master/js/docgist.js#L32
As soon as the rendering is invoked, the attribute is reverted back to the value set in the document.

On a brighter note, I got Prettify support in place: http://nawroth.github.io/docgist/?github-nawroth%2Fdocgist%2F%2Fgists%2Fprettify.adoc
You can see the difference compared to highlight.js: http://nawroth.github.io/docgist/?github-nawroth%2Fdocgist%2F%2Fgists%2Fexample.adoc#_source_code_highlighting

from docgist.

mojavelinux avatar mojavelinux commented on July 19, 2024

As soon as the rendering is invoked, the attribute is reverted back to the value set in the document.

I think I know what has to be done. I'll look at it and come back with an explanation.

I got Prettify support in place

Fantastic! There's no doubt that prettify does a more accurate job of highlighting the major languages, so this is a very nice improvement!

from docgist.

mojavelinux avatar mojavelinux commented on July 19, 2024

The reason the imagesdir attribute is being reset is because, prior to the convert step, the attributes defined up to the end of the header are restored to their original values (see https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/document.rb#L1007). This is an issue in the Asciidoctor API that needs to be addressed (see asciidoctor/asciidoctor#1255).

There are two workarounds to this problem. I'll describe the simpler, quicker fix first, then explain how we might do this in a more formal (yet slightly slower) way.

Modify the original attributes

The quick fix is to make modifications directly to the original_attributes instance variable on the document. That way, when the attributes are restored, it includes the modifications made by the API. Here's how that would be done:

var attributes = doc.attributes.map;
doc.original_attributes.$update(Opal.hash({imagesdir: imageBasePath + attributes.imagesdir}))

You must use the $update function to make changes to the Hash (not []) given how Opal stores the Hash internally.

Load in two phases

The more formal way to solve this problem (until we are able to correct the API), is to load in two phases.

You begin by loading the header only.

doc = Opal.Asciidoctor.$load(content, Opal.hash({parse_header_only: true}))

From the doc, you can read the attributes that are set up to the end of the header. You can cherry pick the attributes you want, modify them as needed, then pass them to the API as overrides. In fact, at this point, you don't even have to call $load again, you could just proceed directly to Asciidoctor.$convert. Since you are passing attributes directly to the API, they will override anything in the document.

Make sense?

from docgist.

nawroth avatar nawroth commented on July 19, 2024

@mojavelinux I went with the two-phase option, as modifying the original attributes had the same problem as my first attempt (that is, they are still reset to the original value).

from docgist.

mojavelinux avatar mojavelinux commented on July 19, 2024

Probably for the best that we're using the public API :)

from docgist.

mojavelinux avatar mojavelinux commented on July 19, 2024

Nice job!

from docgist.

mojavelinux avatar mojavelinux commented on July 19, 2024

\o/

from docgist.

nawroth avatar nawroth commented on July 19, 2024

@jmini The example you gave now works.

from docgist.

jmini avatar jmini commented on July 19, 2024

Thank you a lot. ;-)

from docgist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.