@@ -159,6 +159,9 @@ template showSlideNumber*() =
159159template disableVerticalCentering * () =
160160 nb.context[" disableCentering" ] = true
161161
162+ proc addStyle * (doc: NbDoc , style: string ) =
163+ doc.context[" nb_style" ] = doc.context[" nb_style" ].vString & " \n " & style
164+
162165proc revealTheme * (doc: var NbDoc ) =
163166 doc.partials[" document" ] = document
164167 doc.partials[" head" ] = head
@@ -190,6 +193,15 @@ proc revealTheme*(doc: var NbDoc) =
190193 doc.context[" slidesTheme" ] = " black"
191194 doc.context[" nb_style" ] = " "
192195
196+ doc.addStyle: """
197+ .nimislides-li {
198+ position: relative;
199+ }
200+
201+ .nimislides-li::before {
202+ position: absolute;
203+ }
204+ """
193205
194206 try :
195207 let slidesConfig = loadTomlSection (doc.rawCfg, " nimislides" , NimiSlidesConfig )
@@ -199,9 +211,6 @@ proc revealTheme*(doc: var NbDoc) =
199211 except CatchableError :
200212 discard # if it doesn't exists, just let it be
201213
202- proc addStyle * (doc: NbDoc , style: string ) =
203- doc.context[" nb_style" ] = doc.context[" nb_style" ].vString & " \n " & style
204-
205214var currentFragment* , currentSlideNumber* : int
206215
207216proc slideOptionsToAttributes * (options: SlideOptions ): string =
@@ -378,7 +387,7 @@ template listItem*(animation: seq[FragmentAnimation], body: untyped) =
378387 for an in animation:
379388 classString &= $ an & " "
380389 fadeInNext:
381- nbRawHtml: """ <li class="fragment $1" data-fragment-index="$2" data-fragment-index-nimib="$2"> """ % [classString, $ currentFragment]
390+ nbRawHtml: """ <li class="fragment $1 nimislides-li " data-fragment-index="$2" data-fragment-index-nimib="$2"> """ % [classString, $ currentFragment]
382391 currentFragment += 1
383392 body
384393 nbRawHtml: " </li>"
@@ -393,72 +402,67 @@ template listItem*(body: untyped) =
393402proc toHSlice * (h: HSlice [int , int ]): HSlice [int , int ] = h
394403proc toHSlice * (h: int ): HSlice [int , int ] = h .. h
395404
405+
406+ proc toSet * (x: set [range [0 .. 65535 ]]): set [range [0 .. 65535 ]] = x
407+ proc toSet * (x: int ): set [range [0 .. 65535 ]] = {x}
408+ proc toSet * (x: Slice [int ]): set [range [0 .. 65535 ]] =
409+ for y in x:
410+ result .incl y
411+ proc toSet * (x: seq [Slice [int ]]): set [range [0 .. 65535 ]] =
412+ for s in x:
413+ result .incl s.toSet ()
414+
415+
396416template animateCode * (lines: string , body: untyped ) =
397417 newNbCodeBlock (" animateCode" , body):
398418 nb.blk.context[" highlightLines" ] = lines
399419 captureStdout (nb.blk.output):
400420 body
401421
402- template animateCode * (lines: varargs [seq [ HSlice [ int , int ]] ], body: untyped ) =
422+ template animateCode * (lines: varargs [set [ range [ 0 .. 65535 ]], toSet ], body: untyped ) =
403423 # # Shows code and its output just like nbCode, but highlights different lines of the code in the order specified in `lines`.
404- # # lines: Specify which lines to highlight and in which order. (Must be specified as a seq[HSlice])
424+ # # lines: Specify which lines to highlight and in which order. The lines can be specified using either:
425+ # # - An `int` (highlight single line)
426+ # # - A slice `x..y` (highlight a range of consequative lines)
427+ # # - A set {x, y..z} (highlight any combination of lines)
405428 # # Ex:
406429 # # ```nim
407- # # animateCode(@[1..1], @[3.. 4, 6..6] ): body
430+ # # animateCode(1, 2..3, { 4, 6} ): body
408431 # # ```
409- # # This will first highlight line 1, then lines 3, 4 and 6.
432+ # # This will first highlight line 1, then lines 2 and 3, and lastly line 4 and 6.
410433 newNbCodeBlock (" animateCode" , body):
411434 var linesString: string
412435 if lines.len > 0 :
413436 linesString &= " |"
414437 for lineBundle in lines:
415438 for line in lineBundle:
416- linesString &= $ line.a & " - " & $ line.b & " ,"
439+ linesString &= $ line & " ,"
417440 linesString &= " |"
418441 if lines.len > 0 :
419442 linesString = linesString[0 .. ^ 3 ]
420443 nb.blk.context[" highlightLines" ] = linesString
421444 captureStdout (nb.blk.output):
422445 body
423446
424- template animateCode * (lines: varargs [HSlice [int , int ], toHSlice], body: untyped ) =
425- # # Shows code and its output just like nbCode, but highlights different lines of the code in the order specified in `lines`.
426- # # lines: Specify which lines to highlight and in which order. (Must be specified as a HSlice)
427- # # Ex:
428- # # ```nim
429- # # animateCode(1..1, 2..3, 5..5, 4..4): body
430- # # ```
431- # # This will first highlight line 1, then lines 2 and 3, then line 5 and last line 4.
432- var s: seq [seq [HSlice [int , int ]]]
433- for line in lines:
434- s.add @ [line]
435- animateCode (s):
436- body
437-
438447template newAnimateCodeBlock * (cmd: untyped , impl: untyped ) =
439- template `cmd` * (lines: varargs [seq [HSlice [int , int ]]], body: untyped ) =
440- newNbCodeBlock (cmd.astToStr, body):
448+ const cmdStr = astToStr (cmd)
449+
450+ template `cmd` * (lines: varargs [set [range [0 .. 65535 ]], toSet], body: untyped ) =
451+ newNbCodeBlock (cmdStr, body):
441452 var linesString: string
442453 if lines.len > 0 :
443454 linesString &= " |"
444455 for lineBundle in lines:
445456 for line in lineBundle:
446- linesString &= $ line.a & " - " & $ line.b & " ,"
457+ linesString &= $ line & " ,"
447458 linesString &= " |"
448459 if lines.len > 0 :
449460 linesString = linesString[0 .. ^ 3 ]
450461 nb.blk.context[" highlightLines" ] = linesString
451462 impl (body)
452463
453- template `cmd` * (lines: varargs [HSlice [int , int ], toHSlice], body: untyped ) =
454- var s: seq [seq [HSlice [int , int ]]]
455- for line in lines:
456- s.add @ [line]
457- `cmd` (s):
458- body
459-
460- nb.partials[cmd.astToStr] = nb.partials[" animateCode" ]
461- nb.renderPlans[cmd.astToStr] = nb.renderPlans[" animateCode" ]
464+ nb.partials[cmdStr] = nb.partials[" animateCode" ]
465+ nb.renderPlans[cmdStr] = nb.renderPlans[" animateCode" ]
462466
463467template typewriter * (textMessage: string , typeSpeed = 50 , alignment = " center" ) =
464468 let localText = textMessage
0 commit comments