Skip to main content

sphinx-nostalgistjs

Sphinx extension for embedding RetroArch in HTML documents, using NostalgistJS. Styling and layout depend on Bootstrap v5, not included.

This package is released on pypi.

Basic Usage

Add this extension to your Sphinx conf.py, like so:

extensions = [
    "sphinx_nostalgistjs",
    ⋯
]

You have to at least configure where to find the JS file to be used whenever a document uses this extension, also in conf.py:

nostalgistjs_script_url = "https://unpkg.com/nostalgist"

In this case, we are using UNPKG as a CDN. You can always download a release of NostalgisJS and place it in your _static folder, loading it like so:

nostalgistjs_script_url = "/_static/nostalgist.js"

If the extension was successfully installed, you can include an emulator in a document, using the following directive:

For reStructuredText:
:::{nostalgistjs}
    :rom_url: "30yearsofnintendont.bin"
    :core_id: genesis_plus_gx
:::    

For Myst: (used throughout this document)
```{nostalgistjs}
    :rom_url: "30yearsofnintendont.bin"
    :core_id: genesis_plus_gx
```

This will embed an emulator that loads the given ROM with the respective emulation core. If rom_url is not an URL, and instead, just a plain filename, NostalgistJS will try to load the ROM from retrobrews, as of the latest version. This uses the file extesnsion in an attempt to determine the target system automatically. The core is not important in this case.

Please consult the launch(...) API of NostalgistJS to understand these arguments, and the available cores. As for the core to use, as a general rule:

System Core
Mega Drive genesis_plus_gx
NES fceumm
SNES snes9x
GB, GBC, GBA mgba
Some configuration options allow a document's author to inject arbitrary JavaScript into the page.
This plugin is not appropriate for environments where this may be a security issue.

Advanced Usage

It is possible to change most parameters of NostalgistJS using the directive.

Inside the directive, if there is any content, there must be a JSON object that can configure the emulator in various ways. Most notably, the 'nostalgist_options' is an object that can be used to add options to be passed to the launch(...) API of NostalgistJS.

Here is an example of advanced usage. This injects preamble JS code to setup input device types and mappings, specific to the ROM being used. It can get a bit ugly, though:

```{nostalgistjs}
    :rom_url: "https://example.site/rom.bin"
    :core_id: genesis_plus_gx
    {
        "nostalgist_options": {
            "retroarchConfig": {
                "video_smooth": true,
                "input_auto_mouse_grab": true
            }
        },
        "before_launch_preamble": "let efs = nostalgist.getEmscriptenFS(); efs.mkdirTree('/home/web_user/retroarch/userdata/config/remaps/Genesis Plus GX'); efs.writeFile('/home/web_user/retroarch/userdata/config/remaps/Genesis Plus GX/rom.rmp',  'input_libretro_device_p1 = \"1\"\\ninput_libretro_device_p2 = \"2\"');"
    }
```

Directive options

nostalgist_options

These are the options passed straight to NostalgistJS for configuring the emulator. Consult the NostalgistJS documentation for more info.

The options rom and core are filled in from the directive's rom_url and core_id parameters, and don't need to be specified again. Also, respondToGlobalEvents is set to false by default, but this can be overriden.

Note that there's no need to specify the element option, this is handled automatically by the plugin. Doing so will break the UI controls.

omit_attribution

A boolean. If set to true, this will hide the credits that are rendered at the bottom. Defaults to false.

extra_nostalgist_options

A string. This will be output directly in the JavaScript source, inside an object literal. The resulting object is merged into the options object used for launching NostalgistJS.

This can be used to add options that cannot be expressed in JSON, such as callback functions. Defaults to an empty string.

Custom code injection

before_launch_preamble

A piece of JS code to be executed before the emulator starts, and before any UI setup code runs.

before_launch_epilogue

A piece of JS code to be executed before the emulator starts, but after all UI setup code runs.

on_launch_preamble

A piece of JS code to be executed after the emulator starts, but before any UI setup code runs.

on_launch_epilogue

A piece of JS code to be executed after the emulator starts, and after all UI setup code runs.

Troubleshooting

In case the ROM doesn't load, it may be related to CORS configuration issues. Please refer to the browser's "Developer Tools" console and network tabs for clues of what may be happening.

License

This project is licensed under the GPLv3 license.

Metadata

Release files for sphinx-nostalgistjs 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-nostalgistjs 1.0.3
File Size Uploaded Provenance Actions
sphinx_nostalgistjs-1.0.3.tar.gz 23.2 kB Without provenance Details for sphinx_nostalgistjs-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-nostalgistjs 1.0.3
File Interpreter ABI Platform Actions
sphinx_nostalgistjs-1.0.3-py3-none-any.whl Python 3 none any Details for sphinx_nostalgistjs-1.0.3-py3-none-any.whl

Total release size: 43.0 kB

Release files / sphinx_nostalgistjs-1.0.3.tar.gz

Download URL sphinx_nostalgistjs-1.0.3.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2a71212b75c32131f0af065b3203ab8cd8646b8c0e3330b1e9872366cf2c87e0
BLAKE2b-256 checksum
How to use checksums
e48b69e77d973aeb65de87ab48dc4f1e5d8bee750a8efaeec9a8ada1dc25e9ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.11

Release files / sphinx_nostalgistjs-1.0.3-py3-none-any.whl

Download URL sphinx_nostalgistjs-1.0.3-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4d739edfd158a1ead4525db8ab6abd348ec221bda0c18bdca4fda856bba8f1d
BLAKE2b-256 checksum
How to use checksums
4ef4b9e204aca5348cafc38fa98d84f67a094cdfd8e85854fbe083715a933c54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.11

Security for sphinx-nostalgistjs 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page