{"id":3428,"date":"2018-02-20T17:15:31","date_gmt":"2018-02-20T15:15:31","guid":{"rendered":"https:\/\/www.systemcodegeeks.com\/?p=3428"},"modified":"2018-02-20T10:36:04","modified_gmt":"2018-02-20T08:36:04","slug":"asciidoctor-creating-macro","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/","title":{"rendered":"Asciidoctor: Creating a macro"},"content":{"rendered":"<p>I\u2019ve been writing the <a href=\"https:\/\/neo4j.com\/tag\/twin4j\/\">TWIN4j blog<\/a> for almost a year now and during that time I\u2019ve written a few different <a href=\"http:\/\/asciidoc.org\/chunked\/ch21.html\">asciidoc macros<\/a> to avoid repetition.<\/p>\n<p>The most recent one I wrote does the formatting around the Featured Community Member of the Week. I call it like this from the asciidoc, passing in the name of the person and a link to an image:<\/p>\n<pre class=\"brush:text\">featured::https:\/\/s3.amazonaws.com\/dev.assets.neo4j.com\/wp-content\/uploads\/20180202004247\/this-week-in-neo4j-3-february-2018.jpg[name=\"Suellen Stringer-Hye\"]<\/pre>\n<p>The code for the macro has two parts. The first is some wiring code that registers the macro with Asciidoctor:<\/p>\n<p><cite>lib\/featured-macro.rb<\/cite><\/p>\n<pre class=\"brush:bash\">RUBY_ENGINE == 'opal' ? (require 'featured-macro\/extension') : (require_relative 'featured-macro\/extension')\r\n\u00a0\r\nAsciidoctor::Extensions.register do\r\n  if (@document.basebackend? 'html') &amp;&amp; (@document.safe &lt; SafeMode::SECURE)\r\n    block_macro FeaturedBlockMacro\r\n  end\r\nend<\/pre>\n<p>And this is the code for the macro itself:<\/p>\n<p><cite>lib\/featured-macro\/extension.rb<\/cite><\/p>\n<pre class=\"brush:bash\">require 'asciidoctor\/extensions' unless RUBY_ENGINE == 'opal'\r\n\u00a0\r\ninclude ::Asciidoctor\r\n\u00a0\r\nclass FeaturedBlockMacro &lt; Extensions::BlockMacroProcessor\r\n  use_dsl\r\n\u00a0\r\n  named :featured\r\n\u00a0\r\n  def process parent, target, attrs\r\n    name = attrs[\"name\"]\r\n\u00a0\r\n    html = %(&lt;div class=\"imageblock image-heading\"&gt;\r\n                &lt;div class=\"content\"&gt;\r\n                    &lt;img src=\"#{target}\" alt=\"#{name} - This Week\u2019s Featured Community Member\" width=\"800\" height=\"400\"&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n            &lt;p style=\"font-size: .8em; line-height: 1.5em;\" align=\"center\"&gt;\r\n              &lt;strong&gt;#{name} - This Week's Featured Community Member&lt;\/strong&gt;\r\n            &lt;\/p&gt;)\r\n\u00a0\r\n    create_pass_block parent, html, attrs, subs: nil\r\n  end\r\nend<\/pre>\n<p>When we convert the asciidoc into HTML we need to tell asciidoctor about the macro, which we can do like this:<\/p>\n<pre class=\"brush:bash\">asciidoctor template.adoc \\\r\n  -r .\/lib\/featured-macro.rb \\\r\n  -o -<\/pre>\n<p>And that\u2019s it!<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on System Code Geeks with permission by Mark Needham, partner at our <a href=\"http:\/\/www.systemcodegeeks.com\/join-us\/scg\/\" target=\"_blank\" rel=\"noopener\">SCG program<\/a>. See the original article here: <a href=\"http:\/\/www.markhneedham.com\/blog\/2018\/02\/19\/asciidoctor-creating-macro\/\" target=\"_blank\" rel=\"noopener\">Asciidoctor: Creating a macro<\/a><\/p>\n<p>Opinions expressed by System Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most recent one I wrote does the formatting around the Featured Community Member of the Week. I call it like this from the asciidoc, passing in the name of &hellip;<\/p>\n","protected":false},"author":29,"featured_media":185,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[144],"class_list":["post-3428","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shell-scripting","tag-asciidoc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Asciidoctor: Creating a macro - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Asciidoctor: Creating a macro - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-20T15:15:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mark Needham\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mark Needham\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\"},\"author\":{\"name\":\"Mark Needham\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/ae1c58c8f59ab2d33fc598b0ad933eb4\"},\"headline\":\"Asciidoctor: Creating a macro\",\"datePublished\":\"2018-02-20T15:15:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\"},\"wordCount\":165,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"keywords\":[\"Asciidoc\"],\"articleSection\":[\"Shell Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\",\"name\":\"Asciidoctor: Creating a macro - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"datePublished\":\"2018-02-20T15:15:31+00:00\",\"description\":\"I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shell Scripting\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Asciidoctor: Creating a macro\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/ae1c58c8f59ab2d33fc598b0ad933eb4\",\"name\":\"Mark Needham\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=96&d=mm&r=g\",\"caption\":\"Mark Needham\"},\"sameAs\":[\"http:\/\/www.markhneedham.com\/blog\/\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/mark-needham\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Asciidoctor: Creating a macro - System Code Geeks - 2026","description":"I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/","og_locale":"en_US","og_type":"article","og_title":"Asciidoctor: Creating a macro - System Code Geeks - 2026","og_description":"I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most","og_url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_published_time":"2018-02-20T15:15:31+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","type":"image\/jpeg"}],"author":"Mark Needham","twitter_card":"summary_large_image","twitter_creator":"@systemcodegeeks","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Mark Needham","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/"},"author":{"name":"Mark Needham","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/ae1c58c8f59ab2d33fc598b0ad933eb4"},"headline":"Asciidoctor: Creating a macro","datePublished":"2018-02-20T15:15:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/"},"wordCount":165,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","keywords":["Asciidoc"],"articleSection":["Shell Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/","url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/","name":"Asciidoctor: Creating a macro - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","datePublished":"2018-02-20T15:15:31+00:00","description":"I\u2019ve been writing the TWIN4j blog for almost a year now and during that time I\u2019ve written a few different asciidoc macros to avoid repetition. The most","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/asciidoctor-creating-macro\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Shell Scripting","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/"},{"@type":"ListItem","position":3,"name":"Asciidoctor: Creating a macro"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/ae1c58c8f59ab2d33fc598b0ad933eb4","name":"Mark Needham","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5489baed26ce2d932bf951ecfb47afe80bec45d3648c23521d87c83b8f1c3ea9?s=96&d=mm&r=g","caption":"Mark Needham"},"sameAs":["http:\/\/www.markhneedham.com\/blog\/"],"url":"https:\/\/www.systemcodegeeks.com\/author\/mark-needham\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/3428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=3428"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/3428\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/185"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=3428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=3428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=3428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}