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

Make inline code distinguishable from code blocks #16

Closed
thekid opened this issue Mar 23, 2023 · 1 comment
Closed

Make inline code distinguishable from code blocks #16

thekid opened this issue Mar 23, 2023 · 1 comment

Comments

@thekid
Copy link
Member

thekid commented Mar 23, 2023

Input

Inline `code`!

```
Block of code
```

Output

<p>Inline <code>code</code>!</p>
<code>Block of code
</code>

Problem

We want to highlight the code block, but don't want to do that for inline code. However, in the outputted HTML, they are not distinguishable.

Idea

Wrap the <code> inside <pre>. This would (by default):

  • Remove the necessity of styling the code element with white-space: pre-wrap
  • Make it easily interoperable with https://highlightjs.org/
  • Make it compliant with Marked.JS for example
@thekid
Copy link
Member Author

thekid commented Mar 23, 2023

Implementation is easy:

diff --git a/src/main/php/net/daringfireball/markdown/ToHtml.class.php b/src/main/php/net/daringfireball/markdown/ToHtml.class.php
index 5373a6c..6c9ed24 100755
--- a/src/main/php/net/daringfireball/markdown/ToHtml.class.php
+++ b/src/main/php/net/daringfireball/markdown/ToHtml.class.php
@@ -270,7 +270,7 @@ class ToHtml implements Emitter {
     }

     $attr= $block->language ? ' lang="'.htmlspecialchars($block->language, $this->flags).'"' : '';
-    return '<code'.$attr.'>'.$r.'</code>';
+    return '<pre><code'.$attr.'>'.$r.'</code></pre>';
   }

   /**

However, it breaks BC, so we would have to go for a major release.

thekid added a commit that referenced this issue Mar 23, 2023
Solves problem described in issue #16
@thekid thekid closed this as completed Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant