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

Implement auto anchor for titles #163

Open
GoogleCodeExporter opened this issue Apr 18, 2015 · 1 comment
Open

Implement auto anchor for titles #163

GoogleCodeExporter opened this issue Apr 18, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Email from Kevin:.

I was creating a "config" file to be used in all the documents in a
project and one thing I wanted to do was "auto-anchor" titles.

I have titles like so:
= An Awesome Heading =

and I have the following preproc so far:
%%!preproc: '^=+(.*?)=+$' '\g<0>[\1]'

This gets me this far:
= An Awesome Heading =[ An Awesome Heading ]

...

-------------------------------------------------[email end]

This is a great feature o implement in the core.

Every title should be anchored automatically, and the user, of course, can 
overwrite it with the [anchor].

We need to create a new function to make a "slug" from the text: convert to 
lower case, change spaces and punctuation to hyphens, unaccent chars (á -> a). 
For example:

>>> get_anchor("Hello João, nice hat!!!")
hello-joao-nice-hat
>>>

I'm sure such a function was already implemented countless times, not let's not 
reinvent the wheel. I know Python's docutils have it, maybe we can copy it.


Original issue reported on code.google.com by aureliojargas@gmail.com on 29 Jul 2012 at 10:54

@GoogleCodeExporter
Copy link
Author

Just a couple more things.  If a title has already been used you might want to 
add a <code>-#</code> to the end.

So you get "note", "note-2", "note-3" and "note-..."

And of course still allow overrides in the usual form.

Original comment by kevincox...@gmail.com on 29 Jul 2012 at 12:43

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

No branches or pull requests

1 participant