Skip to content

Commit

Permalink
add additional mentions inline macro
Browse files Browse the repository at this point in the history
- split mentions inline macro into two macros; one shorthand, one formal
- call convert instead of render on Inline
- update example
  • Loading branch information
mojavelinux committed Apr 22, 2017
1 parent e2efad3 commit 9846486
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 19 additions & 4 deletions lib/mentions-inline-macro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@
include ::Asciidoctor

Extensions.register do
# matches @username
inline_macro do
named :mention
using_format :short
match /@(\w+)/
named :@mention
using_format :short # not required here for Asciidoctor >= 1.5.6
match %r/@(\w+)/
process do |parent, target|
mentions_uri_pattern = (parent.document.attr 'mentions-uri-pattern') || 'https://github.com/%s'
mention_uri = mentions_uri_pattern % target
(create_anchor parent, %(@#{target}), type: :link, target: mention_uri).render
(create_anchor parent, %(@#{target}), type: :link, target: mention_uri).convert
end
end

# matches mention:username[<text>]
inline_macro do
named :mention
parse_content_as :text
process do |parent, target, attrs|
mentions_uri_pattern = (parent.document.attr 'mentions-uri-pattern') || 'https://github.com/%s'
mention_uri = mentions_uri_pattern % target
if (text = attrs['text']).empty?
text = %(@#{target})
end
(create_anchor parent, text, type: :link, target: mention_uri).convert
end
end
end
4 changes: 3 additions & 1 deletion lib/mentions-inline-macro/sample.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
= Mentions Inline Macro
:mentions-uri-pattern: http://twitter.com/%s

@mojavelinux, do you have any feedback on this issue?
@mojavelinux, wdyt?

mention:mojavelinux[Dan] yo yo!

0 comments on commit 9846486

Please sign in to comment.