How to find out whether raw text or a table is passed as a parameter?

Thank you for the inspiration. I modified it and so far it seems to be working:

#let TYPE_IMG = 0
#let TYPE_RAW = 1
#let TYPE_TBL = 2

#let get_type(elem) = {
  if elem.func() == raw {
    TYPE_RAW
  } 
  else if elem.func() == table {
    TYPE_TBL
  }
  else if elem.has("children") {
    let t1 = elem.children.position(it => get_type(it) == TYPE_RAW)
    let t2 = elem.children.position(it => get_type(it) == TYPE_TBL)
    
    if t1 != none and t2 == none {TYPE_RAW}
    else if t1 == none and t2 != none {TYPE_TBL}
    else if t1 == none and t2 == none {TYPE_IMG}
    else {
      if t1 < t2 {TYPE_RAW}
      else {TYPE_TBL}
    }
  }
  else if elem.has("body") {
    get_type(elem.body)
  }
  else {
    TYPE_IMG
  }
}
1 Like