Discussion:
[t2t] Some preproc Help Needed
Kevin
2012-05-28 22:36:17 UTC
Permalink
Hey guys, it's me again.

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 ]

I can easily modify the regex to remove the outside spaces:
= An Awesome Heading =[An Awesome Heading]

but that doesn't quite cover it. Is there a way to strip spaces (and
other bad characters) from a section of a line. I have considered
brute-forcing it but that isn't pretty and can only handle a set amount
of words.
%!preproc: '^=+\s*(\S*?)\s*(\S*?)\s*(\S*?)\s*(\S*?)\s*=+$' '\g<0>[\1\2\3\4]'

This last one works but is super ugly. Does anyone have and suggestions?

Thanks, Kevin
Aurelio Jargas
2012-07-29 10:55:35 UTC
Permalink
Hi Kevin,

Using preproc, you can't go any further than what you already did. Beware
that title with punctuation will cause problems.

This auto anchor is a great feature should be added to the txt2tags itself,
by default. Every title should be anchored automatically, and the user, of
course, can overwrite it with the [anchor]. I've opened and issue for that:

http://code.google.com/p/txt2tags/issues/detail?id=163

Thanks for the idea!
Post by Kevin
Hey guys, it's me again.
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.
= An Awesome Heading =
%%!preproc: '^=+(.*?)=+$' '\g<0>[\1]'
= An Awesome Heading =[ An Awesome Heading ]
= An Awesome Heading =[An Awesome Heading]
but that doesn't quite cover it. Is there a way to strip spaces (and
other bad characters) from a section of a line. I have considered
brute-forcing it but that isn't pretty and can only handle a set amount
of words.
%!preproc: '^=+\s*(\S*?)\s*(\S*?)\s*(\S*?)\s*(\S*?)\s*=+$'
'\g<0>[\1\2\3\4]'
This last one works but is super ugly. Does anyone have and suggestions?
Thanks, Kevin
--
Aurelio | www.aurelio.net | @oreio
Loading...