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

Auto-scaling font sizes #159

Closed
dangoldin opened this issue Nov 1, 2014 · 18 comments
Closed

Auto-scaling font sizes #159

dangoldin opened this issue Nov 1, 2014 · 18 comments
Labels

Comments

@dangoldin
Copy link

I've been using Remark for a class I've been teaching after wanting to take advantage of syntax highlighting and think it's awesome. One thing I wish it had was the ability to automatically resize font sizes on each slide similar to what Keynote does.

I'll be glad to take a stab at this if people think it's a decent idea and it would definitely be implemented as a separate option.

@gnab
Copy link
Owner

gnab commented Dec 21, 2014

Sorry for the slow reply. If your up for taking a stab that would be awesome! You're not the only one interested in such a feature.

@gnab gnab added the feature label Dec 22, 2014
@dangoldin
Copy link
Author

I'm definitely new to the JS world though so would need some review and oversight. Will take a stab at it.

@kgaut
Copy link

kgaut commented Apr 8, 2015

Subscribing ! Let me know if i can help you.

@junderhill
Copy link
Contributor

Did you make any progress with this feature? If not I may take a look.
Perhaps we could utilise a library such as https://github.com/davatron5000/FitText.js in order to fulfil this feature?

Another such library is http://www.zachleat.com/web/bigtext-makes-text-big/

@dangoldin
Copy link
Author

Nope - I wasn't able to get much done unfortunately.

@junderhill
Copy link
Contributor

OK, I'm going to take a look at this and see what I can do.

@junderhill
Copy link
Contributor

@gnab What's your thoughts on utilising jQuery to support this? It seems that all the libraries that would offer this functionality depend on jQuery.

@gnab
Copy link
Owner

gnab commented Jun 3, 2015

It would be nice if jQuery wasn't required to use remark. If jQuery is needed for this feature, maybe it can be an optional plugin that depends on jQuery, that is not bundled by default. If you can make it work the way you want with jQuery first, we'll take it from there. Maybe we can bundle only the parts of jQuery that is needed, or even implement it ourselves.

@junderhill
Copy link
Contributor

I can understand that. I will see what aspects of jQuery it utilises and see if it's something we can reimplement using standard JavaScript.

@gnab
Copy link
Owner

gnab commented Jun 3, 2015

The updateDimensions function is called to set the dimensions of a single slide:

https://github.com/gnab/remark/blob/develop/src/remark/views/slideView.js#L29

The dimensions remain the same unless the ratio of the slideshow is modified after creation. Window resizing is handled by scaling the entire slide, so font-sizing should only be needed in after the slide's dimensions are set/updated in the above function.

@aseigneurin
Copy link

Does anyone have a solution for this issue? Maybe a prototype of implementation?

@kgaut
Copy link

kgaut commented Nov 22, 2016

Hi @aseigneurin

Personnaly I moved to reveal.js for my presentations.

@aseigneurin
Copy link

@kgaut: do you imply that reveal.js does auto-scaling?

@Vebryn
Copy link

Vebryn commented Sep 5, 2017

According reveal.js README, it does: https://github.com/hakimel/reveal.js/#presentation-size

I like remark because it doesn't require a web server to interpret Markdown 👍

@koppor
Copy link

koppor commented Sep 24, 2017

Quick solution using jquery-quickfit:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
    <script src="https://cdn.rawgit.com/chunksnbits/jquery-quickfit/master/jquery.quickfit.js"></script>
    <script>
      var slideshow = remark.create();
      $('.remark-slide-content').quickfit({'min': 10, 'max': 36});
    </script>

In case the text still flows out, just replace 10 by a smaller minimum size.

@xaprb
Copy link

xaprb commented Sep 9, 2018

I added this to my Story website theme with a quick hack in the HTML source of the file that contains the Remark slide. This depends on JQuery, and on the slide having the fit-h1 class, and on the following CSS:

fit-h1 h1 {
      height: 1.25em;
      overflow: hidden;
   }
      // Shrink headers until they fit. (They have to be momentarily made
      // visible first.)
      $(".remark-slide-content.fit-h1 h1").each(function(i, e) {
         var $e = $(e);
         var $p = $e.closest('div.remark-slide-container');
         var needsToggle = !$p.hasClass('remark-visible');
         console.log(needsToggle);
         if ( needsToggle ) $p.toggleClass('remark-visible');
         while (e.scrollHeight > e.clientHeight + 1 && $e.css('font-size') != '1px') {
            $e.css('font-size', (parseInt($e.css('font-size')) - 1) + "px");
            // console.log($e.css('font-size') + "sh:" + e.scrollHeight + "ch:" +
            //    e.clientHeight);
         }
         if ( needsToggle ) $p.toggleClass('remark-visible');
      });

@alswl
Copy link

alswl commented Jan 30, 2019

I use FitText.js resolved this problem.

    <script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/FitText.js/1.2.0/jquery.fittext.min.js"></script>

    <script>
        var slideshow = remark.create();
        $('.remark-slide-content').fitText(1.2, { minFontSize: '14px', maxFontSize: '36px' });
    </script>

quick command here:
https://github.com/alswl/.oOo./blob/master/local/bin/remark

@abelards
Copy link
Collaborator

Documented here, thanks all! https://github.com/gnab/remark/wiki/HTML-CSS-JS-samples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants