Jeff King <[email protected]> wrote:
> On Thu, Jan 26, 2017 at 12:13:44AM +0000, brian m. carlson wrote:
> > +
> > + 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>
> > +)
<snip>
> 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.
You can use '\' to continue long lines with any Ruby version:
"<citerefentry>" \
"<refentrytitle>#{target}</refentrytitle>" \
"<manvolnum>#{attrs[1]}</manvolnum>" \
"</citerefentry>"
The above happens during the parse phase, so there's no garbage
or method call overhead compared to the more-frequently seen '+'
or '<<' method calls to combine strings.
> 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.
Ick...
> But either way, I like this better than introducing an extra dependency.
Agreed.