Skip to content

Commit

Permalink
fix: use regex to identify comments
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Sep 25, 2023
1 parent a903bb4 commit f87e543
Show file tree
Hide file tree
Showing 23 changed files with 27 additions and 29 deletions.
9 changes: 4 additions & 5 deletions docs/_extension/component_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
This list will display some informations about the component and a link to the
GitHub file.
"""
import re
from pathlib import Path
from typing import Any, Dict, List

from bs4 import BeautifulSoup as BS
from bs4 import Comment
from docutils import nodes
from sphinx.application import Sphinx
from sphinx.util import logging
Expand Down Expand Up @@ -56,10 +55,10 @@ def run(self) -> List[nodes.Node]:
# create the list of all the components description using bs4
# at the moment we use dummy information
docs = []
pattern = re.compile(r"(?<={#).*?(?=#})", flags=re.DOTALL)
for c in components:
soup = BS(c.read_text(), "html.parser")
comment = soup.find(string=lambda text: isinstance(text, Comment))
docs.append(comment or "No description available")
comment = pattern.findall(c.read_text())
docs.append(comment[0].strip() if comment else "No description available.")

# get the urls from the github repo latest branch
github_url = "https://github.com/pydata/pydata-sphinx-theme/blob/main"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Breadcrumb to display information on the navigation hierarchy. -->
{# Breadcrumb to display information on the navigation hierarchy. #}
{%- block breadcrumbs %}
{#
If we have more than 3 parents (excluding the home page) then we remove
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- The component to display the copyrights informations set in conf.py. -->
{# The component to display the copyrights informations set in conf.py. #}
{% if show_copyright and copyright %}
<p class="copyright">
{% if hasdoc('copyright') %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- A link to the edit interface of the page source in the specified VCS. -->
{# A link to the edit interface of the page source in the specified VCS. #}
{% if sourcename is defined and theme_use_edit_page_button==true and page_source_suffix %}
{% set src = sourcename.split('.') %}
<div class="tocsection editthispage">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Display the icons link as inline blocks in the navbar. -->
{# Display the icons link as inline blocks in the navbar. #}
{%- macro icon_link_nav_item(url, icon, name, type, attributes='') -%}
{%- if url | length > 2 %}
<li class="nav-item">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- add the indies generated from Sphinx. -->
{# add the indies generated from Sphinx. #}
<nav class="sidebar-indices-items">
<p class="sidebar-indices-items__title" role="heading" aria-level="1">{{ _("Indices") }}</p>
<ul class="indices-link">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Display the last time a page have been updated -->
{# Display the last time a page have been updated #}
{%- if last_updated -%}
<p class="last-updated">
{% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Display the icons link as inline blocks in the navbar. -->
{# Display the icons link as inline blocks in the navbar. #}
{%- block icon_links -%}
{%- include "icon-links.html" with context -%}
{%- endblock icon_links %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- The logo of your documentation. -->
{# The logo of your documentation. #}
{# Logo link generation -#}
{% if not theme_logo.get("link") %}
{% set href = pathto(root_doc) %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- The links of the first level toctree displayed in the header navbar -->
{# The links of the first level toctree displayed in the header navbar. #}
<nav class="navbar-nav">
<p class="sidebar-header-items__title"
role="heading"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Display the current page TOC. -->
{# Display the current page TOC. #}
{% set page_toc = generate_toc_html() %}
{%- if page_toc | length >= 1 %}
<div class="page-toc tocsection onthispage">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Previous / next buttons. -->
{# Previous / next buttons. #}
<div class="prev-next-area">
{%- if prev %}
<a class="left-prev"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Behaves the same as `search-button.html` but looks more like a search field. -->
{# Behaves the same as `search-button.html` but looks more like a search field. #}
{# As this function will only work when JavaScript is enabled, we add it through JavaScript. #}
<script>
document.write(`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- A button that, when clicked, will trigger a search popup overlay. -->
{# A button that, when clicked, will trigger a search popup overlay. #}
{# As this function will only work when JavaScript is enabled, we add it through JavaScript. #}
<script>
document.write(`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- A bootstrap-styled field that will direct to the `search.html` page when submitted. -->
{# A bootstrap-styled field that will direct to the `search.html` page when submitted. #}
<form class="bd-search d-flex align-items-center"
action="{{ pathto('search') }}"
method="get">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- div#searchbox hosts the "Hide Search Matches" link -->
{# div#searchbox hosts the "Hide Search Matches" link #}
<div id="searchbox"></div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Placeholder where the ReadTheDocs ethical ads will be placed. -->
{# Placeholder where the ReadTheDocs ethical ads will be placed. #}
{% if READTHEDOCS %}
<div id="ethical-ad-placement"
class="flat"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Add the toctree of each page included under the selected Heading 1 from header navbar. -->
{# Add the toctree of each page included under the selected Heading 1 from header navbar. #}
<nav class="bd-docs-nav bd-links"
aria-label="{{ _('Section Navigation') }}">
<p class="bd-links__title" role="heading" aria-level="1">{{ _("Section Navigation") }}</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- If enabled, create a button to display the .rst source of the displayed page -->
{# If enabled, create a button to display the .rst source of the displayed page. #}
{% if show_source and has_source and sourcename %}
<div class="tocsection sourcelink">
<a href="{{ pathto('_sources/' + sourcename, true)|e }}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Display the version of Sphinx used to build yout documentation. -->
{# Display the version of Sphinx used to build yout documentation. #}
{% if show_sphinx %}
<p class="sphinx-version">
{% trans sphinx_version=sphinx_version|e %}Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> {{ sphinx_version }}.{% endtrans %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- A button to switch from one theme to another. Are currently supported: light, dark and auto -->
{# As the theme switcher will only work when JavaScript is enabled, we add it through JavaScript.
#}
{# A button to switch from one theme to another. Are currently supported: light, dark and auto. #}
{# As the theme switcher will only work when JavaScript is enabled, we add it through JavaScript. #}
<script>
document.write(`
<button class="btn btn-sm navbar-btn theme-switch-button" title="{{ _('light/dark') }}" aria-label="{{ _('light/dark') }}" data-bs-placement="bottom" data-bs-toggle="tooltip">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Display the version of the theme used to build the documentation. -->
{# Display the version of the theme used to build the documentation. #}
<p class="theme-version">
{% trans theme_version=theme_version|e %}Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> {{ theme_version }}.{% endtrans %}
</p>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- A dropdown button to display the list of version available. These version need to be set in a switcher.json file. -->
{# A dropdown button to display the list of version available. These version need to be set in a switcher.json file. #}
{# As the version switcher will only work when JavaScript is enabled, we add it through JavaScript. #}
<script>
document.write(`
Expand Down

0 comments on commit f87e543

Please sign in to comment.