Metadata-Version: 2.4
Name: sphinx-hackerrank
Version: 2026.11.2
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.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.12
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: beautifulsoup4>=4.15.0
Requires-Dist: sphinx<10,>=9.1.1
Dynamic: license-file

|Build Status| |PyPI|

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

Export selected Sphinx HTML as portable HackerRank Interviewer Guidelines.
Fragments embed scoped styles, code-copy controls, and local images.
Externally hosted images retain their URLs without being fetched during export.

Install and configure
---------------------

.. code-block:: console

   pip install sphinx-hackerrank

Add to ``conf.py``:

.. code-block:: python

   """Sphinx configuration."""

   from sphinx_hackerrank import GuidelineExport

   extensions = ["sphinx_hackerrank"]
   hackerrank_exports = [
       GuidelineExport(
           docname="review",
           selector=".hr-interviewer-guideline",
           output_path="interviewer-guidelines/widgets/review.html",
           name="Widget review",
       ),
   ]

Write ``review.rst`` using ordinary RST and your chosen Sphinx extensions:

.. code-block:: rst

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

   .. container:: hr-interviewer-guideline

      Interviewer instructions go here.

      .. code-block:: text

         example input

For collapsible sections, use `sphinx-toolbox.collapse <https://sphinx-toolbox.readthedocs.io/en/stable/extensions/collapse.html>`_.
For excerpts from maintained guides, use `sphinx-section-include <https://github.com/adamtheturtle/sphinx-section-include>`_.
Consumers install and enable their own authoring and template extensions.
See the `sample <https://github.com/adamtheturtle/sphinx-hackerrank/tree/main/sample/source>`_ and its `dependencies <https://github.com/adamtheturtle/sphinx-hackerrank/blob/main/sample/requirements.txt>`_.

Build
-----

.. code-block:: console

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

Open ``build/hackerrank/interviewer-guidelines/index.html`` to preview the exports.
Each request selects exactly one container and writes a unique HTML destination inside the build directory.
Use the ``hr-interviewer-guideline`` class for the bundled styles and code-copy controls.
The builder also produces ordinary themed pages.
Use an extension such as ``sphinx-copybutton`` for copy buttons on those pages.
The exporter's script is embedded only in standalone fragments.
Native disclosures and code remain usable without JavaScript.
Hosts must allow the embedded script for copy buttons to appear.

The exporter preserves the selected content, including admonitions and headings.
Consumers own composition, language contexts, filtering, question mappings, and publishing.
Sphinx's ``only`` directive supports ``builder_hackerrank``, ``builder_html``, or their shared ``html`` format tag.

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

Relative HTML links are rewritten for the export's destination.
To target a hosted guide or source site, configure:

.. code-block:: python

   """Sphinx configuration."""

   hackerrank_source_url = "https://example.org/guides/"
   hackerrank_source_suffix = ".html"
   hackerrank_source_anchors = True

Use ``.rst`` for source files, and disable anchors when the destination does not support them.
External URLs and links within a fragment are retained.

Publishing
----------

Use a separate tool to manage credentials, question identities, and HackerRank API calls.
``sphinx_hackerrank.html.html_equivalent(left, right)`` compares generated and saved HTML while tolerating serialization differences and preserving code whitespace and spaces between inline elements.
``normalize_html(html=...)`` exposes that normalized representation.
The comparison can serve as the HackerRank SDK's ``notes_equal`` callback.

When calling ``render_fragment`` directly with local images, supply ``image_paths`` mapping the rendered image URLs to their files.
The builder supplies this mapping automatically.
Missing or unsupported local images fail export instead of leaving broken URLs.

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

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

.. |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
