@@ -277,14 +277,18 @@ var specialRunes map[rune]actionConstructor = map[rune]actionConstructor{
277277 return nil
278278 },
279279 '!' : func (d * documentConstructor ) SpecialAction {
280- return func (d * documentConstructor , a * list.Element ) {
281- d .HoldAction = true
282- if d .Scanner .Cur == '[' {
283- d .push (d .referenceConstructor (Image ))
284- }
280+ if d .blockCheck () {
281+ return func (d * documentConstructor , a * list.Element ) {
282+ d .HoldAction = true
283+ if d .Scanner .Cur == '[' {
284+ d .push (d .referenceConstructor (Image ))
285+ }
285286
286- d .actStack .remove (a )
287+ d .actStack .remove (a )
288+ }
287289 }
290+
291+ return nil
288292 },
289293 '[' : func (d * documentConstructor ) SpecialAction {
290294 if d .blockCheck () {
@@ -475,13 +479,16 @@ func strongOrEm(d *documentConstructor, r rune) SpecialAction {
475479
476480func listOrLine (d * documentConstructor , a * list.Element , t rune , e * BlockObject ) SpecialAction {
477481 var l int
482+ var f int
478483
479484 if e == nil {
480485 e = NewGeneric ()
481486 e .appendContent (d .Scanner .Cur )
482487 l = 1
488+ f = 1
483489 } else {
484490 l = 2
491+ f = 2
485492 }
486493
487494 s := 0
@@ -508,9 +515,13 @@ func listOrLine(d *documentConstructor, a *list.Element, t rune, e *BlockObject)
508515 debug (l )
509516 e .appendContent (d .Scanner .Cur )
510517 l ++
518+ if f < 3 && ! b {
519+ f ++
520+ }
521+ } else if d .Scanner .Cur == ' ' && ! b {
511522 b = true
523+ s ++
512524 } else if d .Scanner .Cur != ' ' {
513- b = true
514525 if s >= 1 {
515526 debug ("appending as a new list" )
516527 l := NewList (0 , string (t ), Unordered )
@@ -525,19 +536,33 @@ func listOrLine(d *documentConstructor, a *list.Element, t rune, e *BlockObject)
525536 if p := d .queueCheck (Paragraph ) ; p != nil {
526537 debug ("appending to paragraph" )
527538 p .Value .(* BlockObject ).Content = p .Value .(* BlockObject ).Content + string ('\n' ) + e .Content
528- d . actStack . remove ( a )
539+ p . Value .( * BlockObject ). Initialized = true
529540 } else {
530541 debug ("appending as paragraph" )
542+ d .Scanner .Pos = l + s - 1
531543 e .Type = Paragraph
532544 e .Initialized = true
533545 d .push (e )
534- d .actStack .remove (a )
535546 }
547+
548+ switch f {
549+ case 1 :
550+ d .push (NewInline (d .Scanner .Pos , EmText ))
551+ case 2 :
552+ d .push (NewInline (d .Scanner .Pos - 1 , StrongText ))
553+ case 3 :
554+ d .push (NewInline (d .Scanner .Pos , StrongText ))
555+ d .push (NewInline (d .Scanner .Pos - 1 , EmText ))
556+ }
557+
558+ d .Scanner .Pos ++ // why does this need to occur?
559+ d .actStack .remove (a )
536560 }
537- } else if ! b {
561+ } else if b {
538562 debug (s )
539563 e .appendContent (d .Scanner .Cur )
540564 s ++
565+
541566 }
542567 }
543568}
@@ -548,6 +573,8 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
548573 * pre = 0
549574 }
550575
576+ d .Scanner .Pos = 0
577+
551578 var validOp bool
552579 var hold bool
553580 // var tight bool
@@ -572,8 +599,9 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
572599 }
573600
574601 NewItem := func () (* BlockObject , SpecialAction ) {
575- e := NewListItem ()
576602 d .Scanner .Pos = - 1
603+ e := NewListItem ()
604+ d .HoldAction = false
577605 a := func (d * documentConstructor , a * list.Element ) {
578606 e .Initialized = true
579607 if d .Scanner .Cur == '\n' {
@@ -668,7 +696,9 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
668696 if string (d .Scanner .Cur ) == lattrib .Op {
669697 e .appendContent (d .Scanner .Cur )
670698 l ++
699+ } else if d .Scanner .Cur == ' ' && ! b {
671700 b = true
701+ s ++
672702 } else if d .Scanner .Cur != ' ' {
673703 d .HoldAction = false
674704 b = true
@@ -677,19 +707,19 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
677707 e .Content = e .Content [1 :] + string (d .Scanner .Cur )
678708 d .push (e )
679709 d .push (act )
680- d .actStack .remove (_a )
681710 } else {
682711 debug ("creating paragraph, closing list" )
683712 e .Type = Paragraph
684713 e .Initialized = true
685714
686715 closeList (a )
687716 d .actStack .remove (a )
688- d .actStack .remove (_a )
689717
690718 d .push (e )
691719 }
692- } else if ! b {
720+
721+ d .actStack .remove (_a )
722+ } else if b {
693723 e .appendContent (d .Scanner .Cur )
694724 s ++
695725 }
@@ -701,11 +731,19 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
701731 li = e
702732 act = a
703733
704- for _ , s := range c {
705- e .appendContent (s )
734+ if len (c ) == 1 && len (c [0 ]) == 1 {
735+ e .Initialized = true // very specific, but it implies that this is a single character
736+ d .Scanner .Pos = d .Scanner .Pos + 1
737+ } else {
738+ for _ , s := range c {
739+ e .appendContent (s )
740+ d .Scanner .Pos = d .Scanner .Pos + len (s )
741+ }
706742 }
707743
744+
708745 hold = true
746+ d .HoldAction = false
709747 d .push (e )
710748 d .push (a )
711749 }
@@ -748,14 +786,14 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
748786 d .HoldAction = true
749787 if d .Scanner .Cur == ' ' {
750788 l := NewList (* pre , c , Unordered )
751- * pre = 0
752789
753790 debug ("creating new list" )
754791 d .push (d .newListController (& hold , pre , l , "" ))
755792 } else {
756793 d .HoldAction = false
757794 debug ("appending as content to current list item" )
758795 c = c + string (d .Scanner .Cur )
796+ d .Scanner .Pos = d .Scanner .Pos - * pre
759797 li .Content = li .Content + c
760798 li .Initialized = true
761799 d .push (act )
@@ -768,6 +806,7 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
768806 debug ("appending as content to current list item" )
769807 d .HoldAction = false
770808 li .appendContent ('\n' )
809+ d .Scanner .Pos = d .Scanner .Pos - * pre
771810 li .Initialized = true
772811 d .push (act )
773812 }
@@ -803,6 +842,7 @@ func (d *documentConstructor) newListController(phold *bool, pre *int, l *BlockO
803842 debug ("current prefix spaces: " )
804843 debug (* pre )
805844 } else if d .Scanner .Cur == '\n' {
845+ * pre = 0
806846 nl ++
807847 } else {
808848 if phold != nil {
0 commit comments