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

Fence code blocks and nested lists inconsistencies #124

Closed
askmrsinh opened this issue Apr 13, 2019 · 2 comments · Fixed by #231
Closed

Fence code blocks and nested lists inconsistencies #124

askmrsinh opened this issue Apr 13, 2019 · 2 comments · Fixed by #231

Comments

@askmrsinh
Copy link

Initially reported at russross/blackfriday#536

I am working on a Hugo project that uses blackfriday internally to render its content.
This is the nested list that I am using:

## Project Setup and Run
1. Importing the project into Eclipse
   - Open Eclipse *-> Click* File *-> Click* Import *-> Click* General *-> Click* Existing Projects into Workspace. Follow on screen instructions.
   - Make sure all JARs and class folders on the build path are present for the project.
2. Set API Keys
   - Sign up for 
      - Google Maps JavaScript API key [here](https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fdevelopers.google.com%2Fmaps%2Fdocumentation%2Fjavascript%2F&service=ahsid#identifier)
      - Weather API- OpenWeatherMap key [here](https://home.openweathermap.org/users/sign_up)
      - Dark Sky API key [here](https://darksky.net/dev/register)
   - Set the above keys in `wetter\WebContent\resources\includes\api.jsp` file; lines 4,5,6.
     ```Java
     String api_key_GoogleMapsJavaScript   = "INSERT_YOUR_KEY";
     String api_key_OpenWeatherMap         = "INSERT_YOUR_KEY";
     String api_key_DarkSky                = "INSERT_YOUR_KEY";
     ```
3. Optionally set Proxy ie. `http.proxyHost` && `http.proxyPort` in files:
   - `wetter\WebContent\resources\includes\api.jsp`; line 24
4. Run the project on Apache Tomcat server.

I can not get this to render consistently due to the below reasons.

Fenced blocks within nested lists appear as inline code (when not preceded by empty new line)
The above sample produces this:
image

The only way to get the code block to render properly is to add a new blank line before the fenced code (and further intent it) which gives this:
image

But this hack leads to another issue.
The addition of the new line before the fence code in a list, surrounds the corresponding and all subsequent bullet contents in paragraph tags ie. <li><p>...</p></li> (even those which were earlier simply rendered as <li>...</li> ). Similar behaviour was also reported at gohugoio/hugo#5291.

This becomes prominent by the extra paragraph padding at the top level lists (2. Set API Keys...., 3. Optionally set Proxy.... ) in the screenshot above.
In all likelihood, I can at least made things look consistent by adding some extra css like

li > p {
  padding:0;
  margin:0
}

However, this doesn't address the underlying issue directly:

  1. the need for fenced code block to be preceded by a new line in a list
  2. stray addition of paragraph tags where not required

Expected Output:

<h2>Project Setup and Run</h2>
<ol>
  <li>
    Importing the project into Eclipse
    <ul>
      <li>Open Eclipse <em>-&gt; Click</em> File <em>-&gt; Click</em> Import <em>-&gt; Click</em> General <em>-&gt; Click</em> Existing Projects into Workspace. Follow on screen instructions.</li>
      <li>Make sure all JARs and class folders on the build path are present for the project.</li>
    </ul>
  </li>
  <li>
    Set API Keys
    <ul>
      <li>
        Sign up for
        <ul>
          <li>Google Maps JavaScript API key <a href="https://accounts.google.com/ServiceLogin?passive=true&amp;continue=https%3A%2F%2Fdevelopers.google.com%2Fmaps%2Fdocumentation%2Fjavascript%2F&amp;service=ahsid#identifier">here</a></li>
          <li>Weather API- OpenWeatherMap key <a href="https://home.openweathermap.org/users/sign_up">here</a></li>
          <li>Dark Sky API key <a href="https://darksky.net/dev/register">here</a></li>
        </ul>
      </li>
      <li>
        Set the above keys in <code>wetter\WebContent\resources\includes\api.jsp</code> file; lines 4,5,6.
        <pre><code class="language-Java">String api_key_GoogleMapsJavaScript   = &quot;INSERT_YOUR_KEY&quot;;
String api_key_OpenWeatherMap         = &quot;INSERT_YOUR_KEY&quot;;
String api_key_DarkSky                = &quot;INSERT_YOUR_KEY&quot;;
</code></pre>
      </li>
    </ul>
  </li>
  <li>
    Optionally set Proxy ie. <code>http.proxyHost</code> &amp;&amp; <code>http.proxyPort</code> in files:
    <ul>
      <li><code>wetter\WebContent\resources\includes\api.jsp</code>; line 24</li>
    </ul>
  </li>
  <li>Run the project on Apache Tomcat server.</li>
</ol>
@martincapello
Copy link
Contributor

martincapello commented May 3, 2022

I ran into this same issue today. This is a minimized test-case:

1. Some item
   ```java
   int a = 3;
   ```
1. Another item

Output:

<ol>
<li>Some item
<code>
java
int a = 3;
</code></li>
<li>Another item</li>
</ol>

I've been investigating a bit this issue, and it seems that there is a bug in

func codeSpan(p *Parser, data []byte, offset int) (int, ast.Node) {

It counts the number of backticks, but then it doesn't use that information to determine if it has to create an &ast.CodeBlock{} or an &ast.Code{}. It just creates the &ast.Code{}.

Will create a PR if I can make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants