@@ -637,17 +637,21 @@ def pdf(self):
637
637
"""
638
638
super ().pdf ()
639
639
640
- # we need to build master index file which lists all
641
- # of the PDF file. So we create an html file, based on
642
- # the file index.html from the "reference_top" target.
643
-
644
- # First build the top reference page. This only takes a few seconds.
645
- getattr (get_builder ('reference_top' ), 'html' )()
640
+ # We want to build master index file which lists all of the PDF file.
641
+ # We modify the file index.html from the "reference_top" target, if it
642
+ # exists. Otherwise, we are done.
646
643
647
644
from sage .env import SAGE_DOC
648
645
reference_dir = os .path .join (SAGE_DOC , 'html' , 'en' , 'reference' )
649
646
output_dir = self ._output_dir ('pdf' )
650
647
648
+ # Check if the top reference index.html exists.
649
+ try :
650
+ with open (os .path .join (reference_dir , 'index.html' )) as f :
651
+ html = f .read ()
652
+ except FileNotFoundError :
653
+ return
654
+
651
655
# Install in output_dir a symlink to the directory containing static files.
652
656
# Prefer relative path for symlinks.
653
657
relpath = os .path .relpath (reference_dir , output_dir )
@@ -657,8 +661,6 @@ def pdf(self):
657
661
pass
658
662
659
663
# Now modify top reference index.html page and write it to output_dir.
660
- with open (os .path .join (reference_dir , 'index.html' )) as f :
661
- html = f .read ()
662
664
html_output_dir = os .path .dirname (reference_dir )
663
665
664
666
# Fix links in navigation bar
@@ -1051,13 +1053,33 @@ def get_modules(self, filename):
1051
1053
Given a filename for a reST file, return an iterator for
1052
1054
all of the autogenerated reST files that it includes.
1053
1055
"""
1056
+ from sage .features .all import all_features
1057
+
1054
1058
# Create the regular expression used to detect an autogenerated file
1055
1059
auto_re = re .compile (r'^\s*(..\/)*(sage(_docbuild)?\/[\w\/]*)\s*$' )
1056
1060
1057
1061
# Read the lines
1058
1062
with open (filename ) as f :
1059
1063
lines = f .readlines ()
1064
+
1065
+ skip = False
1060
1066
for line in lines :
1067
+ if skip :
1068
+ if not line .strip () or line .count (' ' , 0 ) >= indent :
1069
+ continue
1070
+ skip = False
1071
+ elif line .lstrip ().lower ().startswith ('.. only::' ):
1072
+ try :
1073
+ tag_name = line [line .index ('feature_' ) + 8 :].strip ()
1074
+ for feature in all_features ():
1075
+ if tag_name == feature .name .replace ('.' , '_' ):
1076
+ break
1077
+ else :
1078
+ skip = True
1079
+ indent = line .index ('.. ' ) + 3
1080
+ continue
1081
+ except ValueError :
1082
+ pass
1061
1083
match = auto_re .match (line )
1062
1084
if match :
1063
1085
yield match .group (2 ).replace (os .path .sep , '.' )
0 commit comments