let node_parent (dr: node_ref) (b: b)
  : node_parent =
    let is_page_parent (_, p) =
      begin match p.page_document with
      | Some(dr1) when dr1 = dr -> true
      | _ -> false
      end
    in
    let is_node_parent (_, dn) =
      begin match dn with
      | Div_node(_, children) -> List.mem dr children
      | _ -> false
      end
    in
    begin match List.filter is_page_parent b.browser_pages with
    | (pr, _) :: _ -> Page_parent(pr)
    | [] ->
        begin match List.filter is_node_parent b.browser_nodes with
        | (dr1, _) :: _ -> Parent_node(dr1)
        | [] -> No_parent
        end
    end