summaryrefslogtreecommitdiff
path: root/Documentation/asciidoctor-extensions.rb
AgeCommit message (Collapse)Author
2019-10-06Merge branch 'ma/user-manual-markup-update'Junio C Hamano
The markup used in user-manual has been updated to work better with asciidoctor. * ma/user-manual-markup-update: user-manual.txt: render ASCII art correctly under Asciidoctor asciidoctor-extensions.rb: handle "book" doctype in linkgit user-manual.txt: change header notation user-manual.txt: add missing section label
2019-09-28asciidoctor-extensions.rb: handle "book" doctype in linkgitMartin Ågren
user-manual.txt is the only file we process using the "book" doctype. When we use AsciiDoc, user-manual.conf ensures that the linkgit macro expands into something like <ulink url="git-foo.html">git-foo(1)</ulink> in user-manual.xml, which we then process into a clickable link, both in user-manual.html and user-manual.pdf. With Asciidoctor, user-manual.conf is ignored (this is expected) and our Asciidoctor-specific implementation of linkgit kicks in: <citerefentry> <refentrytitle>git-foo</refentrytitle><manvolnum>1</manvolnum> </citerefentry> This eventually renders as "git-foo(1)", which is not bad, but it doesn't turn into a link. Teach our Asciidoctor-specific implementation of the linkgit macro that if the doctype is "book", we should emit <ulink .../> just like we do with AsciiDoc. While we're doing this, future-proof by supporting a "prefix". The implementation in user-manual.conf doesn't support this, and we don't need this for now because user-manual.txt is the only file we process this way (and it's immediately in Documentation/). Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-09-16asciidoctor-extensions: provide `<refmiscinfo/>`Martin Ågren
As can be seen from the previous commit, there are three attributes that we provide to AsciiDoc through asciidoc.conf. Asciidoctor ignores that file. After that patch, newer versions of Asciidoctor pick up the `manmanual` and `mansource` attributes as we invoke `asciidoctor`, but they don't pick up `manversion`. ([1] says: "Not used by Asciidoctor.") Older versions (<1.5.7) don't handle these attributes at all. As a result, we are missing one or three `<refmiscinfo/>` tags in each xml-file produced when we build with Asciidoctor. Because of this, xmlto doesn't include the Git version number in the rendered manpages. And in particular, with versions <1.5.7, the manpage footers instead contain the fairly ugly "[FIXME: source]". That Asciidoctor ignores asciidoc.conf is nothing new. This is why we implement the `linkgit:` macro in asciidoc.conf *and* in asciidoctor-extensions.rb. Follow suit and provide these tags in asciidoctor-extensions.rb, using a "postprocessor" extension where we just search and replace in the XML, treated as text. We may consider a few alternatives: * Inject these lines into the xml-files from the *Makefile*, e.g., using `sed`. That would reduce repetition, but it feels wrong to impose another step and another risk on the AsciiDoc-processing only to benefit the Asciidoctor-one. * I tried providing a "docinfo processor" to inject these tags, but could not figure out how to "merge" the two <refmeta/> sections that resulted. To avoid xmlto barfing on the result, I needed to use `xmlto --skip-validation ...`, which seems unfortunate. Let's instead inject the missing tags using a postprocessor. We'll make it fairly obvious that we aim to inject the exact same three lines of `<refmiscinfo/>` that asciidoc.conf provides. We inject them in *post*-processing so we need to do the variable expansion ourselves. We do introduce the bug that asciidoc.conf already has in that we won't do any escaping, e.g., of funky versions like "some v <2.25, >2.20". The postprocessor we add here works on the XML as raw text and doesn't really use the full potential of XML to do a more structured injection. This is actually precisely what the Asciidoctor User Manual does in its postprocessor example [2]. I looked into two other approaches: 1. The nokogiri library is apparently the "modern" way of doing XML in ruby. I got it working fairly easily: require 'nokogiri' doc = Nokogiri::XML(output) doc.search("refmeta").each { |n| n.add_child(new_tags) } output = doc.to_xml However, this adds another dependency (e.g., the "ruby-nokogiri" package on Ubuntu). Using Asciidoctor is not our default, but it will probably need to become so soon. Let's avoid adding a dependency just so that we can say "search...add_child" rather than "sub(regex...)". 2. The older REXML is apparently always(?) bundled with ruby, but I couldn't even parse the original document: require 'rexml/document' doc = REXML::Document.new(output) ... The error was "no implicit conversion of nil into String" and I stopped there. I don't think it's unlikely that doing a plain old search-and-replace will work just as fine or better compared to parsing XML and worrying about libraries and library versions. [1] https://asciidoctor.org/docs/user-manual/#builtin-attributes [2] https://asciidoctor.org/docs/user-manual/#postprocessor-example Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11asciidoctor-extensions: fix spurious space after linkgitMartin Ågren
When we render, e.g., "linkgit:gitglossary[7]." with Asciidoctor, we get "gitglossary(7) ." with a space between the linkgit macro expansion and the punctuation. We can fix this by dropping the trailing newline after we've turned `linkgit:foo[bar]` into `<citerefentry>..</citerefentry>`. The diff produced by `USE_ASCIIDOCTOR=Yes ./doc-diff HEAD^ HEAD` is almost 6000 lines large and shows how this fixes "git-foo(x) ,", "(see git-bar(y) )" and so on. One might wonder whether this also turns, e.g., "see linkgit:foo[1] for more" into "see foo(1)for more", but no. We get "...</citerefentry> for more" in the XML, see, e.g., git-am.xml, so the space ends up in git-am.1 just fine. The same is true for the HTML output. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-01-31Documentation: implement linkgit macro for Asciidoctorbrian m. carlson
AsciiDoc uses a configuration file to implement macros like linkgit, while Asciidoctor uses Ruby extensions. Implement a Ruby extension that implements the linkgit macro for Asciidoctor in the same way that asciidoc.conf does for AsciiDoc. Adjust the Makefile to use it by default. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>