Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code annotations not always working in c++ code block #3698

Closed
5 tasks done
rath3t opened this issue Mar 11, 2022 · 3 comments
Closed
5 tasks done

Code annotations not always working in c++ code block #3698

rath3t opened this issue Mar 11, 2022 · 3 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@rath3t
Copy link

rath3t commented Mar 11, 2022

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

Hello everyone and thanks for this very nice package here!
I witnessed a possible bug where my code annotations are not always shown correctly. This happenend in large c++ code blocks.

Expected behaviour

The code annotations should be resolved correctly.

Actual behaviour

The code annotations are not resolved
image
but if i remove a bit of the c++ code the code annotations are resolved.

Steps to reproduce

  1. My very condensed mkdocs.yml file looks like se below at configuration

  2. I have the following markdown file "examples/integrate_pi.md" with c++ code:

    ```cpp
#include <numbers>

#include <dune/alugrid/grid.hh>
#include <dune/geometry/quadraturerules.hh>
#include <dune/grid/io/file/vtk/vtkwriter.hh>

#include <Eigen/Core>
#include <Eigen/Dense>

#include <ikarus/Grids/GridHelper/griddrawer.h>

int main() {
  constexpr int gridDim = 2; // (1)
  using Grid            = Dune::ALUGrid<gridDim, 2, Dune::simplex, Dune::conforming>;
  auto grid             = Dune::GmshReader<Grid>::read("../../examples/src/testFiles/circleCoarse.msh", false);
  auto gridView         = grid->leafGridView();

  draw(gridView);

  /// Calculate area from volume function of elements
  double area1 = 0.0;
  for (auto& element : elements(gridView))
    area1 += element.geometry().volume();

  /// Integrate function using integration rule on grid
  auto f       = [](auto&& global) { return sqrt(global[0] * global[0] + global[1] * global[1]); };
  double area2 = 0.0;
  for (auto& element : elements(gridView)) {
    const auto& rule = Dune::QuadratureRules<double, 2>::rule(element.type(), 1, Dune::QuadratureType::GaussLegendre);
    for (auto& gp : rule)
      //      area2 += element.geometry().integrationElement(gp.position()) * gp.weight();
      area2 += f(element.geometry().global(gp.position())) * element.geometry().integrationElement(gp.position())
               * gp.weight();  // integrationElement --> JacobiDeterminant
  }

  std::cout << area1 << " " << area2 << std::endl;

  /// Naive refinement of grid and compare calculated area to pi
  for (int i = 0; i < 3; ++i) {
    area1 = 0.0;
    grid->globalRefine(1);

    auto gridViewRefined = grid->leafGridView();
    std::cout << "This gridview contains: ";
    std::cout << gridViewRefined.size(0) << " elements" << std::endl;
    draw(gridViewRefined);
    for (auto& element : elements(gridViewRefined)) {
      area1 += element.geometry().volume();
    }
  }
}
    ```

1. Create ALUGrid from gmsh file.

Now the code annotation is not resolved:
image

  1. If i remove the block from the end :
  for (int i = 0; i < 3; ++i) {
    area1 = 0.0;
    grid->globalRefine(1);

    auto gridViewRefined = grid->leafGridView();
    std::cout << "This gridview contains: ";
    std::cout << gridViewRefined.size(0) << " elements" << std::endl;
    draw(gridViewRefined);
    for (auto& element : elements(gridViewRefined)) {
      area1 += element.geometry().volume();
    }
  }

the code annotation is resolved correctly
image

Package versions

  • Python: python3 --version --> Python 3.9.10
  • MkDocs: mkdocs --version --> mkdocs, version 1.2.3 from /home/alex/.local/lib/python3.9/site-packages/mkdocs (Python 3.9)
  • Material: pip show mkdocs-material | grep -E ^Version --> Version: 8.2.5

Configuration

# Project information
site_name: test

# Configuration
theme:
  name: material
  features:
    - content.code.annotate

# Path where the markdown files are
docs_dir: 'website'

# Navigation
nav:
  - Examples:
      - Integrate pi: examples/integrate_pi.md

# Extensions
markdown_extensions:
  - pymdownx.highlight:
      anchor_linenums: true
  - pymdownx.inlinehilite
  - pymdownx.snippets
  - pymdownx.superfences

System information

  • Operating system: debian bookworm inside Windows WSL
  • Browser: Brave and FireFox tested
@squidfunk
Copy link
Owner

Thanks for reporting. This seems to be a side effect of the fix added in #3643 as of which code blocks are only mounted when they become visible. The problem was that the intersection threshold was set to 1, which means element becomes 100% visible, which for a code block of this size was never the case, as it was always either cut off at the top or bottom. Thus, the code block (and as a result annotations) were never mounted. This is also why when you removed some lines, the annotations suddenly started working.

88cfda4 sets the threshold to 0 which means that the code block is mounted the moment it becomes visible.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open labels Mar 22, 2022
@rath3t
Copy link
Author

rath3t commented Mar 23, 2022

Ok thank you i look forward to this!

@rath3t rath3t closed this as completed Mar 23, 2022
@squidfunk
Copy link
Owner

Released as part of 8.2.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants