russross / blackfriday

Blackfriday: a markdown processor for Go
Other
5.43k stars 598 forks source link

Specify start number in lists #385

Open kaushalmodi opened 7 years ago

kaushalmodi commented 7 years ago

Can this feature please be implemented where the start number for an ordered list can be user specified like in this example on Stackexchange.

haopen commented 7 years ago

This feature is also important for me.

kaushalmodi commented 7 years ago

Org mode (which used a markup similar to Markdown) to specify the list numbers. Here's an example:

1. Item 1
2. Item 2
3. [@10] Item 10
4. [@100] Item 100

The actual list numbers used in the markup don't matter like in Markdown. So below would work the same:

1. Item 1
1. Item 2
1. [@10] Item 10
1. [@100] Item 100

Doing above will set the value field of the <li> elements when the Org file is exported to HTML.

So the HTML would look like:

<ol>
   <li>Item 1</li>
   <li>Item 2</li>
   <li value="10">Item 10</li>
   <li value="100">Item 100</li>
</ol>

Would be great if Blackfriday could recognize the "[@N]" syntax, or something similar.

haopen commented 7 years ago

If one compile a R Markdown file with Pandoc in Hugo, Pandoc assigns a continous number automatically and the resulting html page looks perfectly to me.

kaushalmodi commented 7 years ago

@haopen I didn't follow. Where does R Markdown (also never heard of that) fit in the Hugo flow? Are you saying that you used Pandoc to convert (R) Markdown to HTML instead of Hugo+Blackfriday?

haopen commented 7 years ago

Blogdown is a R package based on R Markdown developed by yihui and functions as a Hugo wrapper, if you build your blog in blogdown, your source files can be written in markdown(.md) and be compiled by blackfriday, the default and only render of hugo; or you can write your posts in R Markdown(.Rmd) and blogdown will render the .Rmd files to html files by using Pandoc.

You can find the repository here: https://github.com/rstudio/blogdown, document here: https://bookdown.org/yihui/blogdown/, and a example site here: http://dapengde.com/blogdown_demo_default/.

kaushalmodi commented 7 years ago

I sort of hacked up something that allows a hybrid Markdown+HTML list generation where I can get list number overriding (I use Emacs Org mode for writing posts and they then translate to Blackfriday-friendly Markdown for Hugo to parse):

Example Org

** Force ordered list numbering
:PROPERTIES:
:EXPORT_DATE: 2017-08-01
:EXPORT_FILE_NAME: force-ordered-list-numbering
:END:
1. This will be 1.
1. This will be 2.

1. [@10] This will be 10!
1. This will be 11.

1. [@17] This will be 17!
1. This will be 18.
1. [@123] This will be 123!
1. This will be 124.

1. This will be 1 again.
1. This will be 2.

Another example:

1. This will be 1.
1. [@3] This will be 3!
1. [@7] This will be 7!
1. [@100] This will be 100!

See [[http://orgmode.org/manual/Plain-lists.html][(org) Plain lists]] to read more about plain lists in Org.

Source

Generated hybrid Markdown

+++
title = "Force ordered list numbering"
date = 2017-08-01
tags = ["lists"]
draft = false
+++

1.  This will be 1.
2.  This will be 2.

<!--listend-->

<ol class="org-ol">
<li value="10">This will be 10!</li>
<li>This will be 11.</li>
</ol>

<ol class="org-ol">
<li value="17">This will be 17!</li>
<li>This will be 18.</li>
<li value="123">This will be 123!</li>
<li>This will be 124.</li>
</ol>

1.  This will be 1 again.
2.  This will be 2.

Another example:

<ol class="org-ol">
<li>This will be 1.</li>
<li value="3">This will be 3!</li>
<li value="7">This will be 7!</li>
<li value="100">This will be 100!</li>
</ol>

See [(org) Plain lists](http://orgmode.org/manual/Plain-lists.html) to read more about plain lists in Org.

Source


It will be really cool if this sort of value property setting is done by Blackfriday itself so that the above kind of Markdown+HTML hybrid hack is not needed.

haopen commented 7 years ago

It seems that what you need is an org-like interface by which you can assign the numbers by yourself. As far as I know, none of the popular markdown renders, even the most powerful one, pandoc, could follow your idea in a pure markdown way, the exmple hybird script file you have shown may be a feasible solution satisfies your needs.

Roboe commented 5 years ago

This feature is specified in CommonMark in a simple way: https://spec.commonmark.org/0.29/#start-number

As such, GFM supports it:

  1. An item starting with 4
  2. Another item
  3. Another one