func (c *Card) Body(ctx context.Context, face int) (body string, err error) {
	defer profile("Body")()
	cardFace, ok := faces[face]
	if !ok {
		return "", errors.Errorf("unrecognized card face %d", face)
	}
	if c.note == nil {
		return "", errors.New("card hasn't been fetched")
	}

	funcMap, err := c.model.FuncMap(c, face)
	if err != nil {
		return "", errors.Wrap(err, "failed to get FuncMap")
	}

	tmpl, err := c.model.Template(ctx)
	if err != nil {
		return "", errors.Wrap(err, "failed to generate template")
	}

	data := cardData{
		Card: c,
		Face: face,
		Note: c.note,
		// Model:    model,
		BaseURI: c.appURL,
		Fields:  make(map[string]template.HTML, len(c.model.Fields)),
	}

	for i, field := range c.model.Fields {
		switch c.note.FieldValues[i].Type() {
		case fb.AnkiField, fb.TextField:
			data.Fields[field.Name] = template.HTML(c.note.FieldValues[i].Text)
		}
	}

	htmlDoc := new(bytes.Buffer)
	if e := tmpl.Funcs(funcMap).Execute(htmlDoc, data); e != nil {
		return "", errors.Wrap(e, "template execution")
	}
	// return htmlDoc.String(), nil

	iframeScript, _ := c.model.IframeScript()
	newBody, err := prepareBody(cardFace, c.TemplateID(), string(iframeScript), htmlDoc)
	if err != nil {
		return "", errors.Wrap(err, "prepare body")
	}

	nbString := string(newBody)
	log.Debugf("new body size = %d\n", len(nbString))
	return nbString, nil
}
// Body produces the HTML body of the card to be displayed.
Body produces the HTML body of the card to be displayed.
// Body produces the HTML body of the card to be displayed .
func (c *Card) Body(ctx context.Context, face int) (body string, err error) {
	defer profile("Body")()
	cardFace, ok := faces[face]
	if !ok {
		return "", errors.Errorf("unrecognized card face %d", face)
	}
	if c.note == nil {
		return "", errors.New("card hasn't been fetched")
	}
	funcMap, err := c.model.FuncMap(c, face)
	if err != nil {
		return "", errors.Wrap(err, "failed to get FuncMap")
	}
	tmpl, err := c.model.Template(ctx)
	if err != nil {
		return "", errors.Wrap(err, "failed to generate template")
	}
	data := cardData{
		Card: c,
		Face: face,
		Note: c.note,
		BaseURI: c.appURL,
		Fields:  make(map[string]template.HTML, len(c.model.Fields)),
	}
	for i, field := range c.model.Fields {
		switch c.note.FieldValues[i].Type() {
		case fb.AnkiField, fb.TextField:
			data.Fields[field.Name] = template.HTML(c.note.FieldValues[i].Text)
		}
	}
	htmlDoc := new(bytes.Buffer)
	if e := tmpl.Funcs(funcMap).Execute(htmlDoc, data); e != nil {
		return "", errors.Wrap(e, "template execution")
	}
	iframeScript, _ := c.model.IframeScript()
	newBody, err := prepareBody(cardFace, c.TemplateID(), string(iframeScript), htmlDoc)
	if err != nil {
		return "", errors.Wrap(err, "prepare body")
	}
	nbString := string(newBody)
	log.Debugf("new body size = %d\n", len(nbString))
	return nbString, nil
}
func ( c * Card ) Body ( ctx context . Context , face int ) ( body string , err error ) { defer profile ( " " ) ( ) cardFace , ok := faces [ face ] if ! ok { return " " , errors . Errorf ( " " , face ) } if c . note == nil { return " " , errors . New ( " " ) } funcMap , err := c . model . FuncMap ( c , face ) if err != nil { return " " , errors . Wrap ( err , " " ) } tmpl , err := c . model . Template ( ctx ) if err != nil { return " " , errors . Wrap ( err , " " ) } data := cardData { Card : c , Face : face , Note : c . note , BaseURI : c . appURL , Fields : make ( map [ string ] template . HTML , len ( c . model . Fields ) ) , } for i , field := range c . model . Fields { switch c . note . FieldValues [ i ] . Type ( ) { case fb . AnkiField , fb . TextField : data . Fields [ field . Name ] = template . HTML ( c . note . FieldValues [ i ] . Text ) } } htmlDoc := new ( bytes . Buffer ) if e := tmpl . Funcs ( funcMap ) . Execute ( htmlDoc , data ) ; e != nil { return " " , errors . Wrap ( e , " " ) } iframeScript , _ := c . model . IframeScript ( ) newBody , err := prepareBody ( cardFace , c . TemplateID ( ) , string ( iframeScript ) , htmlDoc ) if err != nil { return " " , errors . Wrap ( err , " " ) } nbString := string ( newBody ) log . Debugf ( " \n " , len ( nbString ) ) return nbString , nil }
Body produces the HTML body of the card to be displayed.
Body produces the HTML body of the card to be displayed .
// Model:    model, // return htmlDoc.String(), nil