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
219 stars 50 forks source link

setting custom attributes #128

Closed wva154 closed 8 years ago

wva154 commented 8 years ago

It seems that when setting custom attributes with the options menu, that only the first one is detected and used. For example using the string

skip-front-matter=1 attributeA=1

it respects the skip-front-matter, but attributeA is not set and using the string

attributeA=1 skip-front-matter=1

do sets attributeA but ignores the skip-front-matter attribute.

Can anyone confirm this issue?

ggrossetie commented 8 years ago

Hello @wva154 Yes I can reproduce this issue, good catch :+1:

I think the space between attributes is ignored.

Document

= Test

{attribute-a}

{attribute-b}

Custom attributes

attribute-a=a attribute-b=b

Result

test

ggrossetie commented 8 years ago

customAttributes must be split by space:

if (customAttributes) {
  attributes.push(customAttributes.split(' '));
}

https://github.com/asciidoctor/asciidoctor-chrome-extension/blob/master/app/js/renderer.js#L137

mojavelinux commented 8 years ago

It's actually a bit more complex than that, though that certainly works for all but the edge cases. See https://github.com/asciidoctor/asciidoctor/blob/v1.5.4/lib/asciidoctor.rb#L1285-L1294

ggrossetie commented 8 years ago

Indeed this a bit moooooore complex. I will pass attributes as a String and let "Asciidoctor core" handles the edge cases :wink:

M3lkior commented 8 years ago

Same issue here since upgrading the extension :/

mojavelinux commented 8 years ago

@Mogztter and @M3lkior, I think the problem is that the custom attributes are getting pushed onto the array as a single entry. In other words, the array looks like this:

[
  'showtitle',
  'icons=font@',
  ...
  'outfilesuffix=.adoc',
  'skip-front-matter=1 attributeA=1''
]

So the Asciidoctor API sees the value of the skip-front-matter attribute as 1 attributeA=1.

I had this same problem in the Jekyll AsciiDoc plugin, so I implemented full attribute parsing. That logic will eventually make its way into the Asciidoctor API. Until then, here it is:

https://github.com/asciidoctor/jekyll-asciidoc/blob/671a17747b21017642d8475e959979cadf13ac46/lib/jekyll-asciidoc/converter.rb#L239-L271

The only difference is that since the input is a text field, you'll need to also add the space escape logic that can be found here:

https://github.com/asciidoctor/asciidoctor/blob/v1.5.4/lib/asciidoctor.rb#L1285-L1294

If you'd like to work upstream instead to introduce this API, I'd be open to working with you on that. See https://github.com/asciidoctor/asciidoctor/issues/1084

ggrossetie commented 8 years ago

@mojavelinux For now I think I will pass all attributes as a single String. That way Asciidoctor will handle the space escape logic, see #134

mojavelinux commented 8 years ago

@Mogztter Yes, that will also solve the issue.

akosma commented 8 years ago

Hi guys, since the current version in the chrome web store does not include this fix, could you please publish a new one with it? It took me a while to understand why the custom attributes did not work (unless I entered only one) until I found this issue :) Thanks!

PS: yes, I can just clone the project and use developer mode, but I think that from a user point of view it's a rather confusing bug.

ggrossetie commented 8 years ago

Hi @akosma,

Sorry about that, my attention was focused on Asciidoctor.js. I will try to find the time this week to publish the new version on the Chrome Web Store :sparkles:

akosma commented 8 years ago

Now that is fantastic! :) thank you so much, for all the effort. This whole family of projects is helping me a lot!

Just for the record, and this might be handy for someone else, in the meantime I'm passing the custom attributes in the querystring, which works beautifully well with the current version of the Chrome extension:

file:///Users/folder/file.asciidoc?toc&numbered&source-language=objectivec&…

ggrossetie commented 8 years ago

You're welcome, I'm glad to know that you like it :wink: I've just published a new version (1.5.4.111), it should be available soon:

https://github.com/asciidoctor/asciidoctor-chrome-extension/releases/tag/v1.5.4.111

akosma commented 8 years ago

Wohoooo! :) thanks