Asciidoctor-pdf: additional margin to `code`, kbd:[] and menu:[]

Created on 10 Sep 2019  路  9Comments  路  Source: asciidoctor/asciidoctor-pdf

Hi @mojavelinux, could you tell me if it is possible to extend fragment of the inline code in a way that it doesn't eat next characters?

== test 1

Lorem `ipsum` dolor sit `amet`, consectetur adipiscing elit.
Maecenas feugiat fermentum kbd:[pretium]. Cras eu dolor imperdiet justo mattis
pulvinar. Cras nec lectus ligula. Proin ``elementum``luctus elit, a tincidunt quam
facilisis non. Nunc quis mauris non turpis finibus luctus. Maecenas ante
sapien, sagittis quis accumsan in, feugiat quis sem. Praesent et auctor libero.

image

My first silly attempt was to change

module InlineTextAligner
  module_function
  def render_behind fragment
    document = fragment.document
    text = fragment.text
    x = fragment.left

    ##################################
    if (border_offset = data[:border_offset])
      x += border_offset
    end
    if (border_width = data[:border_width])
      x += border_width
    end
    ##################################

    y = fragment.baseline
    align = fragment.format_state[:align]
    if align == :center || align == :right
      if (gap_width = fragment.width - (document.width_of text)) != 0
        x += gap_width * (align == :center ? 0.5 : 1)
      end
    end
    document.draw_text! text, at: [x, y]
    fragment.conceal
  end

But as expected (by me :) ) it didn't work.

So is it even possible? To extend the inline code fragment on X?

Now you have to kind of tune the border offset and border width otherwise it highlights before and after characters.

enhancement

Most helpful comment

We need to be able to control the width of the fragment that Prawn uses when arranging the text fragments.

It appears this might now be possible (after recent updates to the converter). I'll look into it.

All 9 comments

Nope, this is not possible. Prawn doesn't provide any way to do it. That's why we have border-offset. Because the best we can do is extend the background/border.

You could hack it by inserting a thin space, but that's pretty brute force and not very precise.

I've filed an issue in Prawn for this to be considered. See https://github.com/prawnpdf/prawn/issues/1128 If it gets implemented there, then we can add left-to-right padding to inline elements.

Although your hack is very clever, it doesn't work because it modifies the fragment too late. We need to be able to control the width of the fragment that Prawn uses when arranging the text fragments. And as far as I can see (and best remember), that's not possible.

Ok, I see. Thx!

We need to be able to control the width of the fragment that Prawn uses when arranging the text fragments.

It appears this might now be possible (after recent updates to the converter). I'll look into it.

Btw, you were actually on the right path. It just requires changes in a few more places.

I think I got it. It's a little patchy, but it works very well.

Thx a lot! Can't test it yet (on vacation) but will definitely do it in a week or so.

Just tested it -- works flawlessly! Awesome, thank you!

I'm so happy to hear that. Thanks for testing!

Was this page helpful?
0 / 5 - 0 ratings