Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional margin to code, kbd:[] and menu:[] #1264

Closed
habamax opened this issue Sep 10, 2019 · 9 comments
Closed

additional margin to code, kbd:[] and menu:[] #1264

habamax opened this issue Sep 10, 2019 · 9 comments
Assignees
Milestone

Comments

@habamax
Copy link
Contributor

habamax commented Sep 10, 2019

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.

@mojavelinux
Copy link
Member

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 prawnpdf/prawn#1128 If it gets implemented there, then we can add left-to-right padding to inline elements.

@mojavelinux
Copy link
Member

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.

@habamax
Copy link
Contributor Author

habamax commented Sep 10, 2019

Ok, I see. Thx!

@mojavelinux
Copy link
Member

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.

@mojavelinux mojavelinux self-assigned this Dec 21, 2019
@mojavelinux mojavelinux added this to the v1.5.0 milestone Dec 21, 2019
@mojavelinux
Copy link
Member

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

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Dec 22, 2019
mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Dec 22, 2019
@mojavelinux
Copy link
Member

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

@habamax
Copy link
Contributor Author

habamax commented Dec 22, 2019

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

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Dec 24, 2019
@habamax
Copy link
Contributor Author

habamax commented Dec 26, 2019

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

@mojavelinux
Copy link
Member

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

@mojavelinux mojavelinux modified the milestones: v1.5.0, v1.5.0.rc.1 Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants