Skip to content

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

@rath3t

Description

@rath3t

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions