/*
 * Copyright (c) 2017-2023 XMLmind Software. All rights reserved.
 *
 * This file is part of the XMLmind XML Editor project.
 * For conditions of distribution and use, see the accompanying legal.txt file.
 *
 * Displays the TOC of a DocBook 5 document. 
 */

@namespace "http://docbook.org/ns/docbook";
@namespace db5 "http://docbook.org/ns/docbook";
@namespace su "java:com.xmlmind.util.StringUtil";

@import url(docbook-config:css/inline.imp);

*,
*:comment,
*:processing-instruction,
topic > *,
set > *,
book > *,
part > *,
reference > *,
preface > *,
chapter > *,
article > *,
appendix > *,
section > *,
sect1 > *,
sect2 > *,
sect3 > *,
sect4 > *,
sect5 > *,
info > * {
    display: none;
}

topic,
set,
book,
part,
reference,
preface,
chapter,
article,
appendix {
    display: block;
    collapsible: yes;
    not-collapsible-head: 1; /* title or info */
    margin-top: 0.5ex;
    margin-left: 4ex;
}

refentry {
    display: block;
    content: "RefEntry: " xpath("join(.//db5:refname, ', ')");
    margin-left: 4ex;
}

partintro,
acknowledgements,
dedication,
toc,
bibliography,
index,
setindex,
colophon,
partintro,
glossary {
    display: block;
    content: xpath("if(./db5:info/db5:title, string(./db5:info/db5:title), ./db5:title, string(./db5:title), su:capitalize(local-name()))");
    margin-left: 4ex;
}

section,
sect1,
sect2,
sect3,
sect4,
sect5 {
    display: block;
    margin-left: 4ex;
}

*:root {
    margin-top: 0;
    margin-left: 0;
}

info:contains-element(title) {
    display: block; 
}

title {
    display: block;
    margin: 0 2px; /* This trick allows to make a difference between the title 
                      and its containing division when pressing Up/Down in
                      the NavigationPane. */
}

title * {
    display: inline;
}

title indexterm {
    display: none;
}

topic > title,
topic > info > title,
set > title,
book > title,
part > title,
reference > title,
preface > title,
chapter > title,
article > title,
appendix > title,
set > info > title,
book > info > title,
part > info > title,
reference > info > title,
preface > info > title,
chapter > info > title,
article > info > title,
appendix > info > title {
    font-size: 1.1em;
    font-weight: bold;
    margin-top: 0.25ex;
    margin-bottom: 0.25ex;
}

article > appendix > title,
article > appendix > info > title {
    font-size: 1em;
    font-weight: normal;
    margin-top: 0;
    margin-bottom: 0;
}

/*
 * Title which is the the first child of a division.
 */

@property-value collapserex() collapser(hide-when-disabled, yes,
                                        show-level-menu, yes);

set > title:first-child:before {
    content: collapserex() " Set: ";
}

book > title:first-child:before {
    content: collapserex() " Book: ";
}

reference > title:first-child:before {
    content: collapserex() " Reference: ";
}

preface > title:first-child:before {
    content: collapserex() " Preface: ";
}

article > title:first-child:before {
    content: collapserex() " Article: ";
}

part > title:first-child:before { 
    content: collapserex() " Part " simple-counter(n-, upper-roman) ": "; 
}

chapter > title:first-child:before { 
    content: collapserex() " Chapter " simple-counter(n-, decimal) ": "; 
}

appendix > title:first-child:before { 
    content: collapserex() " Appendix " simple-counter(n-, upper-alpha) ": "; 
}

article > appendix > title:first-child:before { 
    content: "Appendix " simple-counter(n-, upper-alpha) ": "; 
}

sect1 > title:first-child:before { 
    content: simple-counter(n-) ". "; 
}

sect2 > title:first-child:before { 
    content: simple-counter(nn-) ". "; 
}

sect3 > title:first-child:before { 
    content: simple-counter(nnn-) ". "; 
}

sect4 > title:first-child:before { 
    content: simple-counter(nnnn-) ". "; 
}

section > title:first-child:before { 
    content: simple-counter(n-) ". "; 
}

section section > title:first-child:before { 
    content: simple-counter(nn-) ". "; 
}

section section section > title:first-child:before { 
    content: simple-counter(nnn-) ". "; 
}

section section section section > title:first-child:before { 
    content: simple-counter(nnnn-) ". "; 
}

section section section * section > title:first-child:before { 
    content: ""; 
}

/*
 * Title contained in the first info child of a division.
 */

set > info:first-child > title:before {
    content: collapserex() " Set: ";
}

book > info:first-child > title:before {
    content: collapserex() " Book: ";
}

reference > info:first-child > title:before {
    content: collapserex() " Reference: ";
}

preface > info:first-child > title:before {
    content: collapserex() " Preface: ";
}

article > info:first-child > title:before {
    content: collapserex() " Article: ";
}

part > info:first-child > title:before { 
    content: collapserex() " Part " simple-counter(n--, upper-roman) ": "; 
}

chapter > info:first-child > title:before { 
    content: collapserex() " Chapter " simple-counter(n--, decimal) ": "; 
}

appendix > info:first-child > title:before { 
    content: collapserex() " Appendix " simple-counter(n--, upper-alpha) ": "; 
}

article > appendix > info:first-child > title:before { 
    content: "Appendix " simple-counter(n--, upper-alpha) ": "; 
}

sect1 > info:first-child > title:before { 
    content: simple-counter(n--) ". "; 
}

sect2 > info:first-child > title:before { 
    content: simple-counter(nn--) ". "; 
}

sect3 > info:first-child > title:before { 
    content: simple-counter(nnn--) ". "; 
}

sect4 > info:first-child > title:before { 
    content: simple-counter(nnnn--) ". "; 
}

section > info:first-child > title:before { 
    content: simple-counter(n--) ". "; 
}

section section > info:first-child > title:before { 
    content: simple-counter(nn--) ". "; 
}

section section section > info:first-child > title:before { 
    content: simple-counter(nnn--) ". "; 
}

section section section section > info:first-child > title:before { 
    content: simple-counter(nnnn--) ". "; 
}

section section section * section > info:first-child > title:before { 
    content: ""; 
}

/*
 * Topic is not numbered.
 */
topic > title:first-child:before,
topic > info:first-child > title:before {
    content: collapserex() " "; 
}

/*
 * Tooltip
 */

/* First ancestor having property sourceURL is at worst the document itself. */
@property-value lookup-source-url() 
    xpath("relativize-uri(property('{http://www.xmlmind.com/xmleditor/namespace/property}sourceURL', ancestor-or-self::node()[property('{http://www.xmlmind.com/xmleditor/namespace/property}sourceURL')][1]), property('{http://www.xmlmind.com/xmleditor/namespace/property}sourceURL', /))");

topic,
set,
book,
part,
reference,
preface,
chapter,
article,
appendix,
refentry,
partintro,
acknowledgements,
dedication,
toc,
bibliography,
index,
setindex,
colophon,
partintro,
glossary,
section,
sect1,
sect2,
sect3,
sect4,
sect5 {
    tooltip-content: lookup-source-url();
}

topic[xml|id],
set[xml|id],
book[xml|id],
part[xml|id],
reference[xml|id],
preface[xml|id],
chapter[xml|id],
article[xml|id],
appendix[xml|id],
refentry[xml|id],
partintro[xml|id],
acknowledgements[xml|id],
dedication[xml|id],
toc[xml|id],
bibliography[xml|id],
index[xml|id],
setindex[xml|id],
colophon[xml|id],
partintro[xml|id],
glossary[xml|id],
section[xml|id],
sect1[xml|id],
sect2[xml|id],
sect3[xml|id],
sect4[xml|id],
sect5[xml|id] {
    tooltip-content: lookup-source-url() "#" attr(xml|id);
}

