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

Making a listing block text smaller #185

Closed
rlopez133 opened this issue Jun 11, 2015 · 22 comments
Closed

Making a listing block text smaller #185

rlopez133 opened this issue Jun 11, 2015 · 22 comments
Assignees

Comments

@rlopez133
Copy link

I have some output that I want to make smaller so that it doesn't wrap and looks more like my gedit screen. I tried using the [small] attribute, and it does make it smaller but leaves [small] visible in the output and still wraps. I'm pretty sure I'm just not doing it right.

Question

  1. Can I make listing block text smaller than what [small] does?
  2. How do I get rid it showing [small] # #

What my gedit screen looks like with asciidoc

selection_212

Output looks like:
selection_213

@mojavelinux
Copy link
Member

You'll be happy to know that this is another task that's on my list for 1.5.0. I just hadn't gotten around to filing an issue, but now that's done!

What I plan to do is implement a "shrink to fit" features (which happens to be supported in Prawn). Then, you'll be able to type:

[%autofit]
----
really long text that doesn't want to fit on a single line with the default font size, so we'll make it shrink to fit.
----

...and it won't wrap.

@mojavelinux
Copy link
Member

It would really help when you file tickets if you can paste the raw AsciiDoc source in the issue in addition to whatever screenshots you add. Otherwise, I have to transpose the AsciiDoc visually to test it :)

@mojavelinux mojavelinux added this to the v1.5.0 milestone Jun 12, 2015
@mojavelinux mojavelinux self-assigned this Jun 12, 2015
@mojavelinux
Copy link
Member

Btw, using small is a hack, so we want a solution that doesn't resort to that :)

@rlopez133
Copy link
Author

Yes, sorry for not adding the asciidoc source on there.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 12, 2015
- reduce font size to prevent wrapping in listing & literal blocks
- activate if autofit option is specified on block
- activate if source-autofit attribute is specified on document
@mojavelinux
Copy link
Member

With the pull request I've proposed, you'll be able to set autofit either on the block:

[%autofit]
----
really long text that doesn't want to fit on a single line with the default font size, so we'll make it shrink to fit.
----

or on the document:

:source-autofit:

----
really long text that doesn't want to fit on a single line with the default font size, so we'll make it shrink to fit.
----

I'm not sure if source-autofit is the right attribute name. We might want autofit-option instead. I need to think about it.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 12, 2015
- reduce font size to prevent wrapping in listing & literal blocks
- activate if autofit option is specified on block
- activate if autofit-option attribute is specified on document
@rlopez133
Copy link
Author

Works like a champ! i've only tried the [%autofit] though.

@rlopez133
Copy link
Author

I didn't realize this before, but when you autofit with a list, it is adding spaces between the text instructions and then the source block

example:

. Generate SSH keys on the Ceph Admin Server using `+ssh-keygen+` and copy the generated ssh keys to the managed hosts
+
[subs=+quotes]
----
# *ssh-keygen*
# **for HOST in ctrl{1,2,3} osd{1,2,3,4}; do ssh-copy-id $HOST; done**
----
+

. Update all managed hosts within the _/etc/hosts_ provisioning network entries. 
+
[subs=+quotes]
[%autofit]
----
# **for i in ctrl{1,2,3} osd{1,2,3,4}; do cat /etc/hosts | grep -i 20.0.0 | ssh $i "cat >> /etc/hosts"; done**
----
+

If you look at the output, you can see the gap difference

selection_216

@mojavelinux
Copy link
Member

mojavelinux commented Jun 12, 2015 via email

@rlopez133
Copy link
Author

Nope, same behavior.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 12, 2015
- reduce font size to prevent wrapping in listing & literal blocks
- activate if autofit option is specified on block
- activate if autofit-option attribute is specified on document
@mojavelinux
Copy link
Member

Oops, I was leaving behind space while doing the calculation. Just pushed a fix.

You are going to run into the problem that formatting the text causes the font size to shrink too much. I'll address the main cases of that scenario.

@rlopez133
Copy link
Author

Yeah, I figured that formating the text causes the font size to shrink too much. I figured for those edge cases I'd probably not do the autofit. However, a nice feature would be something that does autofit up to a font size of X, if requires smaller font wrap.

Also, the fix you just made of removing that space really fixed it. It looks like this now:

selection_218

@mojavelinux
Copy link
Member

