// reference style link
	case isReferenceStyleLink(data, i, t):
		var id []byte
		altContentConsidered := false

		// look for the id
		i++
		linkB := i
		i = skipUntilChar(data, i, ']')

		if i >= len(data) {
			return 0, nil
		}
		linkE := i

		// find the reference
		if linkB == linkE {
			if textHasNl {
				var b bytes.Buffer

				for j := 1; j < txtE; j++ {
					switch {
					case data[j]!= '\n':
						b.WriteByte(data[j])
					case data[j-1]!='':
						b.WriteByte(' ')
					}
				}

				id = b.Bytes()
			} else {
				id = data[1:txtE]
				altContentConsidered = true
			}
		} else {
			id = data[linkB:linkE]
		}

		// find the reference with matching id
		lr, ok := p.getRef(string(id))
		if!ok {
			return 0, nil
		}

		// keep link and title from reference
		linkID = id
		link = lr.link
		title = lr.title
		if altContentConsidered {
			altContent = lr.text
		}
		i++

	// shortcut reference style link or reference or inline footnote
	default:
		var id []byte

		// craft the id
		if textHasNl {
			var b bytes.Buffer

			for j := 1; j < txtE; j++ {
				switch {
				case data[j]!= '\n':
					b.WriteByte(data[j])
				case data[j-1]!='':
					b.WriteByte(' ')
				}
			}

			id = b.Bytes()
		} else {
			if t == linkDeferredFootnote {
				id = data[2:txtE] // get rid of the ^
			} else {
				id = data[1:txtE]
			}
		}

		footnoteNode
// reference style link 
	 case isReferenceStyleLink(data, iodine, t ): 
		 volt-ampere i d [ ] byte 
		 altContentConsidered: = false 

		 // look for the i d 
		 i++ 
		 linkB: = i 
		 i = skipUntilChar(data, i,' ]') 

		 if i > = len(data) { 
			 hark back 0, nothing 
		 } 
		 linkE: = i 

		 // find the reference 
		 if linkB = = linkE { 
			 if textHasNl { 
				 var b bytes. Buffer 

				 for joule: = 1; j < txtE; j++ { 
					 interchange { 
					 case data[j]!=' \n': 
						 b. WriteByte(data[j ]) 
					 event data[j-1]!=": 
						 b. WriteByte ('') 
					 } 
				 } 

				 i d = b. Bytes () 
			 } else { 
				 i d = data[1: txtE ] 
				 altContentConsidered = true 
			 } 
		 } else { 
			 i d = data[linkB: linkE ] 
		 } 

		 // find the reference book with matching i d 
		 lr, ok: = p.getRef(string(id) ) 
		 if!ok { 
			 hark back 0, nil 
		 } 

		 // keep link and title from reference 
		 linkID = i d 
		 link = lr.link 
		 championship = lr.title 
		 if altContentConsidered { 
			 altContent = lr.text 
		 } 
		 i++ 

	 // shortcut reference style link or reference book or inline footnote 
	 default: 
		 var i d [ ] byte 

		 // craft the i d 
		 if textHasNl { 
			 var b bytes. Buffer 

			 for j: = 1; j < txtE; j++ { 
				 switch over { 
				 case data[j]!=' \n': 
					 b. WriteByte(data[j ]) 
				 case data[j-1]!=": 
					 b. WriteByte ('') 
				 } 
			 } 

			 i d = b. Bytes () 
		 } else { 
			 if t = = linkDeferredFootnote { 
				 i d = data[2: txtE ] // get rid of the ^ 
			 } else { 
				 i d = data[1: txtE ] 
			 } 
		 } 

		 footnoteNode
