2017-05-26 53 views
1

你知道一些markdown PHP解析器,code highlight等,就像GitHub markdown解析器或https://stackedit.io/editorMarkdown - PHP解析器

如果它是可通過Composer則更好。

我已經試過:

https://packagist.org/packages/michelf/php-markdown

https://packagist.org/packages/league/commonmark

https://packagist.org/packages/erusev/parsedown

但所有這些結果幾乎是純文本。

最好的結果屬於michelf/php-markdown你可以下面的圖片上看到:

enter image description here

$ composer require michelf/php-markdown 

--- 

use Michelf\MarkdownExtra; 

$parser = new MarkdownExtra(); 
$html = $parser->transform($markdown); 

echo $html; 

[編輯1]

現在我幾乎是在我的目標。

我用:

https://github.com/sindresorhus/github-markdown-css

現在我得到非常相似GitHub一個結果,但根據該代碼是沒有得到highlighted(與colors)的對應language(在這種情況下:html)爲您可以下面的圖片上看到:

enter image description here

然後我問題現在是:

什麼額外的步驟,我需要爲了得到代碼的語法高亮像GitHub上確實做的?請檢查下面的GitHub的輸出:

enter image description here

回答

2

我猜你缺少的CSS樣式呈現的HTML。

生成的HTML如下實際確定。

嘗試在文檔中包含樣式,並在其中回顯$html

例如使用Github的風格是這樣的:
https://github.com/sindresorhus/github-markdown-css

+0

感謝,幫助很大。我做了一個** **編輯在我的崗位上面因爲現在是最後一步,我需要根據語言的語法顏色突出顯示的代碼。 – Angel

+0

使用https://highlightjs.org語法高亮。 – ivoba

+0

謝謝,這有幫助! – Angel