2016-03-03 63 views
2

我想寫一個Parsedown的擴展名,以便我可以爲每個表標記添加一個默認類。我發現,我可以成功地通過增加線路分配在blockTable功能屬性(左右線870)破解的源代碼:如何擴展Parsedown以向表標記添加類

$Block = array(
     'alignments' => $alignments, 
     'identified' => true, 
     'element' => array(
       'name' => 'table', 
       'handler' => 'elements', 
       'attributes' => array(
         'class' => 'table', 
       ), 
     ), 
); 

但是,如果我嘗試鬆散遵循Change Element Markup extension tutorial我是不成功的(也許。因爲表分析可能是一個反覆的過程,並在教程中的例子是一個簡單的字符串替換)

我已經試過:

class Extension extends Parsedown 
{ 

     protected function blockTable($Line, array $Block = null) 
     { 
       $Block = parent::blockTable($Line, array $Block = null); 

       $Block['table']['attributes']['class'] = 'table'; 

       return $Block; 
     } 

} 

,但不起作用。

回答

1

我不太清楚你的代碼有什麼問題,因爲你的代碼與我的代碼匹配。我只是增加

'attributes' => array(
     'class' => 'table table-responsive' 
), 

到identifyTable,上線850,使其成爲

 $Block = array(
      'alignments' => $alignments, 
      'identified' => true, 
      'element' => array(
       'name' => 'table', 
       'handler' => 'elements', 
       'attributes' => array(
        'class' => 'table table-responsive', 
       ), 
      ), 
     ); 

這對我的工作就好了。但是這對你來說似乎是一樣的,減去表格響應。

您使用的是什麼版本?

+0

如果您正在尋求OP的更多信息,請使用註釋。 – Raju

+0

我會,但我現在還不能評論。我盡力幫助,但我可以但不被網站允許。 – blakeaholics

+0

這完全可以理解。它在元棧溢出上討論了很多次。一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你將能夠[評論任何職位](http://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 – Raju

相關問題