git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Documentation: implement linkgit macro for Asciidoctor

From
Jeff King <peff@peff.net>
Date
Jan 26, 2017, 03:46 UTC
Message-ID
<20170126034655.fwzow2mgkjj5dpek@sigill.intra.peff.net>
In-Reply-To
<20170126001344.445534-1-sandals@crustytoothpaste.net>
On Thu, Jan 26, 2017 at 12:13:44AM +0000, brian m. carlson wrote:
Show 13 quoted lines
> diff --git a/Documentation/Makefile b/Documentation/Makefile
> index 19c42eb60..d1b7a6865 100644
> --- a/Documentation/Makefile
> +++ b/Documentation/Makefile
> @@ -179,10 +179,7 @@ ASCIIDOC = asciidoctor
>  ASCIIDOC_CONF =
>  ASCIIDOC_HTML = xhtml5
>  ASCIIDOC_DOCBOOK = docbook45
> -ifdef ASCIIDOCTOR_EXTENSIONS_LAB
> -ASCIIDOC_EXTRA = -I$(ASCIIDOCTOR_EXTENSIONS_LAB) -rasciidoctor/extensions -rman-inline-macro
> -endif
> -ASCIIDOC_EXTRA += -alitdd='&\#x2d;&\#x2d;'
> +ASCIIDOC_EXTRA += -I. -rasciidoctor-extensions -alitdd='&\#x2d;&\#x2d;'
Might be more readable to just leave the litdd part on its own line.
Show 30 quoted lines
> diff --git a/Documentation/asciidoctor-extensions.rb b/Documentation/asciidoctor-extensions.rb
> new file mode 100644
> index 000000000..09f7088ee
> --- /dev/null
> +++ b/Documentation/asciidoctor-extensions.rb
> @@ -0,0 +1,28 @@
> +require 'asciidoctor'
> +require 'asciidoctor/extensions'
> +
> +module Git
> +  module Documentation
> +    class LinkGitProcessor < Asciidoctor::Extensions::InlineMacroProcessor
> +      use_dsl
> +
> +      named :chrome
> +
> +      def process(parent, target, attrs)
> +        if parent.document.basebackend? 'html'
> +          prefix = parent.document.attr('git-relative-html-prefix')
> +          %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>\n)
> +        elsif parent.document.basebackend? 'docbook'
> +          %(<citerefentry>
> +<refentrytitle>#{target}</refentrytitle><manvolnum>#{attrs[1]}</manvolnum>
> +</citerefentry>
> +)
> +        end
> +      end
> +    end
> +  end
> +end

I think this looks reasonable. There's some boilerplate, but even as somebody not familiar with asciidoctor, it's all quite obvious.

The multi-line string is kind of ugly because of the indentation. Apparently Ruby has here-docs that will eat leading whitespace, but the syntax was not introduce until Ruby 2.3, which is probably more recent than we should count on.

I think you could write:
          %(<citerefentry>
            <refentrytitle>#{target}</refentrytitle><manvolnum>#{attrs[1]}</manvolnum>
            </citerefentry>
	  ).gsub(/^\s*/, "")
I don't know if that's too clever or not.
But either way, I like this better than introducing an extra dependency.
-Peff
Previous: brian m. carlsonNext: Eric Wong
Message 19 of 24 in “Macros for Asciidoctor support”
  1. 0/7 Macros for Asciidoctor supportbrian m. carlson, Jan 22, 2017
  2. 1/7 Documentation: fix warning in cat-texi.perlbrian m. carlson, Jan 22, 2017
  3. 4/7 Documentation: sort sources for gitman.texibrian m. carlson, Jan 22, 2017
  4. 3/7 Documentation: remove unneeded argument in cat-texi.perlbrian m. carlson, Jan 22, 2017
  5. 2/7 Documentation: modernize cat-texi.perlbrian m. carlson, Jan 22, 2017
  6. 6/7 Documentation: move dblatex arguments into variablebrian m. carlson, Jan 22, 2017
  7. 7/7 Makefile: add a knob to enable the use of Asciidoctorbrian m. carlson, Jan 22, 2017
  8. Øyvind A. HolmJan 23, 2017
  9. brian m. carlsonJan 23, 2017
  10. Øyvind A. HolmJan 25, 2017
  11. 5/7 Documentation: add XSLT to fix DocBook for Texinfobrian m. carlson, Jan 22, 2017
  12. Junio C HamanoJan 23, 2017
  13. Johannes SchindelinJan 25, 2017
  14. Jeff KingJan 25, 2017
  15. brian m. carlsonJan 25, 2017
  16. Jeff KingJan 25, 2017
  17. brian m. carlsonJan 25, 2017
  18. Documentation: implement linkgit macro for Asciidoctorbrian m. carlson, Jan 26, 2017
  19. Jeff KingJan 26, 2017
  20. Eric WongJan 26, 2017
  21. Johannes SchindelinJan 26, 2017
  22. Eric WongJan 26, 2017
  23. brian m. carlsonJan 27, 2017
  24. Junio C HamanoJan 31, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.