Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ jobs:
if: startsWith(runner.os, 'macOS')
run: |
brew install mupdf-tools imagemagick graphviz cairo libffi
brew link cairo
echo "DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib:${DYLD_FALLBACK_LIBRARY_PATH}" >> $GITHUB_ENV
- name: Install tools required by the regression tests (Windows)
if: startsWith(runner.os, 'Windows')
Expand Down
8 changes: 7 additions & 1 deletion src/rinoh/frontend/sphinx/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ...flowable import DummyFlowable, LabeledFlowable, StaticGroupedFlowables
from ...glossary import GlossaryTerm
from ...image import Image
from ...index import IndexTerm, IndexTarget, InlineIndexTarget
from ...index import IndexTerm, IndexSee, IndexSeeAlso, IndexTarget, InlineIndexTarget
from ...paragraph import Paragraph
from ...reference import Reference
from ...structure import Admonition, AdmonitionFlowables, DefinitionList, List
Expand Down Expand Up @@ -97,6 +97,12 @@ def _index_terms(self):
yield IndexTerm(one, two + ' ' + three)
yield IndexTerm(two, three + ', ' + one)
yield IndexTerm(three, one + ' ' + two)
elif type == 'see':
term, reference = (n.strip() for n in entry_name.split(';'))
yield IndexSee(term, reference)
elif type == 'seealso':
term, reference = (n.strip() for n in entry_name.split(';'))
yield IndexSeeAlso(term, reference)
else:
raise NotImplementedError

Expand Down
46 changes: 42 additions & 4 deletions src/rinoh/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


__all__ = ['IndexSection', 'Index', 'IndexStyle', 'IndexLabel', 'IndexTerm',
'InlineIndexTarget', 'IndexTarget']
'IndexSee', 'IndexSeeAlso', 'InlineIndexTarget', 'IndexTarget']


class IndexSection(Section):
Expand Down Expand Up @@ -49,7 +49,8 @@ def flowables(self, container):
initials = self.get_style('initials', container)
def hande_level(index_entries, level=1):
top_level = level == 1
entries = sorted((name for name in index_entries if name),
entries = sorted((name for name in index_entries
if name and not name.startswith('_index_see')),
key=lambda s: (s.lower(), s))
last_section = None
for entry in entries:
Expand All @@ -61,7 +62,12 @@ def hande_level(index_entries, level=1):
last_section = section
target_ids = [target.get_id(document)
for term, target in subentries.get(None, ())]
yield IndexEntry(term, level, target_ids)
see_references = [('index_see', reference) for reference
in subentries.get('_index_see', ())]
seealso_references = [('index_seealso', reference) for reference
in subentries.get('_index_seealso', ())]
yield IndexEntry(term, level, target_ids,
see_references + seealso_references)
for paragraph in hande_level(subentries, level=level + 1):
yield paragraph

Expand All @@ -76,14 +82,20 @@ class IndexLabel(Paragraph):


class IndexEntry(Paragraph):
def __init__(self, content, level, target_ids=None,
def __init__(self, content, level, target_ids=None, see_references=(),
id=None, style=None, parent=None):
if target_ids:
refs = intersperse((Reference(id, 'page')
for id in target_ids), ', ')
entry_text = content + ', ' + MixedStyledText(refs)
else:
entry_text = content
if see_references:
refs = intersperse((MixedStyledText((StringField(see_label), ' ',
reference))
for see_label, reference in see_references),
'; ')
entry_text = entry_text + ', ' + MixedStyledText(refs)
super().__init__(entry_text, id=id, style=style, parent=parent)
self.index_level = level

Expand All @@ -96,6 +108,22 @@ def __repr__(self):
return type(self).__name__ + super().__repr__()


class IndexSee(tuple):
def __new__(cls, term, reference):
return super().__new__(cls, (term, reference))

def __repr__(self):
return type(self).__name__ + super().__repr__()


class IndexSeeAlso(tuple):
def __new__(cls, term, reference):
return super().__new__(cls, (term, reference))

def __repr__(self):
return type(self).__name__ + super().__repr__()


class IndexTargetBase(Styled):
def __init__(self, index_terms, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -105,6 +133,16 @@ def prepare(self, flowable_target):
super().prepare(flowable_target)
index_entries = flowable_target.document.index_entries
for index_term in self.index_terms:
if isinstance(index_term, IndexSee):
term, reference = index_term
_, subentries = index_entries.setdefault(term, (term, {}))
subentries.setdefault('_index_see', []).append(reference)
continue
if isinstance(index_term, IndexSeeAlso):
term, reference = index_term
_, subentries = index_entries.setdefault(term, (term, {}))
subentries.setdefault('_index_seealso', []).append(reference)
continue
level_entries = index_entries
for term in index_term:
term_str = (term.to_string(flowable_target)
Expand Down
2 changes: 2 additions & 0 deletions src/rinoh/language/cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Language(AttributeType):
warning: title for warning admonitions
seealso: title for see-also admonitions

index_see: title for see label index entries
index_seealso: title for see-also label index entries
"""

languages = {} #: Dictionary mapping codes to :class:`Language`\ s
Expand Down
11 changes: 7 additions & 4 deletions src/rinoh/language/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .cls import Language


CS = Language('cs', 'Česky',
CS = Language('cs', 'čeština',
figure='Obrázek',
table='Tabulka',
contents='Obsah',
Expand All @@ -19,8 +19,8 @@
index='Rejstřík',

# admonitions
attention='Pozor!',
caution='Pozor!',
attention='Opatrnost!',
caution='Pozornost!',
danger='!NEBEZPEČÍ!',
error='Chyba',
hint='Poznámka',
Expand All @@ -29,8 +29,11 @@
tip='Tip',
warning='Varování',
seealso='Viz také',
)

# indexes
index_see='viz',
index_seealso='viz také',
)

CS.no_break_after = ("do od u z ze za k ke o na v ve nad pod za po s se "
"a i že až či").split()
4 changes: 4 additions & 0 deletions src/rinoh/language/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
tip='Tipp',
warning='Warnung',
seealso='Siehe auch',

# indexes
index_see='siehe',
index_seealso='siehe auch',
)
4 changes: 4 additions & 0 deletions src/rinoh/language/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
tip='Tip',
warning='Warning',
seealso='See also',

# indexes
index_see='see',
index_seealso='see also',
)

EN.no_break_after = "a an the".split()
8 changes: 6 additions & 2 deletions src/rinoh/language/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .cls import Language


ES = Language('es', 'Spanish',
ES = Language('es', 'español',
figure='Figura',
table='Tabla',
contents='Contenidos',
Expand All @@ -28,5 +28,9 @@
note='Nota',
tip='Consejo',
warning='Precaución',
seealso='Vea también',
seealso='Véase también',

# indexes
index_see='véase',
index_seealso='véase también',
)
20 changes: 13 additions & 7 deletions src/rinoh/language/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@
from .cls import Language


FR = Language('fr', 'Français',
FR = Language('fr', 'français',
figure='Figure',
table='Tableau',
contents='Table des Matières',
list_of_figures='Liste des Figures',
list_of_tables='Liste des Tableaux',
contents='Table des matières',
list_of_figures='Liste des figures',
list_of_tables='Liste des tableaux',
chapter='Chapitre',
index='Index',

# admonitions
attention='Attention!',
caution='Prudence!',
danger='!DANGER!',
attention='Attention !',
caution='Prudence !',
danger='! DANGER !',
error='Erreur',
hint='Conseil',
important='Important',
note='Note',
tip='Astuce',
warning='Avertissement',
seealso='Voir aussi',

# indexes
index_see='voir',
index_seealso='voir aussi',
)

FR.no_break_after = "-".split()
10 changes: 7 additions & 3 deletions src/rinoh/language/hu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from .cls import Language


HU = Language('hu', 'Hungarian',
HU = Language('hu', 'magyar',
contents='Tartalomjegyzék',
list_of_figures='Ábrák Listája',
list_of_tables='Asztalok Listája',
list_of_figures='Ábrák listája',
list_of_tables='Táblázatok listája',
chapter='Fejezet',
index='Index',

Expand All @@ -27,4 +27,8 @@
tip='Tipp',
warning='Figyelmeztetés',
seealso='Lásd még',

# indexes
index_see='lásd',
index_seealso='lásd még',
)
12 changes: 8 additions & 4 deletions src/rinoh/language/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from .cls import Language


IT = Language('it', 'Italiano',
IT = Language('it', 'italiano',
figure='Figura',
table='Tabelle',
table='Tabella',
contents='Contenuti',
list_of_figures='Elenco delle Figure',
list_of_tables='Elenco delle Tabelle',
list_of_figures='Elenco delle figure',
list_of_tables='Elenco delle tabelle',
chapter='Capitolo',
index='Indice',

Expand All @@ -29,4 +29,8 @@
tip='Suggerimento',
warning='Avvertimento',
seealso='Vedi anche',

# indexes
index_see='vedi',
index_seealso='vedi anche',
)
4 changes: 4 additions & 0 deletions src/rinoh/language/nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
tip='Tip',
warning='Waarschuwing',
seealso='Zie ook',

# indexes
index_see='zie',
index_seealso='zie ook',
)
12 changes: 8 additions & 4 deletions src/rinoh/language/pl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from .cls import Language


PL = Language('pl', 'Polski',
PL = Language('pl', 'polski',
figure='Ilustracja',
table='Tabela',
contents='Spis Treści',
list_of_figures='Spis Ilustracji',
list_of_tables='Spis Tabel',
contents='Spis treści',
list_of_figures='Spis ilustracji',
list_of_tables='Spis tabel',
chapter='Rozdział',
index='Skorowidz',

Expand All @@ -29,4 +29,8 @@
tip='Porada',
warning='Ostrzeżenie',
seealso='Zobacz również',

# indexes
index_see='zobacz',
index_seealso='zobacz również',
)
Loading