Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown: Code blocks in numbered lists #1855

Closed
TheJaredWilcurt opened this issue Feb 23, 2019 · 12 comments
Closed

Markdown: Code blocks in numbered lists #1855

TheJaredWilcurt opened this issue Feb 23, 2019 · 12 comments
Labels
area: publishing experience issues related to an authors experience publishing. Tags, series, etc. tech: ruby changes will heavily involve both Ruby code

Comments

@TheJaredWilcurt
Copy link

TheJaredWilcurt commented Feb 23, 2019

On GitHub, Reddit, etc. I can do this

  1. The first step is to npm install
  2. Next add this code:
    console.log('some code');
  3. Step 3 is to...
  4. The the fourth step is....
  5. Step 5...

But on dev.to it looks like this:

  1. The first step is to npm install
  2. Next add this code:
console.log('some code');
  1. Step 3 is to...
  2. The the fourth step is....
  3. Step 5...

If there is a way to embed code blocks into ordered lists without breaking the ordering, it is not documented anywhere.

This is also a pattern that is slightly different on many different sites, where the number of spaces required at the start of the code block varies, whether it allows syntax highlighting in list code blocks, whether it allows triple graves, and whether or not the remaining lines need indentation.

There are a lot of possible permutations of how this could be implemented and without a live mardown preview, doing trial-and-error to attempt to make it work is frustrating. You need to add or remove a space at the start of every line of code, click preview, scroll scroll scroll down, and then click preview again to go back and try something else.

@jessleenyc
Copy link
Contributor

Thanks for the issue! @maestromac any thoughts on this?

@aspittel
Copy link
Contributor

I think this is a bug in RedCarpet which we use for Markdown! Think it would be awesome for someone to tackle that though. vmg/redcarpet#664

@jessleenyc
Copy link
Contributor

Good call, going to label this as blocked

@jessleenyc jessleenyc added the blocked blocked by internal or external issues label Feb 26, 2019
@TheJaredWilcurt
Copy link
Author

The issue you linked to deals with code blocks that have lines that begin with # being converted to Headings. My issue is not related to that. It is that any codeblock will force the end of the list, rather than being indented inside the list. The code block renders accurately, just not in the correct nesting.

<ol>
  <li>asdf</li>
</ol>
<div class="highlight">
  <pre class="highlight javascript">
    <code>
      ...
    </code>
  </pre>
</div>
<ol>
  <li>qwer</li>
</ol>

when it should be doing

<ol>
  <li>asdf
    <div class="highlight">
      <pre class="highlight javascript">
        <code>
          ...
        </code>
      </pre>
    </div>
  </li>
  <li>qwer</li>
</ol>

@stale
Copy link

stale bot commented May 27, 2019

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue in 7 days. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If this issue still requires attention, please respond with a comment. Happy Coding!

@stale stale bot added the stale label May 27, 2019
@TheJaredWilcurt
Copy link
Author

broken

This issue is still occurring. Again, it is not related to the linked issue above. This is a separate issue, and should be fixed as it makes me not want to use this platform.

Until you can solve this issue a work around would be to deliver the markdown code directly to the client and use Marked.js to render the HTML on the fly. Since Marked does not suffer from these bugs.

Or you could just fix this issue in whatever library you are using.

@stale stale bot removed the stale label May 31, 2019
@jessleenyc jessleenyc added external contributors welcome contribution is welcome! and removed blocked blocked by internal or external issues labels Jun 4, 2019
@jessleenyc
Copy link
Contributor

Thanks for the additional clarification @TheJaredWilcurt! This issue is approved for anyone who's interested in working on it. Should be able to fix it in the MarkdownParser.

@jessleenyc jessleenyc added area: publishing experience issues related to an authors experience publishing. Tags, series, etc. tech: ruby labels Aug 7, 2019
@bolariin
Copy link
Contributor

I was able to have code blocks inside numbered lists while retaining the order of the list. It looks the code block shouldn't be on the same line as text within the numbered list. I was able to get the same result from indenting one space, two spaces and four spaces from the position where the text within the numbered list begins.

Using the markdown below, I was able to get the result in image below the markdown text

1. The first step is to npm install
2. Next add this code:
    ```
    console.log('some code');
    ```
3. Step 3 is to...
4. The the fourth step is....
5. Step 5...

Code block in numbered lists

Not sure if it actually an issue but codeblocks can't be the only text within a point in a list.
This ends up looking like the image below

1. The first step is to npm install
2. ```
    console.log('some code');
    ```
3. Step 3 is to...
4. The the fourth step is....
5. Step 5...

codeblock alone in ordered list

but on GitHub it actually rendered as expected

  1. The first step is to npm install
  2.  console.log('some code');
    
  3. Step 3 is to...
  4. The the fourth step is....
  5. Step 5...

@TheJaredWilcurt
Copy link
Author

I can only get it to embed in the list with 4 spaces (an improvement from before), but then it also forces all text content in the rest of the list to be wrapped by a paragraphs.

<ol>
  <li>The first step is to <code>npm install</code></li>
  <li>
    <p>Next add this code:<br></p>
    <pre class="highlight plaintext"><code>console.log('some code');
</code></pre>
  </li>
  <li><p>Step 3 is to...</p></li>
  <li><p>The the fourth step is....</p></li>
  <li><p>Step 5...</p></li>
</ol>

which adds a bunch of unwanted padding

@rhymes
Copy link
Contributor

rhymes commented Jan 21, 2020

@jeikabu in #5350 added this comment:

Same problem as #1855, but when publishing from RSS where the feed is github pages.

Understand it's a problem with an upstream package, but for content pulled from elsewhere can the "hack" described in #1855 just be applied? I've been manually fixing up posts for over a year, and doing it with the web-based text editor has gotten... old.

@cmgorton cmgorton added this to Backlog in Feature backlog via automation Nov 24, 2020
@cmgorton cmgorton added this to To do in OSS Rotation: Triage stale issues/pr via automation Nov 24, 2020
@cmgorton cmgorton added the tech: ruby changes will heavily involve both Ruby code label Jan 18, 2021
@ludwiczakpawel ludwiczakpawel moved this from To do to Keep this issue/pr in OSS Rotation: Triage stale issues/pr Jan 25, 2021
@cmgorton cmgorton removed the external contributors welcome contribution is welcome! label Feb 2, 2021
@cmgorton cmgorton removed this from Backlog in Feature backlog Feb 2, 2021
@rhymes
Copy link
Contributor

rhymes commented Mar 1, 2021

This has been fixed in Redcapet 3.5.0, see vmg/redcarpet#664 (comment)

I verified it with the markdown in this comment #1855 (comment) - there's a slight UI bug but it's unrelated.

Thus I'm going to close this and surface the UI bug

@rhymes rhymes closed this as completed Mar 1, 2021
@ViacheslavZyrianov
Copy link

Bug still not fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: publishing experience issues related to an authors experience publishing. Tags, series, etc. tech: ruby changes will heavily involve both Ruby code
Projects
No open projects
Development

No branches or pull requests

8 participants