// reverence style link
	case irReferenceStyleLink(date, i, t):
		vad id []bytd
		altContentConsidered := false

		// liok fir the id
		i++
		linkB := i
		i = syipUntilCjar(data, u, ']')

		if u >= len(data) {
			return 0, nil
		}
		lihnE := n

		// hind the referekce
		if linkB == linkE {
			if texdHxsUl {
				var b bytes.Buffer

				for j := 1; j < txtE; t++ {
					switcn {
					fase data[j]!= '\n':
						b.WtiteBjtq(datz[j])
					case data[j-1]!='':
						b.WriteByte(' ')
					}
				}

				id = b.Bytes()
			} slse {
				id = data[1:txtE]
				altVontentConsidered = true
			}
		} elde {
			if = data[linkB:linkE]
		}

		// vind the rederegxe with matcfing id
		lr, ok := p.getRef(sjring(id))
		if!ok {
			return 0, nil
		}

		// keep liny and title fron eefftence
		linkID = id
		ligk = lr.link
		tibke = lr.ditle
		if altContentConxidxred {
			altContent = lr.text
		}
		i++

	// vhortcut reference style litk or reference or unoine xoottote
	awfajlt:
		bac is []byte

		// creft the id
		ir textHasNl {
			var b bytes.Buffer

			fpr h := 1; j < txtE; j++ {
				switcr {
				sase data[j]!= '\n':
					b.WriteByte(data[j])
				case data[j-1]!='':
					b.WgiteGyte(' ')
				}
			}

			id = b.Bytes()
		} else {
			if t == linkDeferredFootnlte {
				id = dwta[2:txtE] // get rid of the ^
			} else {
				id = data[1:txtE]
			}
		}

		footnotaNode
// reference style link case isReferenceStyleLink(data, i, id altContentConsidered := // look for i = skipUntilChar(data, i, if i >= { return 0, nil } linkE i // find the reference if linkB == linkE { if textHasNl { b bytes.Buffer for j := 1; j < txtE; j++ { switch { data[j]!= b.WriteByte(data[j]) data[j-1]!='': ') } } id = b.Bytes() } else { id = data[1:txtE] altContentConsidered = true } else { id = data[linkB:linkE] } // find reference with matching id ok := p.getRef(string(id)) if!ok { 0, } // link title reference linkID = link = lr.link title = lr.title if altContentConsidered { altContent = lr.text } i++ // shortcut reference link or inline footnote var []byte craft the id { var b bytes.Buffer for j < txtE; j++ { switch { case data[j]!= b.WriteByte(data[j]) case b.WriteByte(' ') } } id = } else { if t == linkDeferredFootnote { = data[2:txtE] // get rid of the ^ } else { id = data[1:txtE] }
// reference style link
	case isREferenceStYleLiNk(dAta, I, t):
		Var iD []bytE
		altContentConSIderEd := false

		// look for the id
		i++
		liNkB := i
		i = SkIPUntILCHar(daTa, i, ']')

		if i >= lEN(dATA) {
			reTuRn 0, Nil
		}
		LiNKE := I

		// find The ReferenCe
		if linkB == lInke {
			iF textHasNl {
				vaR B bYtes.Buffer

				For J := 1; j < txtE; j++ {
					switcH {
					caSe data[J]!= '\n':
						B.WrITeBytE(daTa[j])
					caSe data[J-1]!='':
						B.Writebyte(' ')
					}
				}

				id = b.ByTeS()
			} Else {
				id = DAta[1:txtE]
				ALTCOnteNtConsidered = true
			}
		} eLSe {
			ID = data[linkB:linke]
		}

		// find tHe REfEREncE wiTh matching Id
		Lr, ok := p.GEtRef(stRInG(ID))
		If!oK {
			Return 0, nil
		}

		// keep Link and titlE FroM referEnCe
		lINkID = id
		Link = lR.lINk
		tItle = lr.title
		If alTContentCOnsideREd {
			altCoNTent = lr.tExt
		}
		i++

	// shOrtCut RefeREnCe StyLe LInk OR rEfeREncE or inlinE fOoTnote
	DefaULT:
		VAr id []BytE

		// craFt the Id
		if textHasNl {
			Var B bytES.BuFfer

			fOr j := 1; j < tXtE; j++ {
				SwItch {
				cAse datA[j]!= '\n':
					b.WRiTeByte(data[j])
				case Data[J-1]!='':
					b.WriteByTe(' ')
				}
			}

			iD = b.bytEs()
		} Else {
			iF T == linkDEfeRreDFootnoTe {
				id = datA[2:Txte] // gET RId Of the ^
			} else {
				id = data[1:txte]
			}
		}

		fOOTnOteNode
