Comments (12)
We should make that work -- I'll have a look at it.
from docgist.
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.
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.
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.
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.
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.
@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.
Probably for the best that we're using the public API :)
from docgist.
Nice job!
from docgist.
\o/
from docgist.
@jmini The example you gave now works.
from docgist.
Thank you a lot. ;-)
from docgist.
Related Issues (20)
- Absolute image paths on GitHub HOT 7
- Link to included document not working. HOT 9
- Get interdocument xrefs working HOT 2
- Support Bitbucket and GitLab HOT 5
- Upgrade to Asciidoctor.js 1.5.3 HOT 24
- Read attributes from the URL HOT 7
- Render footer with document metadata HOT 1
- Support files in Google Drive HOT 1
- Support the stylesheet attribute HOT 2
- Get a short url for the current page
- Convert problem in Safari HOT 26
- Make boolean attributes a toggle button in the Attributes menu
- Allow organizing maintained docs
- Where are fp- links documents stored? HOT 1
- Support interactive checkbox
- Allow setting garbage collection schedule on submitting a new gist. HOT 1
- PROJECT_REQUIRES_IMPORT HOT 4
- Google will discontinue the goo.gl on March 30, 2019 HOT 3
- Edit feature is not working HOT 1
- Footnote syntax doesn't work according to Asciidoctor documentation? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docgist.