77
88import copy
99import random
10+ import re
1011import string
12+ import warnings
1113
1214from plotly import exceptions , optional_imports
1315
@@ -307,12 +309,22 @@ def _list_of_slides(markdown_string):
307309 if not markdown_string .endswith ('\n ---\n ' ):
308310 markdown_string += '\n ---\n '
309311
310- text_blocks = markdown_string .split ('\n ---\n ' )
312+ #text_blocks = markdown_string.split('\n---\n')
313+ text_blocks = re .split (
314+ '\n --\n |\n ---\n |\n ----\n |\n -----\n |\n ------\n ' , markdown_string
315+ )
311316 list_of_slides = []
312317 for j , text in enumerate (text_blocks ):
313318 if not all (char in ['\n ' , '-' , ' ' ] for char in text ):
314319 list_of_slides .append (text )
315320
321+ if '\n -\n ' in markdown_string :
322+ msg = ("You have at least one '-' by itself on its own line in your "
323+ "markdown string. If you are trying to denote a new slide, "
324+ "make sure that the line has 3 '-'s like this: \n \n ---\n \n "
325+ "A new slide will NOT be created here." )
326+ warnings .warn (msg )
327+
316328 return list_of_slides
317329
318330
@@ -653,33 +665,57 @@ def _return_layout_specs(num_of_boxes, url_lines, title_lines, text_block,
653665 text_textAlign = 'center'
654666 else :
655667 text_textAlign = 'left'
656- if num_of_boxes == slide_num == 0 :
657- (bkgd_color ,
658- title_font_color ,
659- text_font_color ) = colors_dict ['darkslide' ]
660- specs_for_title = (0 , 50 , 20 , 100 )
661- specs_for_text = (15 , 60 , 50 , 70 )
668+ if num_of_boxes == 0 :
662669 title_fontSize = 55
670+ if slide_num == 0 or text_block == '' :
671+ (bkgd_color ,
672+ title_font_color ,
673+ text_font_color ) = colors_dict ['darkslide' ]
674+ specs_for_title = (0 , 50 , 20 , 100 )
675+ specs_for_text = (15 , 60 , 50 , 70 )
676+ else :
677+ (bkgd_color ,
678+ title_font_color ,
679+ text_font_color ) = colors_dict ['darkslide' ]
680+ text_top = _top_spec_for_text_at_bottom (
681+ text_block , width_per = 90 ,
682+ per_from_bottom = (margin / HEIGHT ) * 100 ,
683+ min_top = 20
684+ )
685+ specs_for_title = (0 , 2 , 20 , 100 )
686+ specs_for_text = (5 , text_top , 50 , 90 )
687+
663688 elif num_of_boxes == 1 :
664689 if code_blocks != []:
665690 # code
666- if slide_num % 2 == 0 :
667- # text_block, width_per, per_from_bottom=0, min_top=30
691+ if text_block == '' :
692+ margin = 5
693+ specs_for_title = (0 , 3 , 20 , 100 )
694+ specs_for_text = (0 , 0 , 0 , 0 )
695+ top = 12
696+ specs_for_boxes = [
697+ (margin , top , 100 - top - margin , 100 - 2 * margin )
698+ ]
699+
700+ elif slide_num % 2 == 0 :
701+ # middle center
668702 width_per = 90
703+ height_range = 60
669704 text_top = _top_spec_for_text_at_bottom (
670705 text_block , width_per = width_per ,
671706 per_from_bottom = (margin / HEIGHT ) * 100 ,
672- min_top = 85
707+ min_top = 100 - height_range / 2.
673708 )
674709 specs_for_boxes = _box_specs_gen (
675710 num_of_boxes , grouptype = 'middle' ,
676- width_range = 58 , height_range = 70 , margin = margin ,
711+ width_range = 50 , height_range = 60 , margin = margin ,
677712 )
678713 specs_for_title = (0 , 3 , 20 , 100 )
679714 specs_for_text = (
680715 5 , text_top , 2 , width_per
681716 )
682717 else :
718+ # right
683719 width_per = 50
684720 text_top = _top_spec_for_text_at_bottom (
685721 text_block , width_per = width_per ,
@@ -688,24 +724,127 @@ def _return_layout_specs(num_of_boxes, url_lines, title_lines, text_block,
688724 )
689725 specs_for_boxes = _box_specs_gen (
690726 num_of_boxes , grouptype = 'rightgroup_v' ,
691- width_range = 50 , margin = 200 ,
727+ width_range = 50 , margin = 40 ,
692728 )
693729 specs_for_title = (0 , 3 , 20 , 50 )
694730 specs_for_text = (
695- 0 , text_top , 2 , width_per
731+ 2 , text_top , 2 , width_per - 2
696732 )
697733 elif url_lines != [] and 'https://plot.ly' in url_lines [0 ]:
698734 # url
699735 if slide_num % 2 == 0 :
700- pass
736+ # top half
737+ width_per = 95
738+ text_top = _top_spec_for_text_at_bottom (
739+ text_block , width_per = width_per ,
740+ per_from_bottom = (margin / HEIGHT ) * 100 ,
741+ min_top = 60
742+ )
743+ specs_for_boxes = _box_specs_gen (
744+ num_of_boxes , grouptype = 'middle' ,
745+ width_range = 100 , height_range = 60 ,
746+ middle_center = 30
747+ )
748+ specs_for_title = (0 , 60 , 20 , 100 )
749+ specs_for_text = (
750+ 2.5 , text_top , 2 , width_per
751+ )
701752 else :
702- pass
753+ # middle across
754+ width_per = 95
755+ text_top = _top_spec_for_text_at_bottom (
756+ text_block , width_per = width_per ,
757+ per_from_bottom = (margin / HEIGHT ) * 100 ,
758+ min_top = 60
759+ )
760+ specs_for_boxes = _box_specs_gen (
761+ num_of_boxes , grouptype = 'middle' ,
762+ width_range = 100 , height_range = 60
763+ )
764+ specs_for_title = (0 , 3 , 20 , 100 )
765+ specs_for_text = (
766+ 2.5 , text_top , 2 , width_per
767+ )
703768 else :
704769 # image
705770 if slide_num % 2 == 0 :
706- pass
771+ # right
772+ width_per = 50
773+ text_top = _top_spec_for_text_at_bottom (
774+ text_block , width_per = width_per ,
775+ per_from_bottom = (margin / HEIGHT ) * 100 ,
776+ min_top = 30
777+ )
778+ specs_for_boxes = _box_specs_gen (
779+ num_of_boxes , grouptype = 'rightgroup_v' ,
780+ width_range = 50 , margin = 0 ,
781+ )
782+ specs_for_title = (0 , 3 , 20 , 50 )
783+ specs_for_text = (
784+ 2 , text_top , 2 , width_per - 2
785+ )
707786 else :
708- pass
787+ # left
788+ width_per = 50
789+ text_top = _top_spec_for_text_at_bottom (
790+ text_block , width_per = width_per ,
791+ per_from_bottom = (margin / HEIGHT ) * 100 ,
792+ min_top = 30
793+ )
794+ specs_for_boxes = _box_specs_gen (
795+ num_of_boxes , grouptype = 'leftgroup_v' ,
796+ width_range = 50 , margin = 0 ,
797+ )
798+ specs_for_title = (50 , 3 , 20 , 50 )
799+ specs_for_text = (
800+ 52 , text_top , 2 , width_per - 2
801+ )
802+ elif num_of_boxes == 2 :
803+ # right stack
804+ width_per = 50
805+ text_top = _top_spec_for_text_at_bottom (
806+ text_block , width_per = width_per ,
807+ per_from_bottom = (margin / HEIGHT ) * 100 ,
808+ min_top = 30
809+ )
810+ specs_for_boxes = [(50 , 0 , 50 , 50 ), (50 , 50 , 50 , 50 )]
811+ specs_for_title = (0 , 3 , 20 , 50 )
812+ specs_for_text = (
813+ 2 , text_top , 2 , width_per - 2
814+ )
815+ elif num_of_boxes == 3 :
816+ # middle top
817+ width_per = 95
818+ text_top = _top_spec_for_text_at_bottom (
819+ text_block , width_per = width_per ,
820+ per_from_bottom = (margin / HEIGHT ) * 100 ,
821+ min_top = 40
822+ )
823+ specs_for_boxes = _box_specs_gen (
824+ num_of_boxes , grouptype = 'middle' ,
825+ width_range = 100 , height_range = 40 , middle_center = 30
826+ )
827+ specs_for_title = (0 , 3 , 20 , 100 )
828+ specs_for_text = (
829+ 2.5 , text_top , 2 , width_per
830+ )
831+ else :
832+ # right stack
833+ width_per = 40
834+ text_top = _top_spec_for_text_at_bottom (
835+ text_block , width_per = width_per ,
836+ per_from_bottom = (margin / HEIGHT ) * 100 ,
837+ min_top = 30
838+ )
839+ specs_for_boxes = _box_specs_gen (
840+ num_of_boxes , grouptype = 'rightgroup_v' ,
841+ width_range = 60 , margin = 0 ,
842+ )
843+ specs_for_title = (0 , 3 , 20 , 40 )
844+ specs_for_text = (
845+ 2 , text_top , 2 , width_per - 2
846+ )
847+
709848
710849 # set title and text style attributes
711850 title_style_attr = {
@@ -728,7 +867,7 @@ def _return_layout_specs(num_of_boxes, url_lines, title_lines, text_block,
728867
729868
730869class Presentation (dict ):
731- def __init__ (self , markdown_string = None , style = 'moods2 ' ):
870+ def __init__ (self , markdown_string = None , style = 'moods ' ):
732871 self ['presentation' ] = {
733872 'slides' : [],
734873 'slidePreviews' : [None for _ in range (496 )],
@@ -739,8 +878,8 @@ def __init__(self, markdown_string=None, style='moods2'):
739878 if markdown_string :
740879 if style not in PRES_THEMES :
741880 raise exceptions .PlotlyError (
742- "Your presentation style must belond to {}" .format (
743- PRES_THEMES
881+ "Your presentation style must be {}" .format (
882+ list_of_options ( PRES_THEMES , conj = 'or' , period = True )
744883 )
745884 )
746885 self ._markdown_to_presentation (markdown_string , style )
0 commit comments