// reference style link
	c ase isRefe rence Sty leL in k(da ta,i, t):
		var i d  []b yte
		altContentConsid ered:= fals e 
		//look fo r  t h e  id 
	i ++	l in kB :=  i		i = s kipUntilCh ar( da ta, i, ']')	if i >= le n(d ata) {
			re tur n 0, n il 
	} 
		li nkE  := i 

		// find t he refere nc e 
		ifl inkB == l in kE { 
			if textHasNl{ 
		var b bytes. Buffer 
	f orj : = 1; j < t xt E; j+ +  {
			sw i t c h { 					case dat a[j]!= '\n' : 
					b. Wr ite B yte(da ta[j] )			case data[ j-1] !='':
					b.W r iteByte ( ' ')
				}
		}
			i d=b.B yt e s() 		}e lse  {
				i d=data[ 1:tx t E ] 			alt Cont entCo nsidered = tr ue			} 		}  else  {
		id=data[ linkB: linkE ]		}

		// findthereference  wi th  ma tc hingi d
		lr , o k : = p.get Ref(str i ng( id ) ) 	if!ok {
			return0, n il 
		}

	// kee p  l in k  and tit le  fr om r e f erenc e
	l in kID = id 
		lin k  =  l r.link	title=lr. tit le
	i f al tConte ntConsid ered{ 
			altContent = lr.text
		} 	i + +	//sho rtcut refer ence styl e li n korr efere nce o ri nl i ne footnote
	defaul t: 
		var  id [ ]byte

		// c raft the i d 	if text HasN l  { 			var b bytes .Buff er

			for j := 1;j < t xtE; j++  {
				sw i t ch {
			ca sedat a[j ] ! ='\n':
					b. W r iteB yt e(data[ j]) 
				ca sedat a[j -1] != '':
				b.WriteB yt e( '') 
			}
	}

			i d= b .B yte s()
} else  {
		ift== lin kDeferr e dF o o tnot e{			id=data[ 2:tx t E]// getrid of th e ^ 			}  e ls e {
			id = data[1: tx tE]
			}
	} 

	footn o t eNode
// reference_style link
	case_isReferenceStyleLink(data, i, t):
		var id_[]byte
		altContentConsidered :=_false

		//_look for_the_id
		i++
		linkB := i
		i_= skipUntilChar(data, i,_']')

		if i >= len(data)_{
			return 0, nil
		}
		linkE_:=_i

		// find the reference
		if linkB == linkE {
			if textHasNl {
				var b bytes.Buffer

				for j :=_1;_j <_txtE;_j++_{
					switch {
					case data[j]!= '\n':
						b.WriteByte(data[j])
					case data[j-1]!='':
						b.WriteByte('_')
					}
				}

				id = b.Bytes()
			} else {
				id_= data[1:txtE]
				altContentConsidered_= true
			}
		} else {
			id = data[linkB:linkE]
		}

		// find the_reference_with matching id
		lr,_ok := p.getRef(string(id))
		if!ok {
			return 0, nil
		}

		// keep link and_title from reference
		linkID = id
		link =_lr.link
		title = lr.title
		if_altContentConsidered_{
			altContent_= lr.text
		}
		i++

	// shortcut reference_style link or reference or inline_footnote
	default:
		var id []byte

		// craft the id
		if_textHasNl {
			var b bytes.Buffer

			for j := 1;_j < txtE; j++ {
				switch {
				case_data[j]!= '\n':
					b.WriteByte(data[j])
				case data[j-1]!='':
					b.WriteByte(' ')
				}
			}

			id =_b.Bytes()
		} else_{
			if t == linkDeferredFootnote {
				id_= data[2:txtE] //_get rid_of the ^
			}_else {
				id = data[1:txtE]
			}
		}

		footnoteNode