-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Non ascii headers do not slugify nicely. #212
Comments
mmm, wait a moment.... ah, I'm not actually aware of 'other language' support in mkdocs - /me throws it on the list of things to read. |
Now we may write documents in Chinese and the hyperlink looks a little wired. It's not a big deal but it would better to fix it 😃 |
So what the reporter is describing here is that the anchor link is generated using any ASCII characters in the heading text. |
Thanks @tomchristie and sorry for my bad description. Can we use Unicode instead of ASCII for generate anchor links? |
Anchor links do need to be ascii, as URLs are restricted to that. |
Huh, that project is neat. I have no idea if this is accurate, but it appears to work...
|
👍 for using |
Wow, that's impressive. (And yes, appears correct) https://translate.google.co.uk/?ie=UTF-8&hl=en&client=tw-ob#auto/en/%E6%82%A8%E5%A5%BD |
The python-markdown TOC extension (which generates the slugs for us) accepts a slugify function, so it should really easy to integrate awesome-slugify. Would it be worth making this an optional feature? It could cause quite a few broken links for some people relying on the current behavior. |
Personally I'd say til we hit 1.0 ask em to suck it up. |
Tho we could tie it in with eg #279 |
If/when you implement Maybe just make it simple. If a extension has a Just for each plugin you would need to: if 'slugify' in config:
config['slugify'] = mkdoc_slugify_method That way a user could just define the slugify key, and then get the method. The value wouldn't matter as mkdocs would just overwrite it. markdown_extensions:
myextension:
some_config: true
slugify: |
@facelessuser that sounds a bit too magical or me. There is no guarantee that the different slugify functions would have the same method signature. |
I guess, I haven't looked at |
I don't agree with having I'd rather see |
@robodude666 Sorry, I don't follow you...
Why would you need to wrap anything if we use autsome-slugify? and why would it matter if your dependencies use it?
The "yaml toc slugify string"? Are you objecting to idea in #212 (comment)? or something else? |
I'm opposing the solution provided by #297. It limits users of If I configure the markdown_extensions:
- toc:
permalink: "P"
slugify: "mycodebase.mkdocs_stuff.toc_slugify"
- admonition: I would expect the |
While I'm not completely opposed to that idea (as the lead dev of Python-Markdown), it most likley won't happen for some time. Python-Markdown it currently in "maintainance mode" as we work towards 3.0. In other words the 2.x line will only receive bug fixes going forward with no new features.
I'm assuming you mean the the string assigned to the extension config in the YAML config file should be recognized by MkDocs as using Python dot notation and be imported. I agree that that is a little to magic for my tastes. However, the PyYaml library does support special types which will result in the value being a Python object rather than a string. You just have to explicitly define the type in your YAML file and YAML will attempt to import the object and assign it as the value. Therefore, the following would presumably work today with no changes to MkDocs or Python-Markdown (untested - I haven't checked the signature of markdown_extensions:
- toc:
slugify: !!python/name:slugify.slugify A possible alternative would be to wait for the Plugin API (see #206) to land. Then you could use a |
Giving this some additional thought, a Plugin wouldn't even need to replace a dot notation string with a Python object. It could just add the Of course, given PyYaml's ability to assign Python types, I think this whole thing is moot. The only reason to even consider a plugin is if it is decided that explicitly defining the type in YAML is ugly and not something you want to document for users. "Use this plugin" is certainly easier to explain to noobs. Either way, I don't see any reason to leave either this issue or #297 open. But, of course, that is not my call. |
@waylan @d0ugal Can confirm that PyYaml's special types work with mkdocs: markdown_extensions:
- toc:
slugify: !!python/name:mycodebase.myawesome.slugify Allows me to define the dot notation path to my slugify function and it's used appropriately. With that said, I would agree with @waylan that this issue is a non-issue. Might be nice to note in the markdown_extensions that this functionality from PyYaml is available; although it might only be an advanced user feature? |
I actually never made the connection this could be done, even though I knew about pyyaml's special types. This is a useful tip. |
Bothers me that it's even something that's possible to do. :-/ |
Yeah, this is the default in PyYAML which I agree is kinda gross. We can stop it by using IMO |
...
Agreed. Not a big issue here, just icky. |
I would think it could be prevented once a plugin API allows this. This has actually been something I have wanted as well, and the yaml "danger" load allows me to accomplish it now. With that said, I totally understand why a maintainer would want to kill it, but it now saves me from doing coding gymnastics as a user to override and/or acquire the slugify method used in toc and and share it with other extensions that touch the headers. |
I agree with @facelessuser. It shouldn't be prevented until there's another approved method for the same result. Until we have extensions, it's the only way right now to customize the slugification without having to author a subclass of the TOC extension. |
Yeah, my thoughts are heading in this direction too. Let's leave this as it is for now, support this sort of customisation via extensions later and maybe switch to safe_load in the YAML. I am not sure the swtich is really needed, it grosses me out, but I'll never use it anyway. So, now I am wondering if we I should just close this issue and direct people to track #206 |
It doesn't sound like anyone is advocating that we change the default. Users have a way of changing the default now and we want to make that easier with extensions later. So, yeah, there is nothing that needs to happen here. Thanks all for the discussion, that was really useful. I'll happily re-open if anyone can put forward a compelling case to do so. |
I have fix a problem with pymdownx
mkdocs.yml
|
After all, what should I modify in
If my mkdocs dir is
It would be great to your reply! |
@rapon if you read my comments surrounding my example, you will note that it was unsure of the correct import path for the slugify lib. My example was simply meant to serve as an example of how it might be done. However, the other examples provide real working examples. The differences between them is that each is using a different library. The key is that the part after |
If we have a
web
in the markdown file, it will generate a hyperlink like "#web". This is what we expect but for other languages, it just returns "#_1" or "#_2".The text was updated successfully, but these errors were encountered: