Comments (15)
I don't like this and #101, and generally any feature specifically addressing HTML5. Not everyone is designing in HTML5.
from parsedown.
@kminchev This part of the HTML5 spec is completely backwards-compatible. What exactly is your concern?
from parsedown.
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.
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.
this is not the part of Markdown spec.
3. item #1
1. item #2
8. 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.
This is specifically against the spec.
from parsedown.
there are Text::Markdown perl module exists (version 1.0.31)
it has trust_list_start_value
option to support "start" attrubute.
from parsedown.
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.
@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.
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
- foo
- bar
some paragraph
- baz
- quux
(Note that in the above, quux will be numbered 4.)
from parsedown.
@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.
+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:
- 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.
@rmjarvis that's a good point, i'll se what i can do
from parsedown.
@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.
Fixed in #431
from parsedown.
Related Issues (20)
- Demo broken? HOT 1
- PHP Code Eval HOT 1
- Code elements don't render inside lists
- What about using static methods instead of instanciating objects ?
- Maximum image size? HOT 2
- Nested Elements in the same Level
- Multi languagal HOT 1
- How to add class to list items?
- How to change the context in extensions?
- 187 ist die Gang
- Video Support HOT 1
- Bug: Uninitialized string offset: 1
- [bug] embeded <style> tag gets treated as text after the first code block
- image width HOT 1
- parsing email HOT 1
- lists not rendered properly with line()
- setSafeMode prevents multiple line breaks
- Parsedown extension to open in new window HOT 1
- Typo? `steam` -> `stream` HOT 1
- Allowing the spaces in start of lines?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parsedown.