Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Text-Markdown CPAN distribution.

Report information
The Basics
Id: 40814
Status: resolved
Priority: 0/
Queue: Text-Markdown

People
Owner: bobtfish [...] bobtfish.net
Requestors: rjbs [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in:
  • 1.0.1
  • 1.0.12
  • 1.0.13
  • 1.0.14
  • 1.0.16
  • 1.0.17
  • 1.0.18
  • 1.0.19
  • 1.0.2
  • 1.0.20
  • 1.0.21
  • 1.0.22
  • 1.0.23
  • 1.0.3
  • 1.0.4
  • 1.0.5
Fixed in: 1.0.24



Subject: allow OL to begin at given point
I don't mind if this is done with subclassing or an option or what. I just need to be able to say: 1. foo other stuff 2. bar ...probably by saying that the number the lists starts in Markdown with is the number the list starts with in HTML. I will implement this if you will agree to accept it. ;) -- rjbs
Subject: Re: [rt.cpan.org #40814] allow OL to begin at given point
Date: Mon, 10 Nov 2008 23:55:17 +0000
To: bug-Text-Markdown [...] rt.cpan.org
From: Tomas Doran <bobtfish [...] bobtfish.net>
On 10 Nov 2008, at 18:09, Ricardo SIGNES via RT wrote: Show quoted text
> I don't mind if this is done with subclassing or an option or what. I > just need to be able to say: > > 1. foo > > other stuff > > 2. bar > > ...probably by saying that the number the lists starts in Markdown > with > is the number the list starts with in HTML. I will implement this if > you will agree to accept it. ;)
Currently I see: $ echo "1. foo other stuff 2. bar" | markdown.pl <ol> <li>foo</li> </ol> <p>other stuff</p> <ol> <li>bar</li> </ol> What output would you like to see / what are you trying to achieve? I'm more than happy to take patches, and some work on the list parsing would be really appreciated - there are a load of corner cases which miserably fail currently. If you are willing to make the list parser a little more flexible so that you can achieve what you want (through an option or subclassing as you suggest), and can also make it easier to start dealing with these corner cases, then I'm more than happy to take a patch. Send me some example output so that I know what you're trying to do, and I'll grab you on IRC for a chat. Cheers t0m
Subject: Re: [rt.cpan.org #40814] allow OL to begin at given point
Date: Mon, 10 Nov 2008 19:03:50 -0500
To: Tomas Doran via RT <bug-Text-Markdown [...] rt.cpan.org>
From: Ricardo SIGNES <rjbs [...] cpan.org>
* Tomas Doran via RT <bug-Text-Markdown@rt.cpan.org> [2008-11-10T18:56:09] Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=40814 > > > <ol> > <li>foo</li> > </ol> > > <p>other stuff</p> > > <ol> > <li>bar</li> > </ol>
I'm easy, but probably something like: <ol> <li value='1'>foo</li> </ol> <p>..</p> <ol> <li value='2'>bar</li> </ol> Show quoted text
> Send me some example output so that I know what you're trying to do, > and I'll grab you on IRC for a chat.
I'm nearly always on irc.perl.org during Eastern US business hours (and other hours). -- rjbs
Subject: Re: [rt.cpan.org #40814] allow OL to begin at given point
Date: Tue, 11 Nov 2008 00:29:42 +0000
To: bug-Text-Markdown [...] rt.cpan.org
From: Tomas Doran <bobtfish [...] bobtfish.net>
On 11 Nov 2008, at 00:04, Ricardo SIGNES via RT wrote: Show quoted text
> I'm easy, but probably something like:
<snip> Show quoted text
> <li value='2'>bar</li> > </ol>
Sounds sane. Is there a spec / draught for how this is going to be supported in future HTML versions (i.e. the attribute name), or anything similar, or are we out on a limb? But yes, I'd be happy to take a patch adding an option that enabled that output. Cheers t0m
Subject: Re: [rt.cpan.org #40814] allow OL to begin at given point
Date: Mon, 10 Nov 2008 20:12:00 -0500
To: Tomas Doran via RT <bug-Text-Markdown [...] rt.cpan.org>
From: Ricardo SIGNES <rjbs [...] cpan.org>
* Tomas Doran via RT <bug-Text-Markdown@rt.cpan.org> [2008-11-10T19:29:49] Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=40814 > > > > On 11 Nov 2008, at 00:04, Ricardo SIGNES via RT wrote:
> > I'm easy, but probably something like:
> <snip>
> > <li value='2'>bar</li> > > </ol>
> > Sounds sane. Is there a spec / draught for how this is going to be > supported in future HTML versions (i.e. the attribute name), or > anything similar, or are we out on a limb?
The attribute is well-known and well-supported, but HTML4.01 marked it deprecated (if not earlier) in favor of CSS. Unfortunately, there is no simple way to do this in CSS, and the complexish way would be with CSS counters, which are not supported in IE6 or IE7. 'value' wins out. More likely, perhaps, than <li value=x> is <ol start=x>, but 6 of one, half a dozen of another... -- rjbs
patch attached; docs, tests, code
diff --git a/MANIFEST b/MANIFEST index 4ad3c57..a285336 100644 --- a/MANIFEST +++ b/MANIFEST @@ -59,6 +59,7 @@ t/36multimarkdown_featurebleed.t t/37anchormultilinebugs.t t/38listshorizontalrule.t t/39listsindentededgecase.t +t/40trustliststart.t t/code-hr.t t/docs-maruku-unittest/abbreviations.html t/docs-maruku-unittest/abbreviations.text diff --git a/lib/Text/Markdown.pm b/lib/Text/Markdown.pm index 79a13e1..6901339 100644 --- a/lib/Text/Markdown.pm +++ b/lib/Text/Markdown.pm @@ -67,7 +67,7 @@ The options for the processor are: =over -=item empty element suffix +=item empty_element_suffix This option can be used to generate normal HTML output. By default, it is ' />', which is xHTML, change to '>' for normal HTML. @@ -79,6 +79,21 @@ Controls indent width in the generated markup, defaults to 4 Controls if Markdown is processed when inside HTML blocks. Defaults to 0. +=item trust_list_start_value + +If true, ordered lists will use the first number as the starting point for +numbering. This will let you pick up where you left off by writing: + + 1. foo + 2. bar + + some paragraph + + 3. baz + 6. quux + +(Note that in the above, quux will be numbered 4.) + =back =head1 METHODS @@ -133,6 +148,8 @@ sub new { # Is markdown processed in HTML blocks? See t/15inlinehtmldonotturnoffmarkdown.t $p{markdown_in_html_blocks} = $p{markdown_in_html_blocks} ? 1 : 0; + + $p{trust_list_start_value} = $p{trust_list_start_value} ? 1 : 0; my $self = { params => \%p }; bless $self, ref($class) || $class; @@ -927,14 +944,16 @@ sub _DoLists { $whole_list }{ my $list = $1; - my $list_type = ($3 =~ m/$marker_ul/) ? "ul" : "ol"; + my $marker = $3; + my $list_type = ($marker =~ m/$marker_ul/) ? "ul" : "ol"; # Turn double returns into triple returns, so that we can make a # paragraph for the last item in a list, if necessary: $list =~ s/\n{2,}/\n\n\n/g; my $result = ( $list_type eq 'ul' ) ? $self->_ProcessListItemsUL($list, $marker_ul) : $self->_ProcessListItemsOL($list, $marker_ol); - $result = "<$list_type>\n" . $result . "</$list_type>\n"; + + $result = $self->_MakeList($list_type, $result, $marker); $result; }egmx; } @@ -944,14 +963,15 @@ sub _DoLists { $whole_list }{ my $list = $1; - my $list_type = ($3 =~ m/$marker_ul/) ? "ul" : "ol"; + my $marker = $3; + my $list_type = ($marker =~ m/$marker_ul/) ? "ul" : "ol"; # Turn double returns into triple returns, so that we can make a # paragraph for the last item in a list, if necessary: $list =~ s/\n{2,}/\n\n\n/g; my $result = ( $list_type eq 'ul' ) ? $self->_ProcessListItemsUL($list, $marker_ul) : $self->_ProcessListItemsOL($list, $marker_ol); - $result = "<$list_type>\n" . $result . "</$list_type>\n"; + $result = $self->_MakeList($list_type, $result, $marker); $result; }egmx; } @@ -960,6 +980,17 @@ sub _DoLists { return $text; } +sub _MakeList { + my ($self, $list_type, $content, $marker) = @_; + + if ($list_type eq 'ol' and $self->{trust_list_start_value}) { + my ($num) = $marker =~ /^(\d+)[.]/; + return "<ol start='$num'>\n" . $content . "</ol>\n"; + } + + return "<$list_type>\n" . $content . "</$list_type>\n"; +} + sub _ProcessListItemsOL { # # Process the contents of a single ordered list, splitting it diff --git a/t/40trustliststart.t b/t/40trustliststart.t new file mode 100644 index 0000000..289e8d2 --- /dev/null +++ b/t/40trustliststart.t @@ -0,0 +1,33 @@ +use strict; +use warnings; +use Test::More tests => 2; + +use_ok( 'Text::Markdown' ); + +my $m = Text::Markdown->new(trust_list_start_value => 1); +my $html1 = $m->markdown(<<"EOF"); +1. this +2. is a list + +Paragraph. + +3. and we +4. pick up + +EOF + +my $want = <<'EOF'; +<ol start='1'> +<li>this</li> +<li>is a list</li> +</ol> + +<p>Paragraph.</p> + +<ol start='3'> +<li>and we</li> +<li>pick up</li> +</ol> +EOF + +is($html1, $want, "we can use numbering from start marker");
Added to trunk and 1.0.24 is on it's way to CPAN, thanks!