Skip to content

Commit ba5c5bf

Browse files
authored
Merge pull request #505 from DMTF/fix-489
Added support for intra-document links for Markdown output
2 parents 97cd6df + 31ebfae commit ba5c5bf

File tree

13 files changed

+146
-74
lines changed

13 files changed

+146
-74
lines changed

doc-generator/doc_formatter/csv_generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ def add_description(self, text):
287287
""" CSV omits schema description """
288288
pass
289289

290+
def add_deprecation_text(self, deprecation_text):
291+
""" CSV omits deprecation text """
292+
pass
290293

291294
def add_uris(self, uris, urisDeprecated):
292295
""" CSV omits URIs """

doc-generator/doc_formatter/doc_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ def extend_property_info(self, schema_ref, prop_info):
10531053
if 'redfish.dmtf.org/schemas/v1/odata' in from_schema_uri:
10541054
from_schema_uri = 'http://' + is_collection_of
10551055

1056-
link_detail = (_('Link to Collection of %(schema_links)s. See the %(schema_name)s schema for details.')
1056+
link_detail = (_('Link to Collection of %(schema_name)s. See the %(schema_links)s schema for details.')
10571057
% {'schema_links': self.link_to_own_schema(is_collection_of, from_schema_uri),
10581058
'schema_name': ref_schema_name})
10591059

doc-generator/doc_formatter/markdown_generator.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ def format_property_row(self, schema_ref, prop_name, prop_info, prop_path=[], in
6464
6565
This may include embedded objects with their own properties.
6666
"""
67+
if not in_schema_ref:
68+
in_schema_ref = schema_ref
6769

70+
schema_anchor = self.traverser.get_schema_name(in_schema_ref)
71+
6872
formatted = [] # The row itself
6973

7074
within_action = prop_path == ['Actions']
@@ -211,7 +215,14 @@ def format_property_row(self, schema_ref, prop_name, prop_info, prop_path=[], in
211215
if formatted_details['has_direct_prop_details'] and not formatted_details['has_action_details']:
212216
# If there are prop_details (enum details), add a note to the description:
213217
if has_enum:
214-
text_descr = _('For the possible property values, see %(link)s in Property details.') % {'link': prop_name}
218+
if self.markdown_mode == 'slate' or not schema_anchor:
219+
text_descr = (_('For the possible property values, see %(link)s in Property details.') %
220+
{'link': prop_name})
221+
else:
222+
anchor = schema_anchor.lower() + '-' + prop_name.lower()
223+
text_descr = (_('For the possible property values, see %(link)s in Property details.') %
224+
{'link': '[' + prop_name + '](#' + anchor + ')'})
225+
215226
else:
216227
text_descr = _('For more information about this property, see Property details.')
217228
formatted_details['descr'] += ' ' + self.formatter.italic(text_descr)
@@ -648,9 +659,19 @@ def format_as_prop_details(self, prop_name, prop_description, rows):
648659
return "\n".join(contents)
649660

650661

651-
def link_to_own_schema(self, schema_ref, schema_full_uri):
652-
"""Format a reference to a schema."""
653-
result = super().link_to_own_schema(schema_ref, schema_full_uri)
662+
def link_to_own_schema(self, schema_ref, schema_uri):
663+
schema_name = self.traverser.get_schema_name(schema_ref)
664+
if not schema_name:
665+
schema_name = schema_ref
666+
667+
if self.markdown_mode == 'slate':
668+
return self.formatter.italic(schema_name)
669+
670+
if self.is_documented_schema(schema_ref):
671+
result = '[' + schema_name + '](#' + schema_name.lower() + ')'
672+
else:
673+
result = '[' + schema_name + '](' + schema_uri + ')'
674+
654675
return self.formatter.italic(result)
655676

656677

@@ -665,7 +686,13 @@ def emit(self):
665686
contents = []
666687

667688
for section in self.sections:
689+
schema_name = section.get('schema_name')
690+
668691
contents.append(section.get('heading'))
692+
# if there are version numbers in the headings, add an anchor tag for the section using only the section name
693+
if schema_name and not self.markdown_mode == 'slate' and not self.config.get('omit_version_in_headers'):
694+
contents.append('<a name="' + schema_name.lower() + '"></a>')
695+
669696
if section.get('release_history'):
670697
contents.append(section['release_history'])
671698
if section.get('conditional_requirements'):
@@ -726,6 +753,11 @@ def emit(self):
726753
detail_names.sort(key=str.lower)
727754
for detail_name in detail_names:
728755
contents.append(self.format_head_four(detail_name, 0))
756+
757+
# add section/schema-specific anchor tag
758+
if schema_name and not self.markdown_mode == 'slate':
759+
contents.append('<a name="' + schema_name.lower() + '-' + detail_name.lower() + '"></a>')
760+
729761
det_info = section['property_details'][detail_name]
730762

731763
if len(det_info) == 1:
0 Bytes
Binary file not shown.

doc-generator/locale/TEST/LC_MESSAGES/doc_generator.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ msgid "Contains a link to a resource."
193193
msgstr "CONTAINS A LINK TO A RESOURCE."
194194

195195
#: doc_formatter/doc_formatter.py:920
196-
msgid "Link to Collection of %(schema_links)s. See the %(schema_name)s schema for details."
197-
msgstr "LINK TO COLLECTION OF %(schema_links)s. SEE THE %(schema_name)s SCHEMA FOR DETAILS."
196+
msgid "Link to Collection of %(schema_name)s. See the %(schema_links)s schema for details."
197+
msgstr "LINK TO COLLECTION OF %(schema_name)s. SEE THE %(schema_links)s SCHEMA FOR DETAILS."
198198

199199
#: doc_formatter/doc_formatter.py:927
200200
msgid "Link to another %(name)s resource."

doc-generator/locale/doc_generator.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ msgid "Contains a link to a resource."
225225
msgstr ""
226226

227227
#: doc_formatter/doc_formatter.py:977
228-
msgid "Link to Collection of %(schema_links)s. See the %(schema_name)s schema for details."
228+
msgid "Link to Collection of %(schema_name)s. See the %(schema_links)s schema for details."
229229
msgstr ""
230230

231231
#: doc_formatter/doc_formatter.py:984

doc-generator/locale/en/LC_MESSAGES/doc_generator.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ msgid "Contains a link to a resource."
214214
msgstr ""
215215

216216
#: doc_formatter/doc_formatter.py:971
217-
msgid "Link to Collection of %(schema_links)s. See the %(schema_name)s schema for details."
217+
msgid "Link to Collection of %(schema_name)s. See the %(schema_links)s schema for details."
218218
msgstr ""
219219

220220
#: doc_formatter/doc_formatter.py:978

0 commit comments

Comments
 (0)