Skip to content

Instantly share code, notes, and snippets.

@aslakknutsen
Created August 20, 2014 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslakknutsen/07e90afa8fcd8c7aac01 to your computer and use it in GitHub Desktop.
Save aslakknutsen/07e90afa8fcd8c7aac01 to your computer and use it in GitHub Desktop.
Asciidoctor 1.5.0 regression?
require "asciidoctor"
require 'asciidoctor/extensions'
Asciidoctor::Extensions.register do
inline_macro do
named :javaapi
match /((?:java|javax)\.\w[\.\w]+\.[A-Z]\w+)/
process do |parent, target|
doc_uri_pattern = 'https://javaee-spec.java.net/nonav/javadocs/%s.html'
doc_uri = doc_uri_pattern % target.gsub(/\./, '/')
link_name = target
link_name = $1 if target =~ /([A-Z]\w*$)/
(create_anchor parent, link_name, type: :link, target: doc_uri, attributes: {'title' => target}).render
end
end
end
def render content
Asciidoctor.render(content)
end
def verify content
expect(content).to match /<a/
end
describe "Asciidoctor inline macro" do
it "Inline macro on pure text" do
verify render "javax.test.Api"
end
it "Inline macro on code text" do
verify render "+javax.test.Api+"
end
end
@aslakknutsen
Copy link
Author

In Asciidoctor 1.5.0 +javax.test.Api+ never trigger the maco. Nor does it output code tags for that matter.

@mojavelinux
Copy link

Aha! That's because you need to refer to the migration guide :)

http://asciidoctor.org/docs/migration/#migration-cheatsheet

+ now means passthrough, not monospaced. You need to either switch it to backtick:

`javax.test.Api`

Add the compat role:

[x-]+javax.test.Api+

Or switch on compat mode globally:

:compat-mode:

@aslakknutsen
Copy link
Author

Aha! :)

def render content
   Asciidoctor.render(content, :attributes => {'compat-mode' => true})
end

Back to normal..

@mojavelinux
Copy link

Oh, right! That works too. I should have suggested that.

Btw, you can just set a value of empty string to mean true...though that's one of the things we need to cleanup in Asciidoctor because that's a legacy hold-over from AsciiDoc Python. Why true and false aren't true and false is beyond me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment