Skip to content

Commit

Permalink
Misc doc generator changes.
Browse files Browse the repository at this point in the history
* Consistently use <a id="..."/> for anchors.
* Repeat all the errors at the end.
* Fix bug in replacing references in non-api docs.
Change: 147259560
  • Loading branch information
tensorflower-gardener committed Feb 12, 2017
1 parent 0bbb224 commit e6c776d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions tensorflow/tools/docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import argparse
import inspect
import os
import sys

import six
import tensorflow as tf
Expand Down Expand Up @@ -301,7 +302,7 @@ class UpdateTags(py_guide_parser.PyGuideParser):
"""Rewrites a Python guide so that each section has an explicit tag."""

def process_section(self, line_number, section_title, tag):
self.replace_line(line_number, '## %s {#%s}' % (section_title, tag))
self.replace_line(line_number, '## %s<a id="%s"/>' % (section_title, tag))


def other_docs(src_dir, output_dir, visitor, doc_index):
Expand Down Expand Up @@ -342,7 +343,7 @@ def other_docs(src_dir, output_dir, visitor, doc_index):

output = parser.replace_references(
md_string, relative_path_to_root, visitor.duplicate_of,
visitor.index, doc_index)
doc_index=doc_index, index=visitor.index)
open(full_out_path, 'w').write(header + output)

print('Done.')
Expand Down Expand Up @@ -394,3 +395,6 @@ def _main(src_dir, output_dir, base_dir):

flags, _ = argument_parser.parse_known_args()
_main(flags.src_dir, flags.output_dir, flags.base_dir)
if parser.all_errors:
print('Errors during processing:' + '\n '.join(parser.all_errors))
sys.exit(1)
14 changes: 11 additions & 3 deletions tensorflow/tools/docs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
# A regular expression for capturing a @{symbol} reference.
SYMBOL_REFERENCE_RE = re.compile(r'@\{([^}]+)\}')

# Log of all reported errors
all_errors = []


def log_error(s):
all_errors.append(s)
print('ERROR:', s)


def documentation_path(full_name):
"""Returns the file path for the documentation for the given API symbol.
Expand Down Expand Up @@ -185,7 +193,7 @@ def _one_ref(string, relative_path_to_root, duplicate_of, doc_index, index):
return '[%s](%s%s)' % (
link_text, os.path.join(relative_path_to_root, doc_index[string].url),
hash_tag)
print('ERROR: Handle doc reference "@{%s}"' % string)
log_error('Handle doc reference "@{%s}"' % string)
return 'TODO:%s' % string

elif string.startswith('tf'): # Python symbol
Expand All @@ -203,11 +211,11 @@ def _one_ref(string, relative_path_to_root, duplicate_of, doc_index, index):
elif string == 'tensorflow::ops::Const':
ret = 'CONST_URL'
else:
print('ERROR: Handle C++ reference "@{%s}"' % string)
log_error('Handle C++ reference "@{%s}"' % string)
return 'TODO_C++:%s' % string
return '[`%s`](%s)' % (link_text, os.path.join(relative_path_to_root, ret))
# Error!
print('ERROR: Did not understand "@{%s}"' % string)
log_error('Did not understand "@{%s}"' % string)
return 'ERROR:%s' % string


Expand Down

0 comments on commit e6c776d

Please sign in to comment.