Giter Club home page Giter Club logo

Comments (3)

macfreek avatar macfreek commented on June 18, 2024

Thanks for the feature request. The bad news is that I have no current plan to actively add support for non-standard extensions. The good news is that I would gladly accept pull requests for it!

If you are interesting in making a pull request, I am absolutely willing to give you a few pointers if you get stuck.

from restbuilder.

cvergari avatar cvergari commented on June 18, 2024

Thanks for the info. I'd love to contribute but I am afraid I really would not know where to start!

from restbuilder.

mbhynes avatar mbhynes commented on June 18, 2024

Just passing by but I think this is relatively straightforward to resolve, probably with just a little hack in your own project's conf.py:

Problem

  • The root cause here is that the .. mermaid directive isn't recognized by docutils unless it's registered as a node class
  • The sphinxcontrib.mermaid extension adds a node using sphinx's add_node API in the sphinxcontrib.mermaid's setup() function, which is abbreviated below:
[...]
class mermaid(nodes.General, nodes.Inline, nodes.Element):
    pass

def html_visit_mermaid(self, node):
    render_mm_html(self, node, node['code'], node['options'])

[...] 
def setup(app):
    app.add_node(mermaid,
                 html=(html_visit_mermaid, None),
                 latex=(latex_visit_mermaid, None),
                 texinfo=(texinfo_visit_mermaid, None),
                 text=(text_visit_mermaid, None),
                 man=(man_visit_mermaid, None))
  • In the above, nodes are added for each builder name in the **kwargs (ie html is for the html builder)
  • If you are rolling out your own builder in an extension, you would need to have an add_note(mermaid, yourbuilder=(html_visit_mermaid, None)) call added to the app

Example Solve

  • The solve is relatively straightforward: just register a node for the builder name
  • It's possible to add this into a local project's extension's setup(app) such as:
from sphinx.util import logging

def setup(app):

  if 'sphinxcontrib.mermaid' in app.config.extensions:
    try:
      from sphinxcontrib.mermaid import html_visit_mermaid, mermaid
      app.add_node(
        mermaid,
        somebuilder=(html_visit_mermaid, None),
      )
    except ImportError:
      logging.getLogger(__name__).error(
        "sphinxcontrib.mermaid was detected in conf.py extensions=[...] "
        "but we were unable to import html_visit_mermaid from to run app.add_node(mermaid)."
      )

from restbuilder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.