Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Header identifier (for internal links)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
peter gallagher  
View profile  
 More options Nov 15 2012, 1:39 am
From: peter gallagher <pwgallag...@gmail.com>
Date: Wed, 14 Nov 2012 22:39:53 -0800 (PST)
Local: Thurs, Nov 15 2012 1:39 am
Subject: Header identifier (for internal links)

I've been using Pandoc as a BBEdit filter to write documentation that will
(eventually) be LaTeX but is temporarily HTML (in the BBEdit preview
window).

Pandoc automatically attaches link-anchors to headers in these documents
(sections, subsections, H1, H2 etc) giving them formatted id-strings
"behind the scenes". The format of the link-anchors is indicated in the
User Guide.

I wanted to automate the creation of these links in my text (e.g. when I
create an internal link within the document to another section).

Here is the hackish shell script that I run as a BBEdit text-filter on the
selected Header name to transform it in-place to the Pandoc link format.

I'm sure you can improve on this string of perls.

#!/bin/sh

# Text filter: when run on the selected string in BBEdit
# will convert it to a form used by Pandoc for a header identifier

perl -pe 's/[^\w\.\- ]//g' | perl -pe 's/^[0-9\. ]*//g'| perl -pe '$_=lc' |
perl -pe 's/[ \t]/-/g'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
peter gallagher  
View profile  
 More options Nov 15 2012, 1:50 am
From: peter gallagher <pwgallag...@gmail.com>
Date: Wed, 14 Nov 2012 22:50:19 -0800 (PST)
Local: Thurs, Nov 15 2012 1:50 am
Subject: Re: Header identifier (for internal links)

Oops... I copied it wrong, omitting the underscore before the space
character in the first regex. The perl string *should* be:

perl -pe 's/[^\w\.\-_ ]//g' | perl -pe 's/^[0-9\. ]*//g'| perl -pe '$_=lc'
| perl -pe 's/[ \t]/-/g'

Peter


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BP Jonsson  
View profile  
 More options Nov 15 2012, 7:16 am
From: BP Jonsson <melr...@gmail.com>
Date: Thu, 15 Nov 2012 13:16:51 +0100
Local: Thurs, Nov 15 2012 7:16 am
Subject: Re: Header identifier (for internal links)

On 2012-11-15 07:50, peter gallagher wrote:

> Oops... I copied it wrong, omitting the underscore before the space
> character in the first regex. The perl string *should* be:

> perl -pe 's/[^\w\.\-_ ]//g' | perl -pe 's/^[0-9\. ]*//g'| perl -pe '$_=lc'
> | perl -pe 's/[ \t]/-/g'

Why not just make all four substitutions in the same
perl process? I'm not saying you're doing wrong, just
wondering why. Also you might want to make sure to
remove all formatting by first piping trough pandoc
with plain output, for which reason you'll want to trim
off leading and trailing whitespace as well.

     pandoc -w plain | perl -pe's/[^\w\.\-_ ]//g; s/^[0-9\. ]*//g;
$_=lc; s/[ \t]/-/g'

Also you might want to prepare for Unicode in your input
by doing

     perl -Mopen=:utf8,:std -pe'...

As it happens, when the subject of heading ids and
links to them came up here a while ago I wrote a perl
script which collects all ATX headings[^1] in its input
and outputs blank-line separated reference link
definitions with the actual heading texts as link
identifiers and the properly formatted HTML ids as
URLs. Optionally it also adds the heading text as a
title attribute text.

[^1]: Actually all lines beginning with 1-6 hash marks
     -- take care to backslash escape any false positives!

I've added some help text/documentation and attached it.

I use it like this

     perl mkd-head-links.pl chap1.mkd chap2.mkd >headlinks.mkd
     pandoc chap1.mkd chap2.mkd headlinks.mkd

Just do

perl mkd-head-links.pl --help|pandoc -o mkd-head-links.pdf

to see the examples nicely typeset!

/bpj

  mkd-head-links.pl
5K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
peter gallagher  
View profile  
 More options Nov 18 2012, 1:53 am
From: peter gallagher <pwgallag...@gmail.com>
Date: Sat, 17 Nov 2012 22:53:43 -0800 (PST)
Local: Sun, Nov 18 2012 1:53 am
Subject: Re: Header identifier (for internal links)

Thank you, BP. A superior solution. I'm using this as a text filter in
BBEdit as I write (the 'string of perls' is redundant as you point out).
I'll no doubt find a good use for your script.

Peter

ps. I did search the Group first before cobbling together my own attempt.
Somehow your earlier contribution did not turn up.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BP Jonsson  
View profile  
 More options Nov 20 2012, 12:07 pm
From: BP Jonsson <melr...@gmail.com>
Date: Tue, 20 Nov 2012 18:07:05 +0100
Local: Tues, Nov 20 2012 12:07 pm
Subject: Re: Header identifier (for internal links)
On 2012-11-18 07:53, peter gallagher wrote:

> Thank you, BP. A superior solution. I'm using this as a text filter in
> BBEdit as I write (the 'string of perls' is redundant as you point out).
> I'll no doubt find a good use for your script.

> Peter

> ps. I did search the Group first before cobbling together my own attempt.
> Somehow your earlier contribution did not turn up.

I didn't post it to the group.  Your post was what jogged me into
writing some documentation.

Glad you liked it!

/bpj


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »