2013-05-11 20 views
1

這種降價代碼標題:自動<a>各地Pandoc

# Introduction 

打開這個HTML代碼時Pandoc編譯:

<h1 id="introduction"><a href="#introduction">Introduction</a></h1> 

我用降價的方式:

  1. 生成HTML文檔
  2. 在MS Word中編輯它以添加頁面編號
  3. HTML版本去博客,微軟Word版本進入UNI提交

在CSS我可以覆蓋鏈接的顏色,如果他們是H#標籤裏面,但MS Word有解釋CSS覆蓋的層次結構問題..無論如何,它們都以錯誤的顏色結束。

有沒有一種方法可以生成HTML沒有標題封裝在錨標籤,如下?

<h1 id="introduction">Introduction</h1> 
+0

也許我看錯,但你認識您可以直接從pandoc導出爲文字格式? – mb21 2013-11-14 12:20:03

回答

0

如果沒有辦法解決,這裏是一個小PHP腳本,我寫了從那些必須在生成的HTML文件中運行標題中刪除標籤:

<?php 
// Usage: php cleanheadings.php myhtmlfile.html 

// Check that arguments were supplied 
if(!isset($argv[1])) die('No input file, exiting'); 

// Load file 
$content = file_get_contents($argv[1]); 

// Cut out the <a> tag 
$heading = '/(<h[123456] id="[\w-0-9]+">)(<a href="#[\w-0-9]+">)(.+)(<\/a>)(<\/h[123456])/mu'; 
$clean = '$1$3$5'; 

$cleanhtml = preg_replace($heading,$clean,$content); 

// Write changes back to file 
file_put_contents($argv[1], $cleanhtml); 
?>