php-markdown
php-markdown copied to clipboard
markdown code attribute add prefixe with "language-"
now,php-markdown will parse
```php
print 'hwllo world'
````
to:
<pre><code class="php">print 'hwllo world'
</code></pre>
the code class="php"
, I think it no standard.
see the page
- http://jgm.github.io/stmd/spec.html#fenced-code-blocks
- http://www.w3.org/TR/html5/text-level-semantics.html#the-code-element
the code
attribute should be add prefixe with "language-", such as:
<code class="language-php">
maybe set $this->code_class_prefix="language-"
can solve this problem.
BUT this type not working:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.php #example-1}
print 'hello';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
it will output:
<pre><code id="example-1" class="php">print 'hello';
</code></pre>
I'm no sure I can really change the default for code_class_prefix
(which is currently empty) without breaking existing documents that rely on the default. I agree though that perhaps I should have set it to "language-"
by default when I first implemented the feature.
As for the class specified in a special attribute block such as {.php}
, it's normal for code_class_prefix
to not apply. It is by purpose that this block should work identically across headers, links and code blocks, and other things that will accept it in the future. And it makes sense too: you may want to convey something else that is not a language through a class name. Perhaps I should relax the current limitation so this is allowed:
~~~~~~~~~~~~~~~ .php {.wrong}
$query = "SELECT * FROM users WHERE name='$name"";
~~~~~~~~~~~~~~~
```php {.wrong}
$query = "SELECT * FROM users WHERE name='$name"";
```
where the result would be class="language-php wrong"
(assuming you have set code_class_prefix
to "language-"
).
I'm sorry, I not understand why this not work :
~~~~~~~~~~~~~~~ .php {.wrong}
$query = "SELECT * FROM users WHERE name='$name"";
~~~~~~~~~~~~~~~
```php {.wrong}
$query = "SELECT * FROM users WHERE name='$name"";
```
I have require this :
require "vendor/php-markdown-lib/Michelf/MarkdownExtra.inc.php";
I have declare this :
$parser = new Markdown;
$parser->code_class_prefix = "language-";
$my_html = $parser->transform($my_text);
It not parse ~
And it not add class language-
Can you help me please ?
Thank you in advence
As I said in my previous comment, using a class name both inside and outside of the braces is currently not allowed. But I realize it'd probably be a good idea to allow it. I'll probably do that in the next version.
Okay, It's great ! You can look at highlight.js project, it's very interesting for that ! https://highlightjs.org/
But you specify this syntax bellow in your doc here but not work, the ~
is not interprated :
~~~~~~~~~~~~~~~
$query = "SELECT * FROM users WHERE name='$name"";
~~~~~~~~~~~~~~~
Only this work :
```
$query = "SELECT * FROM users WHERE name='$name"";
```
Thank you very much.
@silverpark You need to use MarkdownExtra
class as the parser. When you write new Markdown
you are instantiating the plain-Markdown parser that does not include the Extra features.
Also, this is the discussion about an issue related to the class name of a code block. If you have further questions with basic usage of the parser please open another issue or send me an email. Let's not spam @daoiqi who reported this issue about class names with things that are not related.
Sorry. It's okay.
Thank you :-)