I figured that formating the text causes the font size to shrink too much.

It's not too hard to fix. We're counting the XML tag as part of the line width, which is obviously not right. I just need to strip those out when measuring the line length.

However, a nice feature would be something that does autofit up to a font size of X, if requires smaller font wrap.

Definitely. I'll add that in.

@mojavelinux
Copy link
Member

Also, the fix you just made of removing that space really fixed it.

\o/

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 13, 2015
- reduce font size to prevent wrapping in listing & literal blocks
- prevent font size from reducing more than *_font_size_min
- activate if autofit option is specified on block
- activate if autofit-option attribute is specified on document
@mojavelinux
Copy link
Member

I've implemented the min font size and set a value in the default theme ($base_font_size * 0.75).

You can set the min font size either in the base:

base:
  font_size_min: $base_font_size * 0.75

or in the specific category:

code:
  font_size_min: $code_font_size * 0.75

@mojavelinux
Copy link
Member

Should we reuse the nowrap option that already exists?

It's hard to say. We can't always honor nowrap (due to the min font size), so it's not technically the same. We might also want to implement autofit in the future in the HTML output. I think I may have convinced myself that autofit is a distinct option from nowrap. wdyt?

@mojavelinux
Copy link
Member

I think that if nowrap is set, we should actually truncate the lines that overflow (if we want to truly honor the option specified). There may be cases when this is the desired behavior.

@mojavelinux
Copy link
Member

formatting the text causes the font size to shrink too much.

This is all that's left to fix.

@mojavelinux
Copy link
Member

...and I think I've got it worked out. Stay tuned.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 13, 2015
- autofit (reduce font size) to prevent wrapping in listing & literal blocks
- prevent font size from being reduced more than *_font_size_min
- activate autofit if autofit option is specified on block
- activate autofit if autofit-option attribute is specified on document
- add autofit example to chronicles.adoc
- add additional helper methods to core_ext and sanitizer
@mojavelinux
Copy link
Member

I'm not very happy with the implementation. It should now correctly autofit no matter what content is in the code block. It also works even if you don't use a monospaced font. Rock solid.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 13, 2015
- autofit (reduce font size) to prevent wrapping in listing & literal blocks
- prevent font size from being reduced more than *_font_size_min
- activate autofit if autofit option is specified on block
- activate autofit if autofit-option attribute is specified on document
- add autofit example to chronicles.adoc
- add additional helper methods to core_ext and sanitizer
mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 16, 2015
- autofit (reduce font size) to prevent wrapping in listing & literal blocks
- prevent font size from being reduced more than *_font_size_min
- activate autofit if autofit option is specified on block
- activate autofit if autofit-option attribute is specified on document
- add autofit example to chronicles.adoc
- add additional helper methods to core_ext and sanitizer
mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 16, 2015
- autofit (reduce font size) to prevent wrapping in listing & literal blocks
- prevent font size from being reduced more than *_font_size_min
- activate autofit if autofit option is specified on block
- activate autofit if autofit-option attribute is specified on document
- add autofit example to chronicles.adoc
- add additional helper methods to core_ext and sanitizer
mojavelinux added a commit that referenced this issue Jun 16, 2015
resolves #185 autofit font size in listing & literal blocks
@jinahya
Copy link

jinahya commented Jan 15, 2016

Is [%autofit] also supposed to work with asciidoctor-maven-plugin?
I'm using following configuration and it seems [%autofit] doesn't effect at all in both html5 and pdf backends.
Thanks.

      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <configuration>
          ..
        </configuration>
        <executions>
          ...
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj</artifactId>
            <version>1.5.4</version>
          </dependency>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-pdf</artifactId>
            <version>1.5.0-alpha.11</version>
          </dependency>
          <dependency>
            <groupId>org.jruby</groupId>
            <artifactId>jruby-complete</artifactId>
            <version>9.0.4.0</version>
          </dependency>
        </dependencies>
      </plugin>

@jinahya
Copy link

jinahya commented Jan 15, 2016

@mojavelinux I found solution on #385.
Now I wonder is there any way for html5 backend. Thank you.

@mojavelinux
Copy link
Member

There's nothing like this for the html5 converter. It would need to be solved via JavaScript, so you could write some JavaScript and append it via docinfo. In that case, you'd need to add the "autofit" role (not option) to the block so that it gets passed through to the HTML.

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

4 participants