Giter Site home page Giter Site logo

Comments (15)

kminchev avatar kminchev commented on May 7, 2024

I don't like this and #101, and generally any feature specifically addressing HTML5. Not everyone is designing in HTML5.

from parsedown.

hkdobrev avatar hkdobrev commented on May 7, 2024

@kminchev This part of the HTML5 spec is completely backwards-compatible. What exactly is your concern?

from parsedown.

hkdobrev avatar hkdobrev commented on May 7, 2024

It is worth noting the ol[start] and li[value] attributes are part of HTML4 as well, but their semantics are just a little bit different and are deprecated from the final version of HTML4.

So they are not HTML5-only. They are just resurrected in HTML5.

from parsedown.

wkpark avatar wkpark commented on May 7, 2024

I didn't know that the start attribute is the part of the Markdown spec :)

BTW the start attribute also supported by ReStructuredText

from parsedown.

wkpark avatar wkpark commented on May 7, 2024

this is not the part of Markdown spec.

3. item #1
1. item #2
8. item #3
  1. item #1
  2. item #2
  3. item #3

Markdown does not support "start" or "value" attributes

all numberings are ignored.

anyway I like "start" attribute and It is useful to support it optionally.

from parsedown.

scottchiefbaker avatar scottchiefbaker commented on May 7, 2024

This is specifically against the spec.

from parsedown.

wkpark avatar wkpark commented on May 7, 2024

there are Text::Markdown perl module exists (version 1.0.31)

it has trust_list_start_value option to support "start" attrubute.

from parsedown.

kminchev avatar kminchev commented on May 7, 2024

anyway I like "start" attribute and It is useful to support it optionally.

Agreed. If any HTML5 addition is going to be implemented, I suggest it being optional.

from parsedown.

hkdobrev avatar hkdobrev commented on May 7, 2024

@wkpark This is not part of the Markdown spec. It is just undefined by the spec. It used to be part of the HTML4 spec and it is part of the HTML5 spec.

@scottchiefbaker Why is this against the spec?

from parsedown.

wkpark avatar wkpark commented on May 7, 2024

ReStructuredText have similar feature by default. (demo page: http://rst.ninjs.org/)

and as I already said, the Text::Markdown perl module have trust_list_start_value option to support start attribute.
(Text::Markdown is a fork of the original Markdown.pl)

the source code of Text::Markdown found at Github https://github.com/bobtfish/text-markdown

trust_list_start_value option is described as following

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
  1. foo
  2. bar

some paragraph

  1. baz
  2. quux

(Note that in the above, quux will be numbered 4.)

from parsedown.

erusev avatar erusev commented on May 7, 2024

@hkdobrev

@scottchiefbaker Why is this against the spec?

Probably, because of the following excerpt:

If you instead wrote the list in Markdown like this:

1.  Bird
1.  McHale
1.  Parish

or even:

3. Bird
1. McHale
8. Parish

you’d get the exact same HTML output. The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don’t have to.

from parsedown.

rmjarvis avatar rmjarvis commented on May 7, 2024

+1 on this feature request. I am constantly bitten by this "feature" of markdown. e.g. if someone makes a list of 5 things in an issue, and I want to respond to the 4th one, I'll try to copy it out for a response:

> 4. The fourth item that someone talked about

This is already implemented.  See this issue...

Shows up as:

  1. The fourth item that someone talked about

This is already implemented. See this issue...

It would be nice to have some way to force the numbering to start where I want it, not at 1.

from parsedown.

erusev avatar erusev commented on May 7, 2024

@rmjarvis that's a good point, i'll se what i can do

from parsedown.

aidantwoods avatar aidantwoods commented on May 7, 2024

@erusev just taking a quick glance at the source for this issue

For the following section of code (which creates tags)
if (isset($Element['text'])) { $markup .= '>'; if (isset($Element['handler'])) { $markup .= $this->{$Element['handler']}($Element['text']); } else { $markup .= $Element['text']; } $markup .= '</'.$Element['name'].'>'; }
Would the following change cause any issues? $markup .= '</'.$Element['name'].'>'; to $markup .= '</'.preg_replace('/[ ].*/', '', $Element['name']).'>';
This should just strip everything after a space (if any, and including the space) out of the tag name (which a tag shouldn't have in it anyway at the close).

That change would allow you to change the blockList function from

protected function blockList($Line)
    {
        list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
        if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
        {
            $Block = array(
                'indent' => $Line['indent'],
                'pattern' => $pattern,
                'element' => array(
                    'name' => $name,
                    'handler' => 'elements',
                ),
            );
            $Block['li'] = array(
                'name' => 'li',
                'handler' => 'li',
                'text' => array(
                    $matches[2],
                ),
            );
            $Block['element']['text'] []= & $Block['li'];
            return $Block;
        }
    }

To something like

protected function blockList($Line)
    {
        list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '([*+-])') : array('ol', '([0-9]+)[.]');
        if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
        {
            $Block = array(
                'indent' => $Line['indent'],
                'pattern' => preg_replace('/\(|\)/', '', $pattern),
                'element' => array(
                    'name' => $name,
                    'handler' => 'elements',
                ),
            );
            if($name === 'ol' && $matches[2] !== '1') $Block['element']['attributes'] = array('start' => $matches[2]);
            $Block['li'] = array(
                'name' => 'li',
                'handler' => 'li',
                'text' => array(
                    $matches[3],
                ),
            );
            $Block['element']['text'] []= & $Block['li'];
            return $Block;
        }
    }

All I've done is put an additional capture group round the number on the ol pattern, and the entire expression on the ul pattern (so we keep the same amount of capture groups in each expression). I've then corrected the $matches[2] to $matches[3] for the list item text (since I've added an additional capture group before it). And I've then added an if statement to append a start value (the list number captured) if the list type is ol and the number is something other than 1.

I've then relied on the fact that my adjustment to the tag creation function will strip that start value out of the name when it closes the tag (since a space precedes the start attribute).

Edit: I've added a pull request #431 that you can merge if those changes look okay.

Edit: Have amended the code in this comment to return the original pattern into the $Block array (so the rest of the code works as expected).

from parsedown.

aidantwoods avatar aidantwoods commented on May 7, 2024

Fixed in #431

from parsedown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.