Skip to content

Commit

Permalink
Pick up anchors from raw HTML - WITH PROPOSAL
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Nov 13, 2023
1 parent 04cca3b commit 8ec1eb8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mkdocs/structure/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ def render(self, config: MkDocsConfig, files: Files) -> None:
extension_configs=config['mdx_configs'] or {},
)

present_anchor_ids = set()
base_class = md.preprocessors['html_block'].HTMLExtractorClass

class sub_class(base_class):
def handle_starttag(self, tag, attrs) -> None:
for k, v in attrs:
if k == 'id':
present_anchor_ids.add(v)
return super().handle_starttag(tag, attrs)

md.preprocessors['html_block'].HTMLExtractorClass = sub_class

relative_path_ext = _RelativePathTreeprocessor(self.file, files, config)
relative_path_ext._register(md)

Expand All @@ -271,7 +283,7 @@ def render(self, config: MkDocsConfig, files: Files) -> None:
self.content = md.convert(self.markdown)
self.toc = get_toc(getattr(md, 'toc_tokens', []))
self._title_from_render = extract_title_ext.title
self.present_anchor_ids = relative_path_ext.present_anchor_ids
self.present_anchor_ids = relative_path_ext.present_anchor_ids | present_anchor_ids
if log.getEffectiveLevel() > logging.DEBUG:
self.links_to_anchors = relative_path_ext.links_to_anchors

Expand Down

0 comments on commit 8ec1eb8

Please sign in to comment.