Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Helper functions to deal with Pod elements.

License

NotificationsYou must be signed in to change notification settings

JJ/raku-pod-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pod::Utils - Set of helper functions to ease working with Pods!

SYNOPSIS

usePod::Utils;# time to work with Pod::* elements!say first-subtitle($=pod[0].contents);=beginpod=SUBTITLESome cool text=endpod

DESCRIPTION

Pod::Utils is a set of routines that help you to deal with Pod elements.It lets you manipulate several kinds of Pod objects, obtain gists and modifyheadings.

sub first-code-block

subfirst-code-block (Array@pod)returnsStr;

Returns the firstPod::Block::Code found in an array, concatenating all lines in it.If none is found, it will return an empty string.

Example:

=beginpod=begincode    say "some code";    say "more code";=endcode=endpodfirst-code-block($=pod[0].contents)# OUTPUT «say "some code";␤say "more code";␤»

sub first-title

subfirst-title (Array@pod)returnsPod::Block::Named;

Returns the first=TITLE element found in@pods.

Example:

=beginpod=TITLEtitle=endpodfirst-title($=pod[0].contents)# OUTPUT equivalent to:=TITLEtitle

sub first-subtitle

subfirst-subtitle (Array@pod)returnsPod::Block::Named;

Returns the first=SUBTITLE element found in@pods.

Example:

=beginpod=subTITLEsubtitle=endpodfirst-subtitle($=pod[0].contents)# OUTPUT equivalent to:=SUBTITLEsubtitle

multi sub textify-guts

multitextify-guts (Any:U,       )returnStr;multitextify-guts (Str:D      \v)returnStr;multitextify-guts (List:D     \v)returnStr;multitextify-guts (Pod::Block \v)returnStr;

Converts lists ofPod::Block::* objects andPod::Block objects to strings.

Example:

my$block=Pod::Block::Para.new(contents=> ["block"]);say textify-guts($block);# OUTPUT «block␤»say textify-guts([$block,$block]);# OUTPUT «block block␤»

multi sub recurse-until-str

multisubrecurse-until-str(Str:D$s)returnStr;multisubrecurse-until-str(Pod::Block$n)returnStr;

Accepts aPod::Block::* object and returns a concatenation of all subpods content.

Example:

my$block=Pod::Block::Para.new(contents=> ["block"]);my$complex-block= pod-block("one", pod-block("two"), pod-bold("three"));say recurse-until-str($block);# OUTPUT «block␤»say recurse-until-str($complex-block);# OUTPUT «onetwothree␤»

Pod::Utils::Build

SYNOPSIS

usePod::Utils::Build;# time to build Pod::* elements!say pod-bold("bold text");

DESCRIPTION

Pod::Utils::Build is a set of routines that help you to create newPod elements.

sub pod-title

subpod-title (Str$title,)returnsPod::Block::Named;

Creates a newPod::Block::Named object (with:name set to"TITLE")and populates it with aPod::Block::Para containing$title.

Example:

pod-title("title");# OUTPUT Equivalent to:=begindpod=TITLEtitle=endpod

sub pod-with-title

subpod-with-title (Str$title,Array@blocks)returnsPod::Block::Named;

Creates a newPod::Block::Named object (with:name set to "pod")and populate it with a title (usingpod-title) and@blocks.

Example:

=begindpodNormal paragraph=endpodpod-with-title("title",$=pod.first.contents[0]);# OUTPUT Equivalent to:=begingpod=TITLEtitleNormal paragraph=endpod

sub pod-block

subpod-block (Array*@contents)returnsPod::Block::Para;

Creates aPod::Block::Para with contents set to@contents.

Example:

say pod-block("title",Pod::Block::Para.new(contents=> ["paragraph"]));# OUTPUTPod::Block::Para  titlePod::Block::Para    paragraph

sub pod-link

subpod-link (Str$text,Str$url)returnsPod::FormattingCode;

Creates aPod::FormattingCode (type Link) with contents set to$text.and meta set to$url.

Example:

pod-link("text","url");# OUTPUT Equivalent to:L<text|url>

sub pod-bold

subpod-bold (Str$text,)returnsPod::FormattingCode;

Creates aPod::FormattingCode (type B) with contents set to$text.

Example:

pod-bold("text");# OUTPUT Equivalent to:B<text>

sub pod-code

subpod-code (Str$text,)returnsPod::FormattingCode;

Creates aPod::FormattingCode (type C) with contents set to$text.

Example:

pod-code("text");# OUTPUT Equivalent to:C<text>

sub pod-item

subpod-item (Array*@contents ,Int:$level=1,)returnsPod::Item;

Creates aPod::Item object with contents set to@contents and level to$level.

Example:

pod-item(pod-block("item"),level=>1);# OUTPUT Equivalent to:=itemitem

sub pod-heading

subpod-heading (Str$name,Int:$level=1,)returnsPod::Heading;

Creates aPod::Heading object with level set$level and contents initializedwith aPod::Block::Para object containing$name.

Example:

pod-heading("heading",level=>1);# OUTPUT Equivalent to:=head1heading

sub pod-table

subpod-table (Array@contents,Array:@headers,)returnsPod::Block::Table;

Creates aPod::Block::Table object with the headers@headers and rows@contents.$caption is set to"".Example:

pod-table([["col1","col2"],],headers=> ["h1","h2"]);# OUTPUT Equivalent to:=begintableh1   | h2============col1 | col2=endtable

sub pod-lower-headings

subpod-lower-headings (Array@content,Int:$to,)returnsArray;

Given an array of Pod objects, lower the level of every heading followingthe next formula =>current-level - $by + $to, where$by is the level of thefirst heading found in the array.

Example:

my@contents= [    pod-heading("head",level=>2),    pod-heading("head",level=>3)];pod-lower-headings(@contents)# OUTPUT Equivalent to:=head1head=head2head

AUTHORS

Alexander Mouquin <@Mouq>

Will Coleda <@coke>

Rob Hoelz <@hoelzro>

<@timo>

Moritz Lenz <@moritz>

Juan Julián <@JJ>

<@MasterDuke17>

Zoffix Znet <@zoffixznet>

Antonio <@antoniogamiz>

COPYRIGHT AND LICENSE

Copyright 2019 Perl 6 team

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

About

Helper functions to deal with Pod elements.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp