From d8fbd37e8fcda1d431bea6da69195e7c7cea1e03 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Tue, 22 Sep 2009 21:49:55 -0400 Subject: [PATCH] finally build table-of-contents.html dynamically (better late than never) --- index.html | 2 + table-of-contents.html | 871 +++++++++++++++++++++-------------------- util/buildtoc.py | 47 +++ util/htmlminimizer.py | 4 + 4 files changed, 499 insertions(+), 425 deletions(-) create mode 100644 util/buildtoc.py diff --git a/index.html b/index.html index 7806c53..bdf438a 100644 --- a/index.html +++ b/index.html @@ -25,6 +25,7 @@ h1:before,h2:before{content:''}

Also available on dead trees!
Dive Into Python 3
Pre-order now, get it October 16th!
+

  1. What’s New in “Dive Into Python 3”
  2. Installing Python @@ -48,6 +49,7 @@ h1:before,h2:before{content:''}
  3. Special Method Names
  4. Where to Go From Here
+

The book is freely licensed under the Creative Commons Attribution Share-Alike license. You can download it as HTML or PDF. Über-geeks can also clone the Mercurial repository: diff --git a/table-of-contents.html b/table-of-contents.html index 187b7a7..1443aea 100755 --- a/table-of-contents.html +++ b/table-of-contents.html @@ -1,425 +1,446 @@ - - -Table of contents - Dive Into Python 3 - - - - - -

 
-

You are here: Home Dive Into Python 3 -

Table of Contents

-
    -
  1. What’s New In “Dive Into Python 3” -
  2. Installing Python -
      -
    1. Diving In -
    2. Which Python Is Right For You? -
    3. Installing on Microsoft Windows -
    4. Installing on Mac OS X -
    5. Installing on Ubuntu Linux -
    6. Installing on Other Platforms -
    7. Using The Python Shell -
    8. Python Editors and IDEs -
    -
  3. Your first Python program -
      -
    1. Diving In -
    2. Declaring functions -
    3. Writing readable code -
        -
      1. Docstrings -
      -
    4. The import search path -
    5. Everything is an object -
        -
      1. What’s an object? -
      -
    6. Indenting code -
    7. Exceptions -
    8. Running scripts -
    9. Further reading -
    -
  4. Native Python datatypes -
      -
    1. Diving In -
    2. Booleans -
    3. Numbers -
        -
      1. Coercing integers to floats and vice-versa -
      2. Common numerical operations -
      3. Fractions -
      4. Trigonometry -
      5. Numbers in a boolean context -
      -
    4. Lists -
        -
      1. Creating a list -
      2. Slicing a list -
      3. Adding items to a list -
      4. Searching for values in a list -
      5. Lists in a boolean context -
      -
    5. Tuples -
        -
      1. Assigning Multiple Values At Once -
      -
    6. Sets -
        -
      1. Creating A Set -
      2. Modifying A Set -
      3. Removing Items From A Set -
      4. Common Set Operations -
      5. Sets In A Boolean Context -
      -
    7. Dictionaries -
        -
      1. Creating a dictionary -
      2. Modifying a dictionary -
      3. Mixed-value dictionaries -
      4. Dictionaries in a boolean context -
      -
    8. None -
        -
      1. None in a boolean context -
      -
    9. Further reading -
    -
  5. Comprehensions -
      -
    1. Diving In -
    2. Working With Files And Directories -
        -
      1. The Current Working Directory -
      2. Working With Filenames and Directory Names -
      3. Listing Directories -
      4. Getting File Metadata -
      5. Constructing Absolute Pathnames -
      -
    3. List Comprehensions -
    4. Dictionary Comprehensions -
        -
      1. Other Fun Stuff To Do With Dictionary Comprehensions -
      -
    5. Set Comprehensions -
    6. Further Reading -
    -
  6. Strings -
      -
    1. Some Boring Stuff You Need To Understand Before You Can Dive In -
    2. Unicode -
    3. Diving In -
    4. Formatting Strings -
        -
      1. Compound Field Names -
      2. Format Specifiers -
      -
    5. Other Common String Methods -
        -
      1. Slicing A String -
      -
    6. Strings vs. Bytes -
    7. Postscript: Character Encoding Of Python Source Code -
    8. Further Reading -
    -
  7. Regular expressions -
      -
    1. Diving In -
    2. Case study: street addresses -
    3. Case study: Roman numerals -
        -
      1. Checking for thousands -
      2. Checking for hundreds -
      -
    4. Using the {n,m} Syntax -
        -
      1. Checking for tens and ones -
      -
    5. Verbose regular expressions -
    6. Case study: parsing phone numbers -
    7. Summary -
    -
  8. Closures & Generators -
      -
    1. Diving In -
    2. I know, let’s use regular expressions! -
    3. A list of functions -
    4. A list of patterns -
    5. A file of patterns -
    6. Generators -
        -
      1. A Fibonacci generator -
      2. A plural rule generator -
      -
    -
  9. Classes & Iterators -
      -
    1. Diving In -
    2. Defining Classes -
    3. Instantiating Classes -
    4. Instance Variables -
    5. A Fibonacci iterator -
    6. A Plural Rule Iterator -
    7. Further Reading -
    -
  10. Advanced Iterators -
      -
    1. Diving In -
    2. Finding all occurrences of a pattern -
    3. Finding the unique items in a sequence -
    4. Making assertions -
    5. Generator expressions -
    6. Calculating Permutations… The Lazy Way! -
    7. Other Fun Stuff in the itertools Module -
    8. A New Kind Of String Manipulation -
    9. Evaluating Arbitrary Strings As Python Expressions -
    10. Putting It All Together -
    11. Further Reading -
    -
  11. Unit Testing -
      -
    1. (Not) Diving In -
    2. A single Question -
    3. “Halt and Catch Fire” -
    4. More Halting, More Fire -
    5. And One More Thing… -
    6. A Pleasing Symmetry -
    7. More Bad Input -
    -
  12. Refactoring -
      -
    1. Diving In -
    2. Handling Changing Requirements -
    3. Refactoring -
    4. Summary -
    -
  13. Files -
      -
    1. Diving In -
    2. Reading From Text Files -
        -
      1. Character Encoding Rears Its Ugly Head -
      2. Stream Objects -
      3. Reading Data From A Text File -
      4. Closing Files -
      5. Closing Files Automatically -
      6. Reading Data One Line At A Time -
      -
    3. Writing to Text Files -
        -
      1. Character Encoding Again -
      -
    4. Binary Files -
    5. Stream Objects From Non-File Sources -
        -
      1. Handling Compressed Files -
      -
    6. Standard Input, Output, and Error -
        -
      1. Redirecting Standard Output -
      -
    7. Further Reading -
    -
  14. XML -
      -
    1. Diving In -
    2. A 5-Minute Crash Course in XML -
    3. The Structure Of An Atom Feed -
    4. Parsing XML -
        -
      1. Elements Are Lists -
      2. Attributes Are Dictonaries -
      -
    5. Searching For Nodes Within An XML Document -
    6. Going Further With lxml -
        -
      1. Customizing Your XML Parser -
      2. Incremental Parsing -
      -
    7. Generating XML -
    8. Further Reading -
    -
  15. Serializing Python Objects -
      -
    1. Diving In -
        -
      1. A Quick Note About The Examples in This Chapter -
      -
    2. Saving Data to a Pickle File -
    3. Loading Data from a Pickle File -
    4. Pickling Without a File -
    5. Bytes and Strings Rear Their Ugly Heads Again -
    6. Debugging Pickle Files -
    7. Serializing Python Objects to be Read by Other Languages -
    8. Saving Data to a JSON File -
    9. Mapping of Python Datatypes to JSON -
    10. Serializing Datatypes Unsupported by JSON -
    11. Loading Data from a JSON File -
    12. Further Reading -
    -
  16. HTTP Web Services -
      -
    1. Diving In -
    2. Features of HTTP -
        -
      1. Caching -
      2. Last-Modified Checking -
      3. ETags -
      4. Compression -
      5. Redirects -
      -
    3. How Not To Fetch Data Over HTTP -
    4. What’s On The Wire? -
    5. Introducing httplib2 -
        -
      1. How httplib2 Handles Caching -
      2. How httplib2 Handles Last-Modified and ETag Headers -
      3. How http2lib Handles Compression -
      4. How httplib2 Handles Redirects -
      -
    6. Beyond HTTP GET -
    7. Beyond HTTP POST -
    8. Further Reading -
    -
  17. Case study: porting chardet to Python 3 -
      -
    1. Diving In -
    2. What is Character Encoding Auto-Detection? -
        -
      1. Isn’t That Impossible? -
      2. Does Such An Algorithm Exist? -
      -
    3. Introducing The chardet Module -
        -
      1. UTF-n With A BOM -
      2. Escaped Encodings -
      3. Multi-Byte Encodings -
      4. Single-Byte Encodings -
      5. windows-1252 -
      -
    4. Running 2to3 -
    5. A Short Digression Into Multi-File Modules -
    6. Fixing What 2to3 Can’t -
        -
      1. False is invalid syntax -
      2. No module named constants -
      3. Name 'file' is not defined -
      4. Can’t use a string pattern on a bytes-like object -
      5. Can't convert 'bytes' object to str implicitly -
      6. Unsupported operand type(s) for +: 'int' and 'bytes' -
      7. ord() expected string of length 1, but int found -
      8. Unorderable types: int() >= str() -
      9. Global name 'reduce' is not defined -
      -
    7. Summary -
    -
  18. Packaging Python libraries -
      -
    1. Diving In -
    2. Things Distutils Can’t Do For You -
    3. Directory Structure -
    4. Writing Your Setup Script -
    5. Classifying Your Package -
        -
      1. Examples of Good Package Classifiers -
      -
    6. Specifying Additional Files With A Manifest -
    7. Checking Your Setup Script for Errors -
    8. Creating a Source Distribution -
    9. Creating a Graphical Installer -
        -
      1. Building Installable Packages for Other Operating Systems -
      -
    10. Adding Your Software to The Python Package Index -
    11. The Many Possible Futures of Python Packaging -
    12. Further Reading -
    -
  19. Appendix A. Porting code to Python 3 with 2to3 -
      -
    1. Diving In -
    2. print statement -
    3. Unicode string literals -
    4. unicode() global function -
    5. long data type -
    6. <> comparison -
    7. has_key() dictionary method -
    8. Dictionary methods that return lists -
    9. Modules that have been renamed or reorganized -
        -
      1. http -
      2. urllib -
      3. dbm -
      4. xmlrpc -
      5. Other modules -
      -
    10. Relative imports within a package -
    11. next() iterator method -
    12. filter() global function -
    13. map() global function -
    14. reduce() global function -
    15. apply() global function -
    16. intern() global function -
    17. exec statement -
    18. execfile statement -
    19. repr literals (backticks) -
    20. try...except statement -
    21. raise statement -
    22. throw method on generators -
    23. xrange() global function -
    24. raw_input() and input() global functions -
    25. func_* function attributes -
    26. xreadlines() I/O method -
    27. lambda functions that take a tuple instead of multiple parameters -
    28. Special method attributes -
    29. __nonzero__ special method -
    30. Octal literals -
    31. sys.maxint -
    32. callable() global function -
    33. zip() global function -
    34. StandardError() exception -
    35. types module constants -
    36. isinstance() global function -
    37. basestring datatype -
    38. itertools module -
    39. sys.exc_type, sys.exc_value, sys.exc_traceback -
    40. List comprehensions over tuples -
    41. os.getcwdu() function -
    42. Metaclasses -
    43. Matters of style -
        -
      1. set() literals -
      2. buffer() global function -
      3. Whitespace around commas -
      4. Common idioms -
      -
    -
  20. Appendix B. Special Method Names -
      -
    1. Diving In -
    2. Basics -
    3. Classes That Act Like Iterators -
    4. Computed Attributes -
    5. Classes That Act Like Functions -
    6. Classes That Act Like Sequences -
    7. Classes That Act Like Dictionaries -
    8. Classes That Act Like Numbers -
    9. Classes That Can Be Compared -
    10. Classes That Can Be Serialized -
    11. Classes That Can Be Used in a with Block -
    12. Really Esoteric Stuff -
    13. Further Reading -
    -
  21. Appendix C. Where to go from here -
      -
    1. Things to read -
    2. Where to look for Python 3-compatible code -
    -
-

© 2001–9 Mark Pilgrim - + + +Table of contents - Dive Into Python 3 + + + + + +

 
+

You are here: Home Dive Into Python 3 +

Table of Contents

+ +
    +
  1. What’s New in “Dive Into Python 3” +
      +
    1. a.k.a. “the minus level” +
    +
  2. Installing Python +
      +
    1. Diving In +
    2. Which Python Is Right For You? +
    3. Installing on Microsoft Windows +
    4. Installing on Mac OS X +
    5. Installing on Ubuntu Linux +
    6. Installing on Other Platforms +
    7. Using The Python Shell +
    8. Python Editors and IDEs +
    +
  3. Your First Python Program +
      +
    1. Diving In +
    2. Declaring Functions +
        +
      1. Optional and Named Arguments +
      +
    3. Writing Readable Code +
        +
      1. Documentation Strings +
      +
    4. The import Search Path +
    5. Everything Is An Object +
        +
      1. What’s An Object? +
      +
    6. Indenting Code +
    7. Exceptions +
        +
      1. Catching Import Errors +
      +
    8. Unbound Variables +
    9. Everything is Case-Sensitive +
    10. Running Scripts +
    11. Further Reading +
    +
  4. Native Datatypes +
      +
    1. Diving In +
    2. Booleans +
    3. Numbers +
        +
      1. Coercing Integers To Floats And Vice-Versa +
      2. Common Numerical Operations +
      3. Fractions +
      4. Trigonometry +
      5. Numbers In A Boolean Context +
      +
    4. Lists +
        +
      1. Creating A List +
      2. Slicing A List +
      3. Adding Items To A List +
      4. Searching For Values In A List +
      5. Removing Items From A List +
      6. Removing Items From A List: Bonus Round +
      7. Lists In A Boolean Context +
      +
    5. Tuples +
        +
      1. Tuples In A Boolean Context +
      2. Assigning Multiple Values At Once +
      +
    6. Sets +
        +
      1. Creating A Set +
      2. Modifying A Set +
      3. Removing Items From A Set +
      4. Common Set Operations +
      5. Sets In A Boolean Context +
      +
    7. Dictionaries +
        +
      1. Creating A Dictionary +
      2. Modifying A Dictionary +
      3. Mixed-Value Dictionaries +
      4. Dictionaries In A Boolean Context +
      +
    8. None +
        +
      1. None In A Boolean Context +
      +
    9. Further Reading +
    +
  5. Comprehensions +
      +
    1. Diving In +
    2. Working With Files And Directories +
        +
      1. The Current Working Directory +
      2. Working With Filenames and Directory Names +
      3. Listing Directories +
      4. Getting File Metadata +
      5. Constructing Absolute Pathnames +
      +
    3. List Comprehensions +
    4. Dictionary Comprehensions +
        +
      1. Other Fun Stuff To Do With Dictionary Comprehensions +
      +
    5. Set Comprehensions +
    6. Further Reading +
    +
  6. Strings +
      +
    1. Some Boring Stuff You Need To Understand Before You Can Dive In +
    2. Unicode +
    3. Diving In +
    4. Formatting Strings +
        +
      1. Compound Field Names +
      2. Format Specifiers +
      +
    5. Other Common String Methods +
        +
      1. Slicing A String +
      +
    6. Strings vs. Bytes +
    7. Postscript: Character Encoding Of Python Source Code +
    8. Further Reading +
    +
  7. Regular Expressions +
      +
    1. Diving In +
    2. Case Study: Street Addresses +
    3. Case Study: Roman Numerals +
        +
      1. Checking For Thousands +
      2. Checking For Hundreds +
      +
    4. Using The {n,m} Syntax +
        +
      1. Checking For Tens And Ones +
      +
    5. Verbose Regular Expressions +
    6. Case study: Parsing Phone Numbers +
    7. Summary +
    +
  8. Closures & Generators +
      +
    1. Diving In +
    2. I Know, Let’s Use Regular Expressions! +
    3. A List Of Functions +
    4. A List Of Patterns +
    5. A File Of Patterns +
    6. Generators +
        +
      1. A Fibonacci Generator +
      2. A Plural Rule Generator +
      +
    7. Further Reading +
    +
  9. Classes & Iterators +
      +
    1. Diving In +
    2. Defining Classes +
        +
      1. The __init__() Method +
      +
    3. Instantiating Classes +
    4. Instance Variables +
    5. A Fibonacci Iterator +
    6. A Plural Rule Iterator +
    7. Further Reading +
    +
  10. Advanced Iterators +
      +
    1. Diving In +
    2. Finding all occurrences of a pattern +
    3. Finding the unique items in a sequence +
    4. Making assertions +
    5. Generator expressions +
    6. Calculating Permutations… The Lazy Way! +
    7. Other Fun Stuff in the itertools Module +
    8. A New Kind Of String Manipulation +
    9. Evaluating Arbitrary Strings As Python Expressions +
    10. Putting It All Together +
    11. Further Reading +
    +
  11. Unit Testing +
      +
    1. (Not) Diving In +
    2. A Single Question +
    3. “Halt And Catch Fire” +
    4. More Halting, More Fire +
    5. And One More Thing… +
    6. A Pleasing Symmetry +
    7. More Bad Input +
    +
  12. Refactoring +
      +
    1. Diving In +
    2. Handling Changing Requirements +
    3. Refactoring +
    4. Summary +
    +
  13. Files +
      +
    1. Diving In +
    2. Reading From Text Files +
        +
      1. Character Encoding Rears Its Ugly Head +
      2. Stream Objects +
      3. Reading Data From A Text File +
      4. Closing Files +
      5. Closing Files Automatically +
      6. Reading Data One Line At A Time +
      +
    3. Writing to Text Files +
        +
      1. Character Encoding Again +
      +
    4. Binary Files +
    5. Streams Objects From Non-File Sources +
        +
      1. Handling Compressed Files +
      +
    6. Standard Input, Output, and Error +
        +
      1. Redirecting Standard Output +
      +
    7. Further Reading +
    +
  14. XML +
      +
    1. Diving In +
    2. A 5-Minute Crash Course in XML +
    3. The Structure Of An Atom Feed +
    4. Parsing XML +
        +
      1. Elements Are Lists +
      2. Attributes Are Dictonaries +
      +
    5. Searching For Nodes Within An XML Document +
    6. Going Further With lxml +
    7. Generating XML +
    8. Parsing Broken XML +
    9. Further Reading +
    +
  15. Serializing Python Objects +
      +
    1. Diving In +
        +
      1. A Quick Note About The Examples in This Chapter +
      +
    2. Saving Data to a Pickle File +
    3. Loading Data from a Pickle File +
    4. Pickling Without a File +
    5. Bytes and Strings Rear Their Ugly Heads Again +
    6. Debugging Pickle Files +
    7. Serializing Python Objects to be Read by Other Languages +
    8. Saving Data to a JSON File +
    9. Mapping of Python Datatypes to JSON +
    10. Serializing Datatypes Unsupported by JSON +
    11. Loading Data from a JSON File +
    12. Further Reading +
    +
  16. HTTP Web Services +
      +
    1. Diving In +
    2. Features of HTTP +
        +
      1. Caching +
      2. Last-Modified Checking +
      3. ETags +
      4. Compression +
      5. Redirects +
      +
    3. How Not To Fetch Data Over HTTP +
    4. What’s On The Wire? +
    5. Introducing httplib2 +
        +
      1. A Short Digression To Explain Why httplib2 Returns Bytes Instead of Strings +
      2. How httplib2 Handles Caching +
      3. How httplib2 Handles Last-Modified and ETag Headers +
      4. How http2lib Handles Compression +
      5. How httplib2 Handles Redirects +
      +
    6. Beyond HTTP GET +
    7. Beyond HTTP POST +
    8. Further Reading +
    +
  17. Case Study: Porting chardet to Python 3 +
      +
    1. Diving In +
    2. What is Character Encoding Auto-Detection? +
        +
      1. Isn’t That Impossible? +
      2. Does Such An Algorithm Exist? +
      +
    3. Introducing The chardet Module +
        +
      1. UTF-n With A BOM +
      2. Escaped Encodings +
      3. Multi-Byte Encodings +
      4. Single-Byte Encodings +
      5. windows-1252 +
      +
    4. Running 2to3 +
    5. A Short Digression Into Multi-File Modules +
    6. Fixing What 2to3 Can’t +
        +
      1. False is invalid syntax +
      2. No module named constants +
      3. Name 'file' is not defined +
      4. Can’t use a string pattern on a bytes-like object +
      5. Can't convert 'bytes' object to str implicitly +
      6. Unsupported operand type(s) for +: 'int' and 'bytes' +
      7. ord() expected string of length 1, but int found +
      8. Unorderable types: int() >= str() +
      9. Global name 'reduce' is not defined +
      +
    7. Summary +
    +
  18. Packaging Python Libraries +
      +
    1. Diving In +
    2. Things Distutils Can’t Do For You +
    3. Directory Structure +
    4. Writing Your Setup Script +
    5. Classifying Your Package +
        +
      1. Examples of Good Package Classifiers +
      +
    6. Specifying Additional Files With A Manifest +
    7. Checking Your Setup Script for Errors +
    8. Creating a Source Distribution +
    9. Creating a Graphical Installer +
        +
      1. Building Installable Packages for Other Operating Systems +
      +
    10. Adding Your Software to The Python Package Index +
    11. The Many Possible Futures of Python Packaging +
    12. Further Reading +
    +
  19. Porting Code to Python 3 with 2to3 +
      +
    1. Diving In +
    2. print statement +
    3. Unicode string literals +
    4. unicode() global function +
    5. long data type +
    6. <> comparison +
    7. has_key() dictionary method +
    8. Dictionary methods that return lists +
    9. Modules that have been renamed or reorganized +
        +
      1. http +
      2. urllib +
      3. dbm +
      4. xmlrpc +
      5. Other modules +
      +
    10. Relative imports within a package +
    11. next() iterator method +
    12. filter() global function +
    13. map() global function +
    14. reduce() global function +
    15. apply() global function +
    16. intern() global function +
    17. exec statement +
    18. execfile statement +
    19. repr literals (backticks) +
    20. try...except statement +
    21. raise statement +
    22. throw method on generators +
    23. xrange() global function +
    24. raw_input() and input() global functions +
    25. func_* function attributes +
    26. xreadlines() I/O method +
    27. lambda functions that take a tuple instead of multiple parameters +
    28. Special method attributes +
    29. __nonzero__ special method +
    30. Octal literals +
    31. sys.maxint +
    32. callable() global function +
    33. zip() global function +
    34. StandardError exception +
    35. types module constants +
    36. isinstance() global function +
    37. basestring datatype +
    38. itertools module +
    39. sys.exc_type, sys.exc_value, sys.exc_traceback +
    40. List comprehensions over tuples +
    41. os.getcwdu() function +
    42. Metaclasses +
    43. Matters of style +
        +
      1. set() literals (explicit) +
      2. buffer() global function (explicit) +
      3. Whitespace around commas (explicit) +
      4. Common idioms (explicit) +
      +
    +
  20. Special Method Names +
      +
    1. Diving In +
    2. Basics +
    3. Classes That Act Like Iterators +
    4. Computed Attributes +
    5. Classes That Act Like Functions +
    6. Classes That Act Like Sequences +
    7. Classes That Act Like Dictionaries +
    8. Classes That Act Like Numbers +
    9. Classes That Can Be Compared +
    10. Classes That Can Be Serialized +
    11. Classes That Can Be Used in a with Block +
    12. Really Esoteric Stuff +
    13. Further Reading +
    +
  21. Where to Go From Here +
      +
    1. Things to Read +
    2. Where To Look For Python 3-Compatible Code +
    +
+ +

© 2001–9 Mark Pilgrim + diff --git a/util/buildtoc.py b/util/buildtoc.py new file mode 100644 index 0000000..f98e2c9 --- /dev/null +++ b/util/buildtoc.py @@ -0,0 +1,47 @@ +#!/usr/bin/python3 + +import re + +# get list of chapters +chapters = [] +for line in open('index.html'): + if not line.count('', 1)[0]) +sections = {} + +for filename in chapters: + chapter_id = filename.split(".", 1)[0] + with open(filename, encoding="utf-8") as f: data = f.read() + sections[chapter_id] = re.findall("(.*?)')[1].split('')[0] + +full_toc = ['', '

    '] +chapter_id = '' +for line in short_toc.splitlines(): + if not line.count('', '>', line) + line = line.replace('
  1. ', '
  2. '.format(chapter_id)) + full_toc.append(line) + section_number = 0 + previous_section_level = section_level = 1 + for section_level, section_id, section_title in sections[chapter_id]: + section_level = int(section_level) + if section_level < previous_section_level: + full_toc.append('
') + elif section_level > previous_section_level: + full_toc.append('
    ') + section_number += 1 + full_toc.append('
  1. {2}'.format(chapter_id, section_id, section_title)) + previous_section_level = section_level + section_level = int(section_level) + while (section_level > 1): + full_toc.append('
') + section_level -= 1 +full_toc.append('') +full_toc.append('') +with open('table-of-contents.html', encoding="utf-8") as f: data = f.read() +with open('table-of-contents.html', mode="w", encoding="utf-8") as f: + f.write(data.split('')[0] + "\n".join(full_toc) + data.split('')[1]) diff --git a/util/htmlminimizer.py b/util/htmlminimizer.py index 6539757..42a74af 100755 --- a/util/htmlminimizer.py +++ b/util/htmlminimizer.py @@ -21,6 +21,10 @@ with open(output_file, 'w', encoding="utf-8") as _out, open(input_file, encoding if "url(i/" in line: line = line.replace("url(i/", "url(http://" + next(available_server) + "/dip3/") + # remove selected comments (but not all comments, because some are conditional comments for IE compat) + line = line.replace('', '') + line = line.replace('', '') + # replace entities with Unicode characters for e in re.findall('&(.+?);', line): if e in ('lt', 'amp', 'quot', 'apos', 'nbsp'):