Metadata-Version: 2.4
Name: sphinx-hackerrank
Version: 2026.11.10
Summary: Build portable HackerRank Interviewer Guidelines from Sphinx documentation.
Author-email: Adam Dangoor <adamdangoor@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Rippling
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Issues, https://github.com/adamtheturtle/sphinx-hackerrank/issues
Project-URL: Source, https://github.com/adamtheturtle/sphinx-hackerrank
Keywords: documentation,rst,sphinx
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Sphinx :: Extension
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.13
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: beautifulsoup4>=4.15.0
Requires-Dist: docutils>=0.21.2
Requires-Dist: hackerrank>=2026.11.10
Requires-Dist: sphinx<10,>=9.1.1
Dynamic: license-file

|Build Status| |PyPI|

sphinx-hackerrank
=================

Export Sphinx documentation as self-contained HTML for HackerRank Interviewer Guidelines, with styles and images.
Build and preview locally without HackerRank credentials.

Quick start
-----------

In an existing Sphinx project:

.. code-block:: console

   pip install sphinx-hackerrank

Add ``"sphinx_hackerrank"`` to ``extensions`` in ``docs/conf.py``.
Create ``docs/review.rst`` and add ``review`` to your existing toctree:

.. code-block:: rst

   Widget review
   =============

   .. hackerrank-export:: interviewer-guidelines/review.html
      :name: Widget review

      Interviewer instructions go here.

      .. code-block:: text

         example input

Build:

.. code-block:: console

   sphinx-build -W -b hackerrank docs build/hackerrank

Open ``build/hackerrank/interviewer-guidelines/index.html`` to preview the exports.
Upload ``build/hackerrank/interviewer-guidelines/review.html`` using your own publishing tool.

Code blocks are exported as ``<pre><code>`` with their original text and whitespace.
HackerRank's project IDE adds native copy controls to these blocks in its Guidelines tab.
Hover over a code block to reveal its Copy button.
Check copying inside a project interview.
The standalone preview displays the exported HTML without the IDE's controls.

Choosing content
----------------

Wrap content in ``hackerrank-export`` and give it an HTML output path relative to the build directory.
The required ``:name:`` option supplies the preview index label.
Each boundary is a Sphinx node carrying its destination and name.
No CSS selector or export list is needed.
Multiple boundaries in the same document export independently.
Destinations must be unique and must not overwrite documentation pages or the preview index.
The ``hackerrank`` builder writes only the standalone exports and their preview index.
Run the ordinary ``html`` builder separately for themed documentation pages.
When upgrading, clean an existing HackerRank output directory once to remove pages generated by earlier versions.

Python extensions can construct the same boundary directly:

.. code-block:: python

   """Declare an export around prepared Docutils content."""

   from docutils import nodes

   from sphinx_hackerrank import GuidelineExportNode

   content = GuidelineExportNode(
       output_path="interviewer-guidelines/review.html",
       name="Widget review",
   )
   content += nodes.paragraph("", "Interviewer instructions go here.")
   assert content.astext() == "Interviewer instructions go here."

The builder renders each marked subtree from Sphinx's resolved doctree using its standard HTML translator.
It preserves document context for headings, references, figure numbering, and images without rendering the rest of the page or loading a theme.
Export metadata is retained across incremental and parallel builds.
Other builders receive ordinary containers, preserving their native rendering without additional node handlers.

For collapsible sections, enable `sphinx-toolbox.collapse <https://sphinx-toolbox.readthedocs.io/en/stable/extensions/collapse.html>`_.
To reuse guide sections, enable `sphinx-section-include <https://github.com/adamtheturtle/sphinx-section-include>`_.
See the `sample project <https://github.com/adamtheturtle/sphinx-hackerrank/tree/main/sample>`_ for both.

Migrating from selector exports
-------------------------------

Replace each ``GuidelineExport`` configuration entry with a ``hackerrank-export`` directive or ``GuidelineExportNode`` around the content being exported.
Move ``output_path`` and ``name`` to that boundary, then remove ``hackerrank_exports`` and the old ``GuidelineExport`` import.
A separate ``docname`` and ``selector`` are no longer needed.
CSS classes remain presentation details.

Source links
------------

Relative document links retain their paths by default, so build a separate HTML site to supply the linked pages.
To link to hosted documentation, set ``hackerrank_source_url = "https://example.org/guides/"`` in ``conf.py``.
For source files, set ``hackerrank_source_suffix = ".rst"`` too.
Set ``hackerrank_source_anchors = False`` if the destination does not support anchors.

Contributing
------------

See `CONTRIBUTING.rst <https://github.com/adamtheturtle/sphinx-hackerrank/blob/main/CONTRIBUTING.rst>`_ for checks and releases.
MIT licensed.

.. |Build Status| image:: https://github.com/adamtheturtle/sphinx-hackerrank/actions/workflows/ci.yml/badge.svg?branch=main
   :target: https://github.com/adamtheturtle/sphinx-hackerrank/actions
.. |PyPI| image:: https://badge.fury.io/py/sphinx-hackerrank.svg
   :target: https://badge.fury.io/py/sphinx-hackerrank

Complete API publishing
-----------------------

Requires Python 3.13 or later.
The explicit ``hackerrank-publish`` builder exports guidelines and then executes ``hackerrank_api_operations`` in order using the HackerRank SDK.
Ordinary ``html`` and ``hackerrank`` builds remain offline.
Every documented v3, ATS and SCIM operation is available.
An empty publishing plan exports the operation catalogue without credentials.

Configure a plan in ``conf.py``:

.. code-block:: python

   """Configure explicit API publishing."""

   hackerrank_api_operations = [
       {
           "operation": "api_update_question",
           "path_parameters": {"question_id": "123456"},
           "body": {
               "name": "Widget review",
               "problem_statement": "Review the implementation.",
               "type": "code",
           },
           "body_files": {"internal_notes": "interviewer-guidelines/review.html"},
       },
   ]

Run ``sphinx-build -W -b hackerrank-publish docs build/hackerrank``.
``body_files`` reads UTF-8 exports from inside the build directory and inserts that exact text into the request body.
All operations and files are validated before any request is sent.
Question writes use the SDK's shared validation for AI prompts, including prompts read from exported files.
A known unsupported question type or an overlong prompt prevents the entire plan from publishing.
Use ``HACKERRANK_API_TOKEN`` for v3 operations and a separate ``HACKERRANK_SCIM_API_TOKEN`` for SCIM provisioning.
The builder writes ``hackerrank-api-results.json`` and ``hackerrank-api-catalogue.json`` with complete responses and request schemas.

The publishing builder requires ``hackerrank>=2026.11.10``.
