Le 31/07/2015 20:06, Peter Uhnák a écrit :
> Hi,
> 
> I would like to resolve this issue:
> Automatic section anchors: Each section title should automatically
> generate an implicit hyperlink target (aka, anchor) pointing to the
> section. The text of the hyperlink target (the "reference name") is the
> same as that of the section title.
> 
> however since I'm not familiar with Pillar I don't know how acceptable
> this solution could be
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> PRHTMLWriter>>visitHeader: aHeader
> | level |
> level := self configuration headingLevelOffset + aHeader level."h1 to h7
> exist."
> level := level min: 7 max: 1.
> canvas tag
> name: 'h' , level asString;
> parameterAt: 'id' put: (self createIdForHeader: aHeader); "<<< addition"
> with: [ 
> self writeCounterForHeader: aHeader.
> super visitHeader: aHeader ].
> canvas newLine
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> and
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> createIdForHeader: aHeader
> | id |
> id := aHeader text.
> id := id asLowercase.
> "replace banned characters with dashes"
> id := '[^0-9a-z\-]' asRegex copy: id replacingMatchesWith: '-'.
> "merge multiple dashes"
> id := '-{2,}' asRegex copy: id replacingMatchesWith: '-'.
> "remove dashes from beginning/end of the id"
> id := '^-|-$' asRegex copy: id replacingMatchesWith: ''.
> ^ id
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Strictly speaking HTML 5 is very permissive with the value of id, but
> the question is whether we really want to permit everything. E.g.
> unicode in url is always asking for trouble.
> 
> Thanks,
> Peter
> 
> 

Hi Petter!

I begun a transformer some time ago. His name is "PRAnchorOfSection"
that inherit from "PRNodeTransformer".
For now this transformer is not enable because we need to check some
problems.
For example this works bad if we put a link inside the title. Or what do
we do if we have two times the same title? As "Introduction"?

Cyril


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to