Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom run_hyphenator.js #1

Open
bk322 opened this issue Jul 13, 2013 · 0 comments
Open

Custom run_hyphenator.js #1

bk322 opened this issue Jul 13, 2013 · 0 comments

Comments

@bk322
Copy link

bk322 commented Jul 13, 2013

Here's a way which allows user to have a custom run_hyphenator.js -- so that if the user have the file -- extension won't overwrite it:

(hyphenator.py)

def builder_inited(app):
    if not app.config.hyphenator_path:
        raise ExtensionError('hyphenator extension: "hyphenator_path" must be'
                             ' set in "conf.py"')
    app.add_javascript(os.path.join(app.config.hyphenator_path,
                                    'Hyphenator.js'))
    if app.config.hyphenator_language:
        language = app.config.hyphenator_language
    elif app.config.language:
        language = app.config.language
    else:
        raise ExtensionError('hyphenator extension: no language found'
                             ', please set "hyphenator_language"'
                             ' in your conf.py')

    ### modification starts:
    script_name = "run_hyphenation.js"
    script_path = os.path.join(app.confdir,
                               app.config.html_static_path[0],
                               script_name)
    if not os.path.exists(script_path):
        start_script = ("var hyphenatorSettings = {\n"
                        "  selectorfunction: function() {\n"
                        "          return $('.document, .sphinxsidebar').get()},\n"
                        "  displaytogglebox: true,\n"
                        "  defaultlanguage: '%s'\n"
                        "  };\n"
                        "Hyphenator.config(hyphenatorSettings);\n"
                        "Hyphenator.run();" % language)
        with open(script_path, "w") as script_file:
            script_file.write(start_script)
    ### modification ends

    app.add_javascript(script_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant