mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
DocBook: support @ in index when used for sorting.
This commit is contained in:
parent
1eb19cb8e3
commit
34ea4080ec
147
autotests/export/docbook/index.lyx
Normal file
147
autotests/export/docbook/index.lyx
Normal file
@ -0,0 +1,147 @@
|
||||
#LyX 2.4 created this file. For more info see https://www.lyx.org/
|
||||
\lyxformat 608
|
||||
\begin_document
|
||||
\begin_header
|
||||
\save_transient_properties true
|
||||
\origin unavailable
|
||||
\textclass article
|
||||
\use_default_options true
|
||||
\maintain_unincluded_children no
|
||||
\language american
|
||||
\language_package default
|
||||
\inputencoding utf8
|
||||
\fontencoding auto
|
||||
\font_roman "default" "default"
|
||||
\font_sans "default" "default"
|
||||
\font_typewriter "default" "default"
|
||||
\font_math "auto" "auto"
|
||||
\font_default_family default
|
||||
\use_non_tex_fonts false
|
||||
\font_sc false
|
||||
\font_roman_osf false
|
||||
\font_sans_osf false
|
||||
\font_typewriter_osf false
|
||||
\font_sf_scale 100 100
|
||||
\font_tt_scale 100 100
|
||||
\use_microtype false
|
||||
\use_dash_ligatures true
|
||||
\graphics default
|
||||
\default_output_format default
|
||||
\output_sync 0
|
||||
\bibtex_command default
|
||||
\index_command default
|
||||
\float_placement class
|
||||
\float_alignment class
|
||||
\paperfontsize default
|
||||
\use_hyperref false
|
||||
\papersize default
|
||||
\use_geometry false
|
||||
\use_package amsmath 1
|
||||
\use_package amssymb 1
|
||||
\use_package cancel 1
|
||||
\use_package esint 1
|
||||
\use_package mathdots 1
|
||||
\use_package mathtools 1
|
||||
\use_package mhchem 1
|
||||
\use_package stackrel 1
|
||||
\use_package stmaryrd 1
|
||||
\use_package undertilde 1
|
||||
\cite_engine basic
|
||||
\cite_engine_type default
|
||||
\use_bibtopic false
|
||||
\use_indices false
|
||||
\paperorientation portrait
|
||||
\suppress_date false
|
||||
\justification true
|
||||
\use_refstyle 1
|
||||
\use_minted 0
|
||||
\use_lineno 0
|
||||
\index Index
|
||||
\shortcut idx
|
||||
\color #008000
|
||||
\end_index
|
||||
\secnumdepth 3
|
||||
\tocdepth 3
|
||||
\paragraph_separation indent
|
||||
\paragraph_indentation default
|
||||
\is_math_indent 0
|
||||
\math_numbering_side default
|
||||
\quotes_style english
|
||||
\dynamic_quotes 0
|
||||
\papercolumns 1
|
||||
\papersides 1
|
||||
\paperpagestyle default
|
||||
\tablestyle default
|
||||
\tracking_changes false
|
||||
\output_changes false
|
||||
\change_bars false
|
||||
\postpone_fragile_content true
|
||||
\html_math_output 0
|
||||
\html_css_as_file 0
|
||||
\html_be_strict false
|
||||
\docbook_table_output 0
|
||||
\docbook_mathml_prefix 1
|
||||
\end_header
|
||||
|
||||
\begin_body
|
||||
|
||||
\begin_layout Title
|
||||
Index tests
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Text
|
||||
\begin_inset Index idx
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Text
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Index idx
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
SortedAs@Text
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Index idx
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Primary!Secondary
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Index idx
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
SortedPrimary@Primary!Secondary
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Index idx
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Primary!Secondary!Tertiary
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
\end_layout
|
||||
|
||||
\end_body
|
||||
\end_document
|
7
autotests/export/docbook/index.xml
Normal file
7
autotests/export/docbook/index.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- This DocBook file was created by LyX 2.4.0dev
|
||||
See https://www.lyx.org/ for more information -->
|
||||
<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
|
||||
<title>Index tests</title>
|
||||
<para>Text<indexterm><primary>Text</primary></indexterm><indexterm><primary sortas='SortedAs'>Text</primary></indexterm><indexterm><primary>Primary</primary><secondary>Secondary</secondary></indexterm><indexterm><primary sortas='SortedPrimary'>Primary</primary><secondary>Secondary</secondary></indexterm><indexterm><primary>Primary</primary><secondary>Secondary</secondary><tertiary>Tertiary</tertiary></indexterm>.</para>
|
||||
</article>
|
@ -194,16 +194,15 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
|
||||
InsetText::latex(ots, runparams);
|
||||
docstring latexString = trim(odss.str());
|
||||
|
||||
// Check whether there are unsupported things.
|
||||
if (latexString.find(from_utf8("@")) != latexString.npos) {
|
||||
docstring error = from_utf8("Unsupported feature: an index entry contains an @. "
|
||||
// Check whether there are unsupported things. @ is supported, but only for sorting, without specific formatting.
|
||||
if (latexString.find(from_utf8("@\\")) != lyx::docstring::npos) {
|
||||
docstring error = from_utf8("Unsupported feature: an index entry contains an @\\. "
|
||||
"Complete entry: \"") + latexString + from_utf8("\"");
|
||||
LYXERR0(error);
|
||||
xs << XMLStream::ESCAPE_NONE << (from_utf8("<!-- Output Error: ") + error + from_utf8(" -->\n"));
|
||||
// TODO: implement @ using the sortas attribute (on primary, secondary, tertiary).
|
||||
}
|
||||
|
||||
// Handle several indices.
|
||||
// Handle several indices (indicated in the inset instead of the raw latexString).
|
||||
docstring indexType = from_utf8("");
|
||||
if (buffer().masterBuffer()->params().use_indices) {
|
||||
indexType += " type=\"" + params_.index + "\"";
|
||||
@ -212,14 +211,25 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
|
||||
// Split the string into its main constituents: terms, and command (see, see also, range).
|
||||
size_t positionVerticalBar = latexString.find(from_ascii("|")); // What comes before | is (sub)(sub)entries.
|
||||
docstring indexTerms = latexString.substr(0, positionVerticalBar);
|
||||
docstring command = latexString.substr(positionVerticalBar + 1);
|
||||
docstring command;
|
||||
if (positionVerticalBar != lyx::docstring::npos) {
|
||||
command = latexString.substr(positionVerticalBar + 1);
|
||||
}
|
||||
|
||||
// Handle sorting issues, with @.
|
||||
vector<docstring> sortingElements = getVectorFromString(indexTerms, from_ascii("@"), false);
|
||||
docstring sortAs;
|
||||
if (sortingElements.size() == 2) {
|
||||
sortAs = sortingElements[0];
|
||||
indexTerms = sortingElements[1];
|
||||
}
|
||||
|
||||
// Handle primary, secondary, and tertiary terms (entries, subentries, and subsubentries, for LaTeX).
|
||||
vector<docstring> terms = getVectorFromString(indexTerms, from_ascii("!"), false);
|
||||
|
||||
// Handle ranges. Happily, (| and |) can only be at the end of the string! However, | may be trapped by the
|
||||
bool hasStartRange = latexString.find(from_ascii("|(")) != latexString.npos;
|
||||
bool hasEndRange = latexString.find(from_ascii("|)")) != latexString.npos;
|
||||
// Handle ranges. Happily, (| and |) can only be at the end of the string!
|
||||
bool hasStartRange = latexString.find(from_ascii("|(")) != lyx::docstring::npos;
|
||||
bool hasEndRange = latexString.find(from_ascii("|)")) != lyx::docstring::npos;
|
||||
if (hasStartRange || hasEndRange) {
|
||||
// Remove the ranges from the command if they do not appear at the beginning.
|
||||
size_t index = 0;
|
||||
@ -258,7 +268,7 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
|
||||
} else {
|
||||
see = list;
|
||||
|
||||
if (see.find(from_ascii(",")) != see.npos) {
|
||||
if (see.find(from_ascii(",")) != std::string::npos) {
|
||||
docstring error = from_utf8("Several index terms found as \"see\"! Only one is acceptable. "
|
||||
"Complete entry: \"") + latexString + from_utf8("\"");
|
||||
LYXERR0(error);
|
||||
@ -275,6 +285,12 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
|
||||
// If there are such things in the index entry, then this code may miserably fail. For example, for "Peter|(textbf",
|
||||
// no range will be detected.
|
||||
// TODO: Could handle formatting as significance="preferred"?
|
||||
if (!command.empty()) {
|
||||
docstring error = from_utf8("Unsupported feature: an index entry contains a | with an unsupported command, ")
|
||||
+ command + from_utf8(". ") + from_utf8("Complete entry: \"") + latexString + from_utf8("\"");
|
||||
LYXERR0(error);
|
||||
xs << XMLStream::ESCAPE_NONE << (from_utf8("<!-- Output Error: ") + error + from_utf8(" -->\n"));
|
||||
}
|
||||
|
||||
// Write all of this down.
|
||||
if (terms.empty() && !hasEndRange) {
|
||||
@ -335,7 +351,12 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
|
||||
} else {
|
||||
xs << xml::StartTag("indexterm", attrs);
|
||||
if (!terms.empty()) { // hasEndRange has no content.
|
||||
xs << xml::StartTag("primary");
|
||||
docstring attr;
|
||||
if (!sortAs.empty()) {
|
||||
attr = from_utf8("sortas='") + sortAs + from_utf8("'");
|
||||
}
|
||||
|
||||
xs << xml::StartTag("primary", attr);
|
||||
xs << terms[0];
|
||||
xs << xml::EndTag("primary");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user