Skip to content

Question: Casing Options? #1289

Closed as not planned
Closed as not planned

Description

@joshrhoades

This seems like a basic question or configuration, but I can't find it anywhere in the docs or other postings.

Is there a way to prevent pages/nav structure from using initial case?

Such as I create something.md and it renders in the nav as Something. I would like to be able to preserve the casing if possible.

I could do this in the yaml by setting an override title, but this would be egregious for the amount of documentation we're about to write.

I could also do this via CSS and force it to LC, but this is not ideal either as I would rather preserve the case as it was originally entered.

Hopefully I've just missed something?

Activity

  1. trel commented on Sep 20, 2017

    @trel
    Contributor

    Agreed. I'd like the casing to be preserved by default. But since there is already a standing precedent of upcasing, I'd be happy with an option to preserve.

  2. joshrhoades commented on Sep 20, 2017

    @joshrhoades
    Author

    Actually, this seems a bit more convoluted. It appears as if single entities are converted to initialcase, as is anything with a dot-naming convention, whereas camelcase is not.

    The URI, however, seems to maintain the original casing.

    File Nav Output URI
    namespace.fn.method.md Namespace.fn.method namespace.fn.method
    hide.md Hide hide
    getActualSize.md getActualSize getActualSize
    test this Test this test%20this
  3. trel commented on Sep 20, 2017

    @trel
    Contributor

    Yes, our current workaround is to specify anything that isn't vanilla initial upcase.

    Every other scenario behaved surprisingly.

  4. joshrhoades commented on Sep 20, 2017

    @joshrhoades
    Author

    kebab-case and snake_case also get the Initial case treatment too:

    File Nav Output URI
    test-this Test this test-this
    test_this Test this test_this

    A configurable option to preserve casing as entered would be ideal to my mind, without impacting already existing usages/behaviors.

  5. joshrhoades commented on Sep 20, 2017

    @joshrhoades
    Author

    Weird, it isn't consistent either:
    namespace.fn.method.md gets initial-cased, but another file with the same naming convention namespace.fn.otherMethod.md does not.

    Or perhaps it is consistent. The difference seems to be that one is entirely lc, while the other is camelCase.

  6. waylan commented on Sep 21, 2017

    @waylan
    Contributor

    This is not a configurable option, but is hard-coded. And we are very resistant to adding new configuration options. In fact, we've removed more than we've added in the last few releases.

    The behavior is rather simple. If a filename is all lower case, then Python's string.capitalize method is run on it (capitalize first character of string). If the filename is not all lowercase, then no capitalization is done. The current behavior was put in place over 4 years ago (see ed59436), with a slightly simpler variation (which didn't check existing case) being added one day earlier (see c38db61). Prior to that titles were not derived from filenames and there have been no other changes to title generation since (except for the code being moved without any changes in behavior in 984029a). I find it curious that this is the first we have had any complaints about it.

    In any event, we are intending to rework the way titles are determined in the next major release (see #316). And if that doesn't meet your needs, the new Plugin API (see #1223) might be a way for users to define their own method for defining page titles. The work on these things can be found in the 1.0.dev branch.

  7. joshrhoades commented on Sep 21, 2017

    @joshrhoades
    Author

    @waylan Thanks for the info.

    Don’t get me wrong, not trying to dog you guys for it, just found it curious as it seemed somewhat unexpected especially when I couldn’t find any info on it. I expected to find at least one random topic on it somewhere.

    Though I agree it’s also strange if no one ever mentioned this before, we’re not doing anything crazy with our naming conventions (standard JS namespace dot notation), so I’d be shocked if I’m the first person who ran into it. Of course, running into it and then digging into it are two separate things, or perhaps people found other workarounds or just decided it wasn’t that crucial for their needs.

    It’s not a dealbreaker for me (kinda sorta), liking what I can do so far with the tool otherwise, and I’m going to need to customize some things anyway so perhaps I’ll work around it.

    Thanks for the info, guys.

  8. added this to the 1.0.0 milestone on Sep 21, 2017
  9. modified the milestones: 1.0.0, Post 1.0 on Feb 5, 2018
  10. 0xTirthesh commented on Aug 27, 2020

    @0xTirthesh

    I know this thread is too old - but I had to ask, are you guys planning any update on this?

  11. waylan commented on Aug 27, 2020

    @waylan
    Contributor

    @ganatrat the last activity was to give this the [needs design decision] tag. Until a decision is made, there are no plans.

  12. pawamoy commented on Apr 15, 2024

    @pawamoy
    Contributor

    This is one of the feature/change request where everybody wants something different, and it is almost impossible to satisfy everyone with the default behavior. The current default behavior is good in probably 90% of cases (maybe more, maybe less).

    The most obvious solution to this is to declare titles in YAML front-matter metadata in each file:

    ---
    title: my title
    ---
    
    blabla

    But there are alternatives.

    Instead of adding a configuration option with multiple predefined values and the according behaviors, we could add it but make it accept a Python function (using YAML Python tags) that accepts input objects from MkDocs and returns a title for the navigation. This way users could implement their own behavior.

    # mkdocs.yml
    casing: !!python/name:my_module.my_function

    A current, possible solution would be to hook into on_nav to iterate on the navigation items and update them as you see fit. A very basic example:

    # hooks.py
    from pathlib import Path
    
    def on_nav(env, config, files):
        for file in files:
            if file.page:
                # Restore origin file name (without extension) as title.
                file.page.title = Path(file.src_uri).stem
    # mkdocs.yml
    hooks:
    - hooks.py

    Since it seems to be achievable through hooks and plugins, I'll close this as out of scope for MkDocs core. If the plugin API can be improved though, please